Beispiel #1
0
 def setUp(self):
     self.p = have_cake()
     self.pg = PlanningGraph(self.p, self.p.initial)
     # some independent nodes for testing mutex
     self.na1 = PgNode_a(
         Action(expr('Go(here)'), [[], []], [[expr('At(here)')], []]))
     self.na2 = PgNode_a(
         Action(expr('Go(there)'), [[], []], [[expr('At(there)')], []]))
     self.na3 = PgNode_a(
         Action(expr('Noop(At(there))'), [[expr('At(there)')], []],
                [[expr('At(there)')], []]))
     self.na4 = PgNode_a(
         Action(expr('Noop(At(here))'), [[expr('At(here)')], []],
                [[expr('At(here)')], []]))
     self.na5 = PgNode_a(
         Action(expr('Reverse(At(here))'), [[expr('At(here)')], []],
                [[], [expr('At(here)')]]))
     self.ns1 = PgNode_s(expr('At(here)'), True)
     self.ns2 = PgNode_s(expr('At(there)'), True)
     self.ns3 = PgNode_s(expr('At(here)'), False)
     self.ns4 = PgNode_s(expr('At(there)'), False)
     self.na1.children.add(self.ns1)
     self.ns1.parents.add(self.na1)
     self.na2.children.add(self.ns2)
     self.ns2.parents.add(self.na2)
     self.na1.parents.add(self.ns3)
     self.na2.parents.add(self.ns4)
Beispiel #2
0
 def setUp(self):
     self.cake_problem = have_cake()
     self.ac_problem_1 = air_cargo_p1()
     self.ac_problem_2 = air_cargo_p2()
     self.ac_problem_3 = air_cargo_p3()
     self.ac_problem_4 = air_cargo_p4()
     self.cake_node = Node(self.cake_problem.initial)
     self.ac_node_1 = Node(self.ac_problem_1.initial)
     self.ac_node_2 = Node(self.ac_problem_2.initial)
     self.ac_node_3 = Node(self.ac_problem_3.initial)
     self.ac_node_4 = Node(self.ac_problem_4.initial)
Beispiel #3
0
 def test_add_action_level(self):
     p = have_cake()
     for a in p.actions_list:
         print('   {}{}'.format(a.name, a.args))
     print("Fluents in this problem are:")
     for f in p.state_map:
         print('   {}'.format(f))
     print("Goal requirement for this problem are:")
     for g in p.goal:
         print('   {}'.format(g))
     run_search(p, breadth_first_search)
Beispiel #4
0
 def setUp(self):
     self.cake_problem = have_cake()
     self.ac_problem_1 = air_cargo_p1()
     self.ac_problem_2 = air_cargo_p2()
     self.ac_problem_3 = air_cargo_p3()
     self.ac_problem_4 = air_cargo_p4()
     self.cake_node = Node(self.cake_problem.initial)
     self.ac_node_1 = Node(self.ac_problem_1.initial)
     self.ac_node_2 = Node(self.ac_problem_2.initial)
     self.ac_node_3 = Node(self.ac_problem_3.initial)
     self.ac_node_4 = Node(self.ac_problem_4.initial)
     self.msg = "Make sure all your mutex tests pass before troubleshooting this function."
