Class: Longjing::Problem

Inherits:
Object
  • Object
show all
Defined in:
lib/longjing/problem.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(actions, init, goal) ⇒ Problem

Returns a new instance of Problem.



8
9
10
11
12
# File 'lib/longjing/problem.rb', line 8

def initialize(actions, init, goal)
  @all_actions = actions
  @initial = State.new(init.to_set)
  @goal = goal
end

Instance Attribute Details

#all_actionsObject (readonly)

Returns the value of attribute all_actions.



6
7
8
# File 'lib/longjing/problem.rb', line 6

def all_actions
  @all_actions
end

#goalObject (readonly)

Returns the value of attribute goal.



6
7
8
# File 'lib/longjing/problem.rb', line 6

def goal
  @goal
end

#initialObject (readonly)

Returns the value of attribute initial.



6
7
8
# File 'lib/longjing/problem.rb', line 6

def initial
  @initial
end

Instance Method Details

#actions(state) ⇒ Object



18
19
20
21
22
# File 'lib/longjing/problem.rb', line 18

def actions(state)
  @all_actions.select do |action|
    action.precond.applicable?(state.raw)
  end
end

#goal?(state) ⇒ Boolean

Returns:

  • (Boolean)


14
15
16
# File 'lib/longjing/problem.rb', line 14

def goal?(state)
  @goal.applicable?(state.raw)
end

#result(action, state) ⇒ Object



24
25
26
27
# File 'lib/longjing/problem.rb', line 24

def result(action, state)
  raw = action.effect.apply(state.raw)
  State.new(raw, state.path + [action])
end