Exemplo n.º 1
0
def first_goals(goal, operator_nodes, variable_nodes, tree):
  goals = filter(lambda (var, value): len(variable_nodes[var][value].operators) == 1,
                 set(flatten(get_conditions(o, tree).iteritems() for o in (operator_nodes[goal].operators | {goal}))))
  print set(flatten(get_conditions(o, tree).iteritems() for o in operator_nodes[goal].operators))
  print goals
  print filter(lambda o: o != goal and any(e in goals for e in o.eff()), applicable(goal, operator_nodes, variable_nodes))
  return filter(lambda o: o != goal and any(e in goals for e in o.eff()), applicable(goal, operator_nodes, variable_nodes))
Exemplo n.º 2
0
 def applicable_operator(operator):
   operator_nodes[operator] = union(variable_nodes[v][val] for v, val in get_conditions(operator, tree).iteritems())
   if operator != goal:
     variable_node = union([operator_nodes[operator], Node(None, {operator})])
     for var2, value2 in operator.eff():
       if value2 not in variable_nodes[var2] or variable_node.cost < variable_nodes[var2][value2].cost:
         variable_nodes[var2][value2] = variable_node
         queue.push(variable_node.cost, (var2, value2))
Exemplo n.º 3
0
def any_goals(goal, operator_nodes, variable_nodes, tree):
  goals = set(flatten(get_conditions(o, tree).iteritems() for o in (operator_nodes[goal].operators | {goal})))
  return filter(lambda o: any(e in goals for e in o.eff()), applicable(goal, operator_nodes, variable_nodes))