Class: Planner::State

Inherits:
Hash
  • Object
show all
Defined in:
lib/sfpagent/sfplanner.rb

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(id) ⇒ State

Returns a new instance of State.



239
240
241
# File 'lib/sfpagent/sfplanner.rb', line 239

def initialize(id)
  @id = id
end

Instance Attribute Details

#idObject (readonly)

Returns the value of attribute id.



209
210
211
# File 'lib/sfpagent/sfplanner.rb', line 209

def id
  @id
end

Class Method Details

.read(i, lines, variables) ⇒ Object



211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
# File 'lib/sfpagent/sfplanner.rb', line 211

def self.read(i, lines, variables)
  state = State.new(lines[i] == 'begin_state' ? 'init' : 'goal')
  if state.id == 'init'
    i += 1
    var_index = 0
    i.upto(lines.length) do |j|
      i = j
      break if lines[j] == 'end_state'
      var = variables[var_index]
      state[var.sym] = var[lines[j].to_i]
      var_index += 1
    end
    fail "Cannot find end_state" if lines[i] != 'end_state'
    [i, state]
  elsif state.id == 'goal'
    i += 2
    i.upto(lines.length) do |j|
      i = j
      break if lines[j] == 'end_goal'
      parts = lines[j].split(' ')
      var = variables[parts[0].to_i]
      state[var.sym] = var[parts[1].to_i]
    end
    fail "Cannot find end_goal" if lines[i] != 'end_goal'
    [i, state]
  end
end