Skip to content
Browse files

Fix indentation and white spaces

  • Loading branch information...
1 parent aced1a8 commit 5ee693c8f59c5e24169b4695c5af9445a081b917 @ysulaiman committed Apr 13, 2012
Showing with 15 additions and 24 deletions.
  1. +15 −24 planner.rb
View
39 planner.rb
@@ -5,11 +5,12 @@
require 'heuristic'
def debug(str)
- #puts str
+ #puts str
end
class Problem
attr_accessor :predicates, :objects, :operators, :initial_state, :goal
+
def initialize(values)
@predicates = values[:predicates]
@objects = values[:objects]
@@ -32,11 +33,11 @@ def initialize(p)
@name = tokens.shift
@parameters = tokens
end
-
end
class Fact
attr_reader :predicate, :values
+
@@facts = {}
def initialize(predicate, values)
@@ -60,11 +61,10 @@ def key
def to_s
key
end
-
+
def Fact.instances
@@facts.values
end
-
end
class State
@@ -82,7 +82,7 @@ def initialize(value, predicates)
@previous = nil
@action = nil
end
-
+
def clone
s = State.new([], nil)
s.facts = @facts.dup
@@ -134,12 +134,12 @@ def find_applicable_actions
res << action if is_applicable?(action)
end
end
-
+
debug "Applicable actions in state #{self}: "
debug res
res
end
-
+
def is_applicable?(action)
action.operator.precondition.each do |prec|
f = get_matching_fact(prec, action)
@@ -196,12 +196,11 @@ def ==(object)
elsif !self.class.equal?(object.class)
return false
end
-
+
object.each_fact{|f| return false if !self.include_fact?(f)}
self.each_fact{|f| return false if !object.include_fact?(f)}
true
end
-
end
class Operator
@@ -213,7 +212,6 @@ def initialize(name, value)
@precondition = value['precondition']
@effect = value['effect']
end
-
end
class Action
@@ -230,9 +228,7 @@ def to_s
end
class Planner
-
def initialize(domain_file, problem_file)
-
domain = YAML.load(File.new(domain_file,'r').read)
predicates = {}
domain['predicates'].each do |p|
@@ -252,10 +248,10 @@ def initialize(domain_file, problem_file)
@current_state = initial_state
@problem = Problem.new(:predicates => predicates,
- :objects => objects,
- :initial_state => initial_state,
- :goal => goal,
- :operators => operators)
+ :objects => objects,
+ :initial_state => initial_state,
+ :goal => goal,
+ :operators => operators)
@heuristic = Heuristic.new(@problem)
end
@@ -275,11 +271,8 @@ def solve
puts "\nSOLUTION: (#{@current_state.solution.size} actions)"
puts @current_state.solution.join("\n")
end
-
-
def next_state(current_state)
-
queue = Containers::PriorityQueue.new{ |x, y| (x <=> y) == -1 }
queue.push(current_state, current_state.heuristic)
tabu_states = []
@@ -300,14 +293,14 @@ def next_state(current_state)
nil
end
-
+
def is_goal_satisfied?(state)
@problem.goal.each_fact do |goal|
return false if !state.include_fact?(goal)
end
true
end
-
+
def Planner.comb(array, n)
return array.map{|e| [e]} if n == 1
res = []
@@ -316,10 +309,8 @@ def Planner.comb(array, n)
res << [e] + f
end
end
- res
+ res
end
-
-
end
if __FILE__ == $0

0 comments on commit 5ee693c

Please sign in to comment.
Something went wrong with that request. Please try again.