Beispiel #5
0
    def setUp(self):
        self.cake_problem = have_cake()
        self.cake_pg = PlanningGraph(self.cake_problem,
                                     self.cake_problem.initial,
                                     serialize=False).fill()

        self.eat_action, self.bake_action = [
            a for a in self.cake_pg._actionNodes if not a.no_op
        ]
        no_ops = [a for a in self.cake_pg._actionNodes if a.no_op]
        self.null_action = make_node(
            Action(expr('Null()'), [set(), set()], [set(), set()]))

        # some independent nodes for testing mutexes
        at_here = expr('At(here)')
        at_there = expr('At(there)')
        self.pos_literals = [at_here, at_there]
        self.neg_literals = [~x for x in self.pos_literals]
        self.literal_layer = LiteralLayer(
            self.pos_literals + self.neg_literals, ActionLayer())
        self.literal_layer.update_mutexes()

        # independent actions for testing mutex
        self.actions = [
            make_node(
                Action(expr('Go(here)'), [set(), set()],
                       [set([at_here]), set()])),
            make_node(
                Action(expr('Go(there)'), [set(), set()],
                       [set([at_there]), set()]))
        ]
        self.no_ops = [
            make_node(x)
            for x in chain(*(makeNoOp(l) for l in self.pos_literals))
        ]
        self.action_layer = ActionLayer(self.no_ops + self.actions,
                                        self.literal_layer)
        self.action_layer.update_mutexes()
        for action in self.no_ops + self.actions:
            self.action_layer.add_inbound_edges(action, action.preconditions)
            self.action_layer.add_outbound_edges(action, action.effects)
 def setUp(self):
     self.p = have_cake()
     self.pg = PlanningGraph(self.p, self.p.initial)
     # some independent nodes for testing mutex
     self.na1 = PgNode_a(Action(expr('Go(here)'),
                                [[], []], [[expr('At(here)')], []]))
     self.na2 = PgNode_a(Action(expr('Go(there)'),
                                [[], []], [[expr('At(there)')], []]))
     self.na3 = PgNode_a(Action(expr('Noop(At(there))'),
                                [[expr('At(there)')], []], [[expr('At(there)')], []]))
     self.na4 = PgNode_a(Action(expr('Noop(At(here))'),
                                [[expr('At(here)')], []], [[expr('At(here)')], []]))
     self.na5 = PgNode_a(Action(expr('Reverse(At(here))'),
                                [[expr('At(here)')], []], [[], [expr('At(here)')]]))
     self.ns1 = PgNode_s(expr('At(here)'), True)
     self.ns2 = PgNode_s(expr('At(there)'), True)
     self.ns3 = PgNode_s(expr('At(here)'), False)
     self.ns4 = PgNode_s(expr('At(there)'), False)
     self.na1.children.add(self.ns1)
     self.ns1.parents.add(self.na1)
     self.na2.children.add(self.ns2)
     self.ns2.parents.add(self.na2)
     self.na1.parents.add(self.ns3)
     self.na2.parents.add(self.ns4)
Beispiel #7
0
    def setUp(self):
        self.cake_problem = have_cake()
        self.cake_pg = PlanningGraph(self.cake_problem,
                                     self.cake_problem.initial,
                                     serialize=False).fill()

        eat_action, bake_action = [
            a for a in self.cake_pg._actionNodes if not a.no_op
        ]
        no_ops = [a for a in self.cake_pg._actionNodes if a.no_op]

        # bake has the effect Have(Cake) which is the logical negation of the effect
        # ~Have(cake) from the persistence action ~NoOp::Have(cake)
        self.inconsistent_effects_actions = [bake_action, no_ops[3]]

        # the persistence action ~NoOp::Have(cake) has the effect ~Have(cake), which is
        # the logical negation of Have(cake) -- the precondition for the Eat(cake) action
        self.interference_actions = [eat_action, no_ops[3]]

        # eat has precondition Have(cake) and bake has precondition ~Have(cake)
        # which are logical inverses, so eat & bake should be mutex at every
        # level of the planning graph where both actions appear
        self.competing_needs_actions = [eat_action, bake_action]

        self.ac_problem = air_cargo_p1()
        self.ac_pg_serial = PlanningGraph(self.ac_problem,
                                          self.ac_problem.initial).fill()
        # In(C1, P2) and In(C2, P1) have inconsistent support when they first appear in
        # the air cargo problem,
        self.inconsistent_support_literals = [
            expr("In(C1, P2)"), expr("In(C2, P1)")
        ]

        # some independent nodes for testing mutexes
        at_here = expr('At(here)')
        at_there = expr('At(there)')
        self.pos_literals = [at_here, at_there]
        self.neg_literals = [~x for x in self.pos_literals]
        self.literal_layer = LiteralLayer(
            self.pos_literals + self.neg_literals, ActionLayer())
        self.literal_layer.update_mutexes()

        # independent actions for testing mutex
        self.actions = [
            make_node(
                Action(expr('Go(here)'), [set(), set()],
                       [set([at_here]), set()])),
            make_node(
                Action(expr('Go(there)'), [set(), set()],
                       [set([at_there]), set()]))
        ]
        self.no_ops = [
            make_node(x)
            for x in chain(*(makeNoOp(l) for l in self.pos_literals))
        ]
        self.action_layer = ActionLayer(self.no_ops + self.actions,
                                        self.literal_layer)
        self.action_layer.update_mutexes()
        for action in self.no_ops + self.actions:
            self.action_layer.add_inbound_edges(action, action.preconditions)
            self.action_layer.add_outbound_edges(action, action.effects)

        # competing needs tests -- build two copies of the planning graph: one where
        #  A, B, and C are pairwise mutex, and another where they are not
        A, B, C = expr('A'), expr('B'), expr('C')
        self.fake_competing_needs_actions = [
            make_node(
                Action(expr('FakeAction(A)'), [set([A]), set()],
                       [set([A]), set()])),
            make_node(
                Action(expr('FakeAction(B)'), [set([B]), set()],
                       [set([B]), set()])),
            make_node(
                Action(expr('FakeAction(C)'), [set([C]), set()],
                       [set([C]), set()]))
        ]
        competing_layer = LiteralLayer([A, B, C], ActionLayer())
        for a1, a2 in combinations([A, B, C], 2):
            competing_layer.set_mutex(a1, a2)
        self.competing_action_layer = ActionLayer(competing_layer.parent_layer,
                                                  competing_layer, False, True)
        for action in self.fake_competing_needs_actions:
            self.competing_action_layer.add(action)
            competing_layer |= action.effects
            competing_layer.add_outbound_edges(action, action.preconditions)
            self.competing_action_layer.add_inbound_edges(
                action, action.preconditions)
            self.competing_action_layer.add_outbound_edges(
                action, action.effects)

        not_competing_layer = LiteralLayer([A, B, C], ActionLayer())
        self.not_competing_action_layer = ActionLayer(
            not_competing_layer.parent_layer, not_competing_layer, False, True)
        for action in self.fake_competing_needs_actions:
            self.not_competing_action_layer.add(action)
            not_competing_layer |= action.effects
            not_competing_layer.add_outbound_edges(action,
                                                   action.preconditions)
            self.not_competing_action_layer.add_inbound_edges(
                action, action.preconditions)
            self.not_competing_action_layer.add_outbound_edges(
                action, action.effects)
