Class: Planner::Operator
- Inherits:
-
Object
- Object
- Planner::Operator
- Defined in:
- lib/sfpagent/sfplanner.rb
Instance Attribute Summary collapse
-
#cost ⇒ Object
readonly
Returns the value of attribute cost.
-
#name ⇒ Object
readonly
Returns the value of attribute name.
-
#postconditions ⇒ Object
readonly
Returns the value of attribute postconditions.
-
#preconditions ⇒ Object
readonly
Returns the value of attribute preconditions.
-
#variables ⇒ Object
readonly
Returns the value of attribute variables.
Instance Method Summary collapse
- #<<(variable, pre = nil, post = nil) ⇒ Object
- #applicable(state) ⇒ Object
- #apply(state) ⇒ Object
-
#initialize(name, cost = 1) ⇒ Operator
constructor
A new instance of Operator.
- #update_joins_and_dependencies ⇒ Object
Constructor Details
#initialize(name, cost = 1) ⇒ Operator
Returns a new instance of Operator.
26 27 28 29 30 31 32 |
# File 'lib/sfpagent/sfplanner.rb', line 26 def initialize(name, cost=1) @name = name @cost = cost @preconditions = {} @postconditions = {} @variables = {} end |
Instance Attribute Details
#cost ⇒ Object (readonly)
Returns the value of attribute cost.
24 25 26 |
# File 'lib/sfpagent/sfplanner.rb', line 24 def cost @cost end |
#name ⇒ Object (readonly)
Returns the value of attribute name.
24 25 26 |
# File 'lib/sfpagent/sfplanner.rb', line 24 def name @name end |
#postconditions ⇒ Object (readonly)
Returns the value of attribute postconditions.
24 25 26 |
# File 'lib/sfpagent/sfplanner.rb', line 24 def postconditions @postconditions end |
#preconditions ⇒ Object (readonly)
Returns the value of attribute preconditions.
24 25 26 |
# File 'lib/sfpagent/sfplanner.rb', line 24 def preconditions @preconditions end |
#variables ⇒ Object (readonly)
Returns the value of attribute variables.
24 25 26 |
# File 'lib/sfpagent/sfplanner.rb', line 24 def variables @variables end |
Instance Method Details
#<<(variable, pre = nil, post = nil) ⇒ Object
34 35 36 37 38 39 40 41 42 43 44 45 |
# File 'lib/sfpagent/sfplanner.rb', line 34 def <<(variable, pre=nil, post=nil) return if variable.nil? or (pre.nil? and post.nil?) if !pre.nil? fail "Invalid precondition #{variable.name}:#{pre}" if !variable.index(pre) @preconditions[variable] = pre end if !post.nil? fail "Invalid postcondition #{variable.name}:#{post}" if !variable.index(post) @postconditions[variable] = post end @variables[variable.name] = variable end |
#applicable(state) ⇒ Object
47 48 49 50 |
# File 'lib/sfpagent/sfplanner.rb', line 47 def applicable(state) @preconditions.each { |var,pre| return false if state[var] != pre } true end |
#apply(state) ⇒ Object
52 53 54 |
# File 'lib/sfpagent/sfplanner.rb', line 52 def apply(state) @postconditions.each { |var,post| state[var] = post } end |
#update_joins_and_dependencies ⇒ Object
56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 |
# File 'lib/sfpagent/sfplanner.rb', line 56 def update_joins_and_dependencies @postconditions.each_key { |var_post| @preconditions.each_key { |var_pre| next if var_post == var_pre if !var_post.dependencies.has_key?(var_pre) var_post.dependencies[var_pre] = [self] else var_post.dependencies[var_pre] << self end } @postconditions.each_key { |var_post2| next if var_post == var_post2 if !var_post.joins.has_key?(var_post2) var_post.joins[var_post2] = [self] else var_post.joins[var_post2] << self end } } end |