Beispiel #8
0
 def setUp(self):
     #print("in GH setup")
     self.p = have_cake()
     self.pg = PlanningGraph(self.p, self.p.initial)
from example_have_cake import have_cake

from my_planning_graph import PlanningGraph

if __name__ == '__main__':
    p = have_cake()
    graph = PlanningGraph(p, p.initial)
 def setUp(self):
     self.p = have_cake()
     self.pg = PlanningGraph(self.p, self.p.initial)
     print("Setup is good")
                if not pa1.is_mutex(pa2):
                    return False

        return True

    def h_levelsum(self) -> int:
        """The sum of the level costs of the individual goals (admissible if goals independent)

        :return: int
        """
        level_sum = 0
        # for each goal in the problem, determine the level cost, then add them together
        for goal in self.problem.goal:
            found = False  # indicate that the goal was found
            for l, sl in enumerate(self.s_levels):
                for s in sl:
                    if goal == s.symbol and s.is_pos:
                        level_sum += l
                        found = True
                        break
                if found:
                    break

        return level_sum


if __name__ == '__main__':
    from example_have_cake import have_cake
    pc = have_cake()
    pg = PlanningGraph(pc, pc.initial)
    def setUp(self):
        # print("\n===================== TestPlanningGraphHeuristics.....test_inconsistent_support_mutex")

        self.p = have_cake()
        self.pg = PlanningGraph(self.p, self.p.initial)
 def setUp(self):
     # print("\n===================== TestPlanningGraphLevels.....setUp")
     self.p = have_cake()
     self.pg = PlanningGraph(self.p, self.p.initial)
 def setUp(self):
     self.p = have_cake()
     self.pg = PlanningGraph(self.p, self.p.initial)
Beispiel #15
0
 def setUp(self):
     #import pdb;pdb.set_trace()
     self.p = have_cake()
     self.pg = PlanningGraph(self.p, self.p.initial)
Beispiel #16
0
 def setUp(self):
     self.p = have_cake()
     self.pg = PlanningGraph(self.p, self.p.initial)
Beispiel #17
0
 def setUp(self):
     self.p = have_cake() #Run have_cake constructor function to create new instance of have cake problem
     self.pg = PlanningGraph(self.p, self.p.initial) #Create planning graph based on have cake problem passing