def setUp(self):
     self.p1 = air_cargo_p1()
     self.act1 = Action(
         expr('Load(C1, P1, SFO)'),
         [[expr('At(C1, SFO)'), expr('At(P1, SFO)')], []],
         [[expr('In(C1, P1)')], [expr('At(C1, SFO)')]]
     )
示例#2
0
    def noop_actions(self, literal_list):
        """create persistent action for each possible fluent

        "No-Op" actions are virtual actions (i.e., actions that only exist in
        the planning graph, not in the planning problem domain) that operate
        on each fluent (literal expression) from the problem domain. No op
        actions "pass through" the literal expressions from one level of the
        planning graph to the next.

        The no-op action list requires both a positive and a negative action
        for each literal expression. Positive no-op actions require the literal
        as a positive precondition and add the literal expression as an effect
        in the output, and negative no-op actions require the literal as a
        negative precondition and remove the literal expression as an effect in
        the output.

        This function should only be called by the class constructor.

        :param literal_list:
        :return: list of Action
        """
        action_list = []
        for fluent in literal_list:
            act1 = Action(expr("Noop_pos({})".format(fluent)), ([fluent], []), ([fluent], []))
            action_list.append(act1)
            act2 = Action(expr("Noop_neg({})".format(fluent)), ([], [fluent]), ([], [fluent]))
            action_list.append(act2)
        return action_list
示例#3
0
        def unload_actions():
            """Create all concrete Unload actions and return a list

            :return: list of Action objects
            Action(Unload(c, p, a),
            """
            unloads = []
            # TODO create all Unload ground actions from the domain Unload action
            for cargo in self.cargos:
                for plane in self.planes:
                    for airport in self.airports:

                        #PRECOND: In(c, p) ∧ At(p, a) ∧ Cargo(c) ∧ Plane(p) ∧ Airport(a)
                        precond_pos = [expr("In({}, {})".format(cargo, plane)),
                                       expr("At({}, {})".format(plane, airport))]
                        precond_neg = []
                        precond = [precond_pos, precond_neg]

                        #EFFECT: At(c, a) ∧ ¬ In(c, p))
                        effect_add = [expr("At({}, {})".format(cargo, airport))]
                        effect_rem = [expr("In({}, {})".format(cargo, plane))]
                        effect = [effect_add, effect_rem]

                        #Action(Unload(c, p, a)
                        unload = Action(expr("Unload({}, {}, {})".format(cargo, plane, airport)), precond, effect)
                        unloads.append(unload)
            return unloads
示例#4
0
def conjunctive_sentence(pos_list, neg_list):
    """ returns expr conjuntive sentence given positive and negative fluent lists

    :param pos_list: list of fluents
    :param neg_list: list of fluents
    :return: expr sentence of fluent conjunction
        e.g. "At(C1, SFO) ∧ ~At(P1, SFO)"
    """
    clauses = []
    for f in pos_list:
        clauses.append(expr("{}".format(f)))
    for f in neg_list:
        clauses.append(expr("~{}".format(f)))
    return associate('&', clauses)
        def unload_actions():
            '''Create all concrete Unload actions and return a list

            :return: list of Action objects
            '''
            unloads = []
            for plane in self.planes:
                for cargo in self.cargos:
                    for airport in self.airports:
                        precond_pos = [expr("In({}, {})".format(cargo, plane)),
                                       expr("At({}, {})".format(plane, airport)),]
                        precond_neg = []
                        effect_add = [expr("At({}, {})".format(cargo, airport))]
                        effect_rem = [expr("In({}, {})".format(cargo, plane))]
                        unload = Action(expr("Unload({}, {}, {})".format(cargo, plane, airport)),
                                      [precond_pos, precond_neg],
                                      [effect_add, effect_rem])
                        unloads.append(unload)
            return unloads
        def unload_actions():
            """Create all concrete Unload actions and return a list

            :return: list of Action objects
            """
            unloads = []
            # TODO create all Unload ground actions from the domain Unload action
            for c in self.cargos:
                for p in self.planes:
                    for a in self.airports:
                        precond_pos = [expr("In({}, {})".format(c, p)), expr("At({}, {})".format(p, a))]
                        precond_neg = []
                        effect_add = [expr("At({}, {})".format(c, a))]
                        effect_rem = [expr("In({}, {})".format(c, p))]
                        unload = Action(expr("Unload({}, {}, {})".format(c, p, a)),
                                        [precond_pos, precond_neg],
                                        [effect_add, effect_rem])
                        unloads.append(unload)
            return unloads
    def __init__(self, symbol: str, is_pos: bool):
        ''' S-level Planning Graph node constructor

        :param symbol: expr
        :param is_pos: bool
        Instance variables calculated:
            literal: expr
                    fluent in its literal form including negative operator if applicable
        Instance variables inherited from PgNode:
            parents: set of nodes connected to this node in previous A level; initially empty
            children: set of nodes connected to this node in next A level; initially empty
            mutex: set of sibling S-nodes that this node has mutual exclusion with; initially empty
        '''
        PgNode.__init__(self)
        self.symbol = symbol
        self.is_pos = is_pos
        self.literal = expr(self.symbol)
        if not self.is_pos:
            self.literal = expr('~{}'.format(self.symbol))
        def fly_actions():
            """Create all concrete Fly actions and return a list

            :return: list of Action objects
            """
            flys = []
            for fr in self.airports:
                for to in self.airports:
                    if fr != to:
                        for p in self.planes:
                            precond_pos = [expr("At({}, {})".format(p, fr)),]
                            precond_neg = []
                            effect_add = [expr("At({}, {})".format(p, to))]
                            effect_rem = [expr("At({}, {})".format(p, fr))]
                            fly = Action(expr("Fly({}, {}, {})".format(p, fr, to)),
                                         [precond_pos, precond_neg],
                                         [effect_add, effect_rem])
                            flys.append(fly)
            return flys
    def test_inconsistent_support_mutex(self):
        self.assertFalse(PlanningGraph.inconsistent_support_mutex(self.pg, self.ns1, self.ns2),
                         "Independent node paths should NOT be inconsistent-support mutex")
        mutexify(self.na1, self.na2)
        self.assertTrue(PlanningGraph.inconsistent_support_mutex(self.pg, self.ns1, self.ns2),
                        "Mutex parent actions should result in inconsistent-support mutex")

        self.na6 = PgNode_a(Action(expr('Go(everywhere)'),
                                   [[], []], [[expr('At(here)'), expr('At(there)')], []]))
        self.na6.children.add(self.ns1)
        self.ns1.parents.add(self.na6)
        self.na6.children.add(self.ns2)
        self.ns2.parents.add(self.na6)
        self.na6.parents.add(self.ns3)
        self.na6.parents.add(self.ns4)
        mutexify(self.na1, self.na6)
        mutexify(self.na2, self.na6)
        self.assertFalse(PlanningGraph.inconsistent_support_mutex(
            self.pg, self.ns1, self.ns2),
            "If one parent action can achieve both states, should NOT be inconsistent-support mutex, even if parent actions are themselves mutex")
        def load_actions():
            """Create all concrete Load actions and return a list

            :return: list of Action objects
            """
            loads = []

            for a in self.airports:
                for p in self.planes:
                    for c in self.cargos:
                        precond_pos = [expr("At({}, {})".format(c, a)),expr("At({}, {})".format(p, a))]
                        precond_neg = []
                        effect_add =  [expr("In({}, {})".format(c, p))]
                        effect_rem = [expr("At({}, {})".format(c, a))]

                        load = Action(expr("Load({}, {}, {})".format(c, p, a)),
                                         [precond_pos, precond_neg],
                                         [effect_add, effect_rem])
                        loads.append(load)

            return loads
示例#11
0
 def get_actions(self):
     precond_pos = [expr("Have(Cake)")]
     precond_neg = []
     effect_add = [expr("Eaten(Cake)")]
     effect_rem = [expr("Have(Cake)")]
     eat_action = Action(expr("Eat(Cake)"),
                         [precond_pos, precond_neg],
                         [effect_add, effect_rem])
     precond_pos = []
     precond_neg = [expr("Have(Cake)")]
     effect_add = [expr("Have(Cake)")]
     effect_rem = []
     bake_action = Action(expr("Bake(Cake)"),
                          [precond_pos, precond_neg],
                          [effect_add, effect_rem])
     return [eat_action, bake_action]
示例#12
0
def air_cargo_p3() -> AirCargoProblem:
    # TODO implement Problem 3 definition
    cargos = ['C1', 'C2', 'C3', 'C4']
    planes = ['P1', 'P2', 'P3', 'P4']
    airports = ['JFK', 'SFO', 'ATL', 'ORD']
    pos = [expr('At(C1, SFO)'),
           expr('At(C2, JFK)'),
           expr('At(C3, ATL)'),
           expr('At(C4, ORD)'),
           expr('At(P1, SFO)'),
           expr('At(P2, JFK)'),
           ]
    neg = [expr('At(C1, JFK)'),
           expr('At(C1, ATL)'),
           expr('At(C1, ORD)'),
           expr('In(C1, P1)'),
           expr('In(C1, P2)'),
           expr('At(C2, SFO)'),
           expr('At(C2, ATL)'),
           expr('At(C2, ORD)'),
           expr('In(C2, P1)'),
           expr('In(C2, P2)'),
           expr('At(C3, JFK)'),
           expr('At(C3, SFO)'),
           expr('At(C3, ORD)'),
           expr('In(C3, P1)'),
           expr('In(C3, P2)'),
           expr('At(C4, JFK)'),
           expr('At(C4, ATL)'),
           expr('At(C4, SFO)'),
           expr('In(C4, P1)'),
           expr('In(C4, P2)'),
           expr('At(P1, JFK)'),
           expr('At(P1, ATL)'),
           expr('At(P1, ORD)'),
           expr('At(P2, SFO)'),
           expr('At(P2, ATL)'),
           expr('At(P2, ORD)')
           ]
    init = FluentState(pos, neg)
    goal = [expr('At(C1, JFK)'),
            expr('At(C2, SFO)'),
            expr('At(C3, JFK)'),
            expr('At(C4, SFO)'),
            ]
    return AirCargoProblem(cargos, planes, airports, init, goal)
def air_cargo_p3(): #-> AirCargoProblem:
    """
    Init(At(C1, SFO) ∧ At(C2, JFK) ∧ At(C3, ATL) ∧ At(C4, ORD)
    	∧ At(P1, SFO) ∧ At(P2, JFK)
    	∧ Cargo(C1) ∧ Cargo(C2) ∧ Cargo(C3) ∧ Cargo(C4)
    	∧ Plane(P1) ∧ Plane(P2)
    	∧ Airport(JFK) ∧ Airport(SFO) ∧ Airport(ATL) ∧ Airport(ORD))
    Goal(At(C1, JFK) ∧ At(C3, JFK) ∧ At(C2, SFO) ∧ At(C4, SFO))
    """

    # TODO implement Problem 3 definition
    # I used similar construct to the air_cargo_p1 to construct air_cargo_p2 and
    # air_cargo_p3. I also used the concepts provided in the class and in the book


    cargos = ['C1', 'C2', 'C3', 'C4']
    planes = ['P1', 'P2']
    airports = ['JFK', 'SFO', 'ATL', 'ORD']
    pos = [expr('At(C1, SFO)'),
           expr('At(C2, JFK)'),
           expr('At(C3, ATL)'),
           expr('At(C4, ORD)'),
           expr('At(P1, SFO)'),
           expr('At(P2, JFK)')
           ]
    neg = [expr('At(C1, JFK)'),
           expr('At(C1, ATL)'),
           expr('At(C1, ORD)'),
           expr('In(C1, P1)'),
           expr('In(C1, P2)'),
           expr('At(P1, JFK)'),
           expr('At(P1, ATL)'),
           expr('At(P1, ORD)'),
           expr('At(C2, SFO)'),
           expr('At(C2, ATL)'),
           expr('At(C2, ORD)'),
           expr('In(C2, P1)'),
           expr('In(C2, P2)'),
           expr('At(P2, SFO)'),
           expr('At(P2, ATL)'),
           expr('At(P2, ORD)'),
           expr('At(C3, SFO)'),
           expr('At(C3, JFK)'),
           expr('At(C3, ORD)'),
           expr('In(C3, P1)'),
           expr('In(C3, P2)'),
           expr('At(C4, SFO)'),
           expr('At(C4, JFK)'),
           expr('At(C4, ATL)'),
           expr('In(C4, P1)'),
           expr('In(C4, P2)'),
           ]
    init = FluentState(pos, neg)
    goal = [expr('At(C1, JFK)'),
            expr('At(C3, JFK)'),
            expr('At(C2, SFO)'),
            expr('At(C4, SFO)')
            ]

    return AirCargoProblem(cargos, planes, airports, init, goal)
示例#14
0
 def pos_sentence(self):
     return expr(conjunctive_sentence(self.pos, []))
def air_cargo_p2() -> AirCargoProblem:
    cargos = ["C1", "C2", "C3"]
    planes = ["P1", "P2", "P3"]
    airports = ["SFO", "JFK", "ATL"]

    pos = [
        expr("At(C1, SFO)"),
        expr("At(C2, JFK)"),
        expr("At(C3, ATL)"),
        expr("At(P1, SFO)"),
        expr("At(P2, JFK)"),
        expr("At(P3, ATL)")
    ]

    neg = [
        expr('At(C1, ATL)'),
        expr('At(C1, JFK)'),
        expr('In(C1, P1)'),
        expr('In(C1, P2)'),
        expr('In(C1, P3)'),
        expr('At(C2, ATL)'),
        expr('At(C2, SFO)'),
        expr('In(C2, P1)'),
        expr('In(C2, P2)'),
        expr('In(C2, P3)'),
        expr('At(C3, JFK)'),
        expr('At(C3, SFO)'),
        expr('In(C3, P1)'),
        expr('In(C3, P2)'),
        expr('In(C3, P3)'),
        expr('At(P1, ATL)'),
        expr('At(P1, JFK)'),
        expr('At(P2, ATL)'),
        expr('At(P2, SFO)'),
        expr('At(P3, JFK)'),
        expr('At(P3, SFO)'),
    ]

    init = FluentState(pos, neg)

    goal = [expr("At(C1, JFK)"), expr("At(C2, SFO)"), expr("At(C3, SFO)")]

    return AirCargoProblem(cargos, planes, airports, init, goal)
示例#16
0
 def make_action_query(self, t):
     return expr("ShouldDo(action, {})".format(t))
示例#17
0
def air_cargo_p1() -> AirCargoProblem:
    cargos = ['C1', 'C2']
    planes = ['P1', 'P2']
    airports = ['JFK', 'SFO']
    pos = [
        expr('At(C1, SFO)'),
        expr('At(C2, JFK)'),
        expr('At(P1, SFO)'),
        expr('At(P2, JFK)'),
    ]
    neg = [
        expr('At(C2, SFO)'),
        expr('In(C2, P1)'),
        expr('In(C2, P2)'),
        expr('At(C1, JFK)'),
        expr('In(C1, P1)'),
        expr('In(C1, P2)'),
        expr('At(P1, JFK)'),
        expr('At(P2, SFO)'),
    ]
    init = FluentState(pos, neg)
    goal = [
        expr('At(C1, JFK)'),
        expr('At(C2, SFO)'),
    ]
    return AirCargoProblem(cargos, planes, airports, init, goal)
        def load_actions():
            """Create all concrete Load actions and return a list
            
            FORMAL EXPRESSION:
            
            Action(Load(c, p, a),
            	PRECOND: At(c, a) ∧ At(p, a) ∧ Cargo(c) ∧ Plane(p) ∧ Airport(a)
            	EFFECT: ¬ At(c, a) ∧ In(c, p))

            :return: list of Action objects
            """

            loads = []
            # TODO create all load ground actions from the domain Load action

            ##
            ## Inspiration: https://medium.com/towards-data-science/ai-planning-historical-developments-edcd9f24c991
            ## we create concrete Action objects based on the domain action schema for: Load
            ##

            # print("\n CARGO: ", self.cargos)
            # print("PLANES: ", self.planes)
            # print("AIRPORTS: ", self.airports)

            for _cargo in self.cargos:
                for _plane in self.planes:
                    for _airport in self.airports:

                        # print("\nCARGO: ", _cargo)
                        # print("PLANES: ", _plane)
                        # print("AIRPORTS: ", _airport)

                        # PRECOND_POS: At(c, a) ∧ At(p, a)
                        # FORMAT: precond_pos = [expr("Human(person)"), expr("Hungry(Person)")]
                        # ENGLISH: There is cargo and a plane at the airport
                        precond_pos = [
                            expr("At({}, {})".format(_cargo, _airport)),
                            expr("At({}, {})".format(_plane, _airport))
                        ]

                        # PRECOND_NEG:
                        # FORMAT: precond_neg = [expr("Eaten(food)")]
                        # ENGLISH: -None-
                        precond_neg = []

                        # FORMAT: effect_add =  [expr("Eaten(food)")]
                        # Add the cargo to the plane
                        # ENGLISH: Add the cargo to the plane
                        effect_add = [
                            expr("In({}, {})".format(_cargo, _plane))
                        ]

                        # FORMAT: effect_rem =  [expr("Hungry(person)")]
                        # ENGLISH: Remove cargo from the airport
                        effect_rem = [
                            expr("At({}, {})".format(_cargo, _airport))
                        ]

                        # Create list of Action objects to be loaded
                        # FORMAT: eat = Action(expr("Eat(person, food)"), [precond_pos, precond_neg], [effect_add, effect_rem])
                        load = Action(
                            expr("Load({}, {}, {})".format(
                                _cargo, _plane,
                                _airport)), [precond_pos, precond_neg],
                            [effect_add, effect_rem])
                        # Append actions to loads list
                        loads.append(load)
            return loads
 def setUp(self):
     self.p1 = air_cargo_p1()
     self.act1 = Action(
         expr('Load(C1, P1, SFO)'),
         [[expr('At(C1, SFO)'), expr('At(P1, SFO)')], []],
         [[expr('In(C1, P1)')], [expr('At(C1, SFO)')]])
def air_cargo_p3() -> AirCargoProblem:
    #TODO implement Problem 3 definition
    cargos = ['C1', 'C2', 'C3', 'C4']
    planes = ['P1', 'P2']
    airports = ['ATL', 'JFK', 'ORD', 'SFO']
    # List where the cargo and planes are
    pos = [
        expr('At(C1, SFO)'),
        expr('At(C2, JFK)'),
        expr('At(C3, ATL)'),
        expr('At(C4, ORD)'),
        expr('At(P1, SFO)'),
        expr('At(P2, JFK)'),
    ]
    # List where the cargo and planes aren't
    neg = [
        expr('At(C1, ATL)'),
        expr('At(C1, JFK)'),
        expr('At(C1, ORD)'),
        expr('At(C2, ATL)'),
        expr('At(C2, ORD)'),
        expr('At(C2, SFO)'),
        expr('At(C3, JFK)'),
        expr('At(C3, ORD)'),
        expr('At(C3, SFO)'),
        expr('At(C4, ATL)'),
        expr('At(C4, JFK)'),
        expr('At(C4, SFO)'),
        expr('At(P1, ATL)'),
        expr('At(P1, JFK)'),
        expr('At(P1, ORD)'),
        expr('At(P2, ATL)'),
        expr('At(P2, ORD)'),
        expr('At(P2, SFO)'),
        expr('In(C1, P1)'),
        expr('In(C1, P2)'),
        expr('In(C2, P1)'),
        expr('In(C2, P2)'),
        expr('In(C3, P1)'),
        expr('In(C3, P2)'),
        expr('In(C4, P1)'),
        expr('In(C4, P2)'),
    ]
    init = FluentState(pos, neg)
    # List goals: C1,C3 -> JFK and C2,C4 -> SFO
    goal = [
        expr('At(C1, JFK)'),
        expr('At(C2, SFO)'),
        expr('At(C3, JFK)'),
        expr('At(C4, SFO)'),
    ]
    return AirCargoProblem(cargos, planes, airports, init, goal)
示例#21
0
def air_cargo_p3() -> AirCargoProblem:
    ''' Initial and goal states encoded for Problem 3
    Init(At(C1, SFO) ∧ At(C2, JFK) ∧ At(C3, ATL) ∧ At(C4, ORD)
    ∧ At(P1, SFO) ∧ At(P2, JFK)
    ∧ Cargo(C1) ∧ Cargo(C2) ∧ Cargo(C3) ∧ Cargo(C4)
    ∧ Plane(P1) ∧ Plane(P2)
    ∧ Airport(JFK) ∧ Airport(SFO) ∧ Airport(ATL) ∧ Airport(ORD))
    Goal(At(C1, JFK) ∧ At(C3, JFK) ∧ At(C2, SFO) ∧ At(C4, SFO))
    '''
    cargos = ['C1', 'C2', 'C3', 'C4']
    planes = ['P1', 'P2']
    airports = ['JFK', 'SFO', 'ATL', 'ORD']
    pos = [
        expr('At(C1, SFO)'),
        expr('At(C2, JFK)'),
        expr('At(C3, ATL)'),
        expr('At(C4, ORD)'),
        expr('At(P1, SFO)'),
        expr('At(P2, JFK)'),
    ]
    neg = [
        expr('At(C2, SFO)'),
        expr('At(C2, ATL)'),
        expr('At(C2, ORD)'),
        expr('In(C2, P1)'),
        expr('In(C2, P2)'),
        expr('At(C1, JFK)'),
        expr('At(C1, ATL)'),
        expr('At(C1, ORD)'),
        expr('In(C1, P1)'),
        expr('In(C1, P2)'),
        expr('At(C3, SFO)'),
        expr('At(C3, JFK)'),
        expr('At(C3, ORD)'),
        expr('In(C3, P1)'),
        expr('In(C3, P2)'),
        expr('At(C4, SFO)'),
        expr('At(C4, ATL)'),
        expr('At(C4, JFK)'),
        expr('In(C4, P1)'),
        expr('In(C4, P2)'),
        expr('At(P1, JFK)'),
        expr('At(P1, ATL)'),
        expr('At(P1, ORD)'),
        expr('At(P2, SFO)'),
        expr('At(P2, ATL)'),
        expr('At(P2, ORD)'),
    ]
    init = FluentState(pos, neg)
    goal = [
        expr('At(C1, JFK)'),
        expr('At(C2, SFO)'),
        expr('At(C3, JFK)'),
        expr('At(C4, SFO)'),
    ]
    return AirCargoProblem(cargos, planes, airports, init, goal)
def air_cargo_p2() -> AirCargoProblem:
    """  
         Problem 2 initial state and goal:
   
         Init(At(C1, SFO) ∧ At(C2, JFK) ∧ At(C3, BOS)∧ At(P1, SFO) ∧ At(P2, JFK) ∧ At(P3, ATL)∧ Cargo(C1) ∧ Cargo(C2)
              ∧ Cargo(C3) ∧ Plane(P1) ∧ Plane(P2) ∧ Plane(P3) ∧ Airport(JFK) ∧ Airport(SFO) ∧ Airport(BOS))
         
         Goal(At(C1, JFK) ∧ At(C2, SFO) ∧ At(C3, SFO))
    """
    cargos = ['C1', 'C2', 'C3']
    planes = ['P1', 'P2', 'P3']
    airports = ['ATL', 'JFK', 'SFO']
    
    pos = [expr('At(C1, SFO)'),
           expr('At(C2, JFK)'),
           expr('At(C3, ATL)'),
           expr('At(P1, SFO)'),
           expr('At(P2, JFK)'),
           expr('At(P3, ATL)'),
           ]
   
    neg = [expr('At(C1, ATL)'),
           expr('At(C1, JFK)'),
           expr('At(C2, ATL)'),
           expr('At(C2, SFO)'),
           expr('At(C3, JFK)'),
           expr('At(C3, SFO)'),
           expr('At(P1, ATL)'),
           expr('At(P1, JFK)'),
           expr('At(P2, ATL)'),
           expr('At(P2, SFO)'),
           expr('At(P3, JFK)'),
           expr('At(P3, SFO)'),
           expr('In(C1, P1)'),
           expr('In(C1, P2)'),
           expr('In(C1, P3)'),
           expr('In(C2, P1)'),
           expr('In(C2, P2)'),
           expr('In(C2, P3)'),
           expr('In(C3, P1)'),
           expr('In(C3, P2)'),
           expr('In(C3, P3)'),
           ]
    init = FluentState(pos, neg)
    
    goal = [expr('At(C1, JFK)'),
            expr('At(C2, SFO)'),
            expr('At(C3, SFO)'),
            ]
    return AirCargoProblem(cargos, planes, airports, init, goal)
示例#23
0
def air_cargo_p2() -> AirCargoProblem:
    # TODO implement Problem 2 definition
    cargos = ['C1', 'C2', 'C3']
    planes = ['P1', 'P2', 'P3']
    airports = ['ATL', 'JFK', 'SFO']
    # List where the cargo and planes are
    pos = [
        expr('At(C1, SFO)'),
        expr('At(C2, JFK)'),
        expr('At(C3, ATL)'),
        expr('At(P1, SFO)'),
        expr('At(P2, JFK)'),
        expr('At(P3, ATL)'),
    ]
    # List where the cargo and planes aren't
    # Indicate that the cargo hasn't been loaded in any of the planes yet
    neg = [
        expr('At(C1, ATL)'),
        expr('At(C1, JFK)'),
        expr('At(C2, ATL)'),
        expr('At(C2, SFO)'),
        expr('At(C3, JFK)'),
        expr('At(C3, SFO)'),
        expr('At(P1, ATL)'),
        expr('At(P1, JFK)'),
        expr('At(P2, ATL)'),
        expr('At(P2, SFO)'),
        expr('At(P3, JFK)'),
        expr('At(P3, SFO)'),
        expr('In(C1, P1)'),
        expr('In(C1, P2)'),
        expr('In(C1, P3)'),
        expr('In(C2, P1)'),
        expr('In(C2, P2)'),
        expr('In(C2, P3)'),
        expr('In(C3, P1)'),
        expr('In(C3, P2)'),
        expr('In(C3, P3)'),
    ]
    init = FluentState(pos, neg)
    # List goals: C1 -> JFK and C2,C3 -> SFO
    goal = [
        expr('At(C1, JFK)'),
        expr('At(C2, SFO)'),
        expr('At(C3, SFO)'),
    ]
    return AirCargoProblem(cargos, planes, airports, init, goal)
示例#24
0
def air_cargo_p2() -> AirCargoProblem:
    airports = ['SFO', 'JFK', 'ATL']
    cargos = ['C1', 'C2', 'C3']
    planes = ['P1', 'P2', 'P3']
    pos = [
        expr('At(C1, SFO)'),
        expr('At(C2, JFK)'),
        expr('At(C3, ATL)'),
        expr('At(P1, SFO)'),
        expr('At(P2, JFK)'),
        expr('At(P3, ATL)'),
    ]
    neg = [
        expr('At(C1, JFK)'),
        expr('At(C1, ATL)'),
        expr('In(C1, P1)'),
        expr('In(C1, p2)'),
        expr('In(C1, p3)'),
        expr('At(C2, SFO)'),
        expr('At(C2, ATL)'),
        expr('In(C2, P1)'),
        expr('In(C2, p2)'),
        expr('In(C2, p3)'),
        expr('At(C3, SFO)'),
        expr('At(C3, JFK)'),
        expr('In(C3, P1)'),
        expr('In(C3, p2)'),
        expr('In(C3, p3)'),
        expr('At(P1, JFK)'),
        expr('At(P1, ATL)'),
        expr('At(P2, SFO)'),
        expr('At(P2, ATL)'),
        expr('At(P3, SFO)'),
        expr('At(P3, JFK)'),
    ]
    init = FluentState(pos, neg)
    goal = [
        expr('At(C1, JFK)'),
        expr('At(C2, SFO)'),
        expr('At(C3, SFO)'),
    ]

    return AirCargoProblem(cargos, planes, airports, init, goal)
示例#25
0
 def pos_sentence(self):
     return expr(conjunctive_sentence(self.pos, []))
示例#26
0
 def sentence(self):
     return expr(conjunctive_sentence(self.pos, self.neg))
def air_cargo_p3() -> AirCargoProblem:

    # TODO implement Problem 3 definition

    ##	∧ Cargo(C1) ∧ Cargo(C2) ∧ Cargo(C3) ∧ Cargo(C4)
    ##	∧ Plane(P1) ∧ Plane(P2)
    ##	∧ Airport(JFK) ∧ Airport(SFO) ∧ Airport(ATL) ∧ Airport(ORD))
    cargos = ['C1', 'C2', 'C3', 'C4']
    planes = ['P1', 'P2']
    airports = ['JFK', 'SFO', 'ATL', 'ORD']

    # At(C1, SFO) ∧ At(C2, JFK) ∧ At(C3, ATL) ∧ At(C4, ORD)
    ##	∧ At(P1, SFO) ∧ At(P2, JFK)
    pos = [
        expr('At(C1, SFO)'),
        expr('At(C2, JFK)'),
        expr('At(C3, ATL)'),
        expr('At(C4, ORD)'),
        expr('At(P1, SFO)'),
        expr('At(P2, JFK)')
    ]

    # The permutations of possibilities to arrive at the  goal state
    #
    neg = [
        expr('At(C1, JFK)'),
        expr('At(C1, ATL)'),
        expr('At(C1, ORD)'),
        expr('In(C1, P1)'),
        expr('In(C1, P2)'),
        expr('At(C2, SFO)'),
        expr('At(C2, ATL)'),
        expr('At(C2, ORD)'),
        expr('In(C2, P1)'),
        expr('In(C2, P2)'),
        expr('At(C3, SFO)'),
        expr('At(C3, JFK)'),
        expr('At(C3, ORD)'),
        expr('In(C3, P1)'),
        expr('In(C3, P2)'),
        expr('At(C4, SFO)'),
        expr('At(C4, JFK)'),
        expr('At(C4, ATL)'),
        expr('In(C4, P1)'),
        expr('In(C4, P2)'),
        expr('At(P1, JFK)'),
        expr('At(P1, ATL)'),
        expr('At(P1, ORD)'),
        expr('At(P2, SFO)'),
        expr('At(P2, ATL)'),
        expr('At(P2, ORD)')
    ]

    init = FluentState(pos, neg)

    ## Goal(At(C1, JFK) ∧ At(C3, JFK) ∧ At(C2, SFO) ∧ At(C4, SFO))
    #
    goal = [
        expr('At(C1, JFK)'),
        expr('At(C3, JFK)'),
        expr('At(C2, SFO)'),
        expr('At(C4, SFO)')
    ]

    return AirCargoProblem(cargos, planes, airports, init, goal)
 def test_AC_result(self):
     fs = decode_state(self.p1.result(self.p1.initial, self.act1),
                       self.p1.state_map)
     self.assertTrue(expr('In(C1, P1)') in fs.pos)
     self.assertTrue(expr('At(C1, SFO)') in fs.neg)
def air_cargo_p2() -> AirCargoProblem:
    # TODO implement Problem 2 definition
    cargos = ['C1', 'C2', 'C3']
    planes = ['P1', 'P2', 'P3']
    airports = ['JFK', 'SFO', 'ATL']
    pos = [
        expr('At(C1, SFO)'),
        expr('At(C2, JFK)'),
        expr('At(C3, ATL)'),
        expr('At(P1, SFO)'),
        expr('At(P2, JFK)'),
        expr('At(P3, ATL)')
    ]
    neg = [
        expr('At(C1, JFK)'),
        expr('At(C1, ATL)'),
        expr('At(C2, SFO)'),
        expr('At(C2, ATL)'),
        expr('At(C3, SFO)'),
        expr('At(C3, JFK)'),
        expr('At(P1, JFK)'),
        expr('At(P1, ATL)'),
        expr('At(P2, SFO)'),
        expr('At(P2, ATL)'),
        expr('At(P3, SFO)'),
        expr('At(P3, JFK)'),
        expr('In(C1, P1)'),
        expr('In(C1, P2)'),
        expr('In(C1, P3)'),
        expr('In(C2, P1)'),
        expr('In(C2, P2)'),
        expr('In(C2, P3)'),
        expr('In(C3, P1)'),
        expr('In(C3, P2)'),
        expr('In(C3, P3)')
    ]
    init = FluentState(pos, neg)
    goal = [expr('At(C1, JFK)'), expr('At(C2, SFO)'), expr('At(C3, SFO)')]
    return AirCargoProblem(cargos, planes, airports, init, goal)
def air_cargo_p3() -> AirCargoProblem:
    #Init(At(C1, SFO) ∧ At(C2, JFK) ∧ At(C3, ATL) ∧ At(C4, ORD) 
    #   ∧ At(P1, SFO) ∧ At(P2, JFK) 
    #   ∧ Cargo(C1) ∧ Cargo(C2) ∧ Cargo(C3) ∧ Cargo(C4)
    #   ∧ Plane(P1) ∧ Plane(P2)
    #   ∧ Airport(JFK) ∧ Airport(SFO) ∧ Airport(ATL) ∧ Airport(ORD))
    #Goal(At(C1, JFK) ∧ At(C3, JFK) ∧ At(C2, SFO) ∧ At(C4, SFO))
    cargos = ['C1', 'C2', 'C3', 'C4']
    planes = ['P1', 'P2']
    airports = ['JFK', 'SFO', 'ATL', 'ORD']
    
    pos = [expr('At(C1, SFO)'),
           expr('At(C2, JFK)'),
           expr('At(C3, ATL)'),
           expr('At(C4, ORD)'),
           expr('At(P1, SFO)'),
           expr('At(P2, JFK)')
           ]
    #All the other possible fluents when actions are taken
    neg = [expr('At(C1, JFK)'),
           expr('At(C1, ATL)'),
           expr('At(C1, ORD)'),
           expr('In(C1, P1)'),
           expr('In(C1, P2)'),
           expr('At(C2, SFO)'),
           expr('At(C2, ATL)'),
           expr('At(C2, ORD)'),
           expr('In(C2, P1)'),
           expr('In(C2, P2)'),
           expr('At(C3, SFO)'),
           expr('At(C3, JFK)'),
           expr('At(C3, ORD)'),
           expr('In(C3, P1)'),
           expr('In(C3, P2)'),
           expr('At(C4, SFO)'),
           expr('At(C4, JFK)'),
           expr('At(C4, ATL)'),
           expr('In(C4, P1)'),
           expr('In(C4, P2)'),
           expr('At(P1, JFK)'),
           expr('At(P1, ATL)'),
           expr('At(P1, ORD)'),
           expr('At(P2, SFO)'),
           expr('At(P2, ATL)'),
           expr('At(P2, ORD)')
           ]
    init = FluentState(pos, neg)
    
    goal = [expr('At(C1, JFK)'),
            expr('At(C3, JFK)'),
            expr('At(C2, SFO)'),
            expr('At(C4, SFO)')
            ]
    return AirCargoProblem(cargos, planes, airports, init, goal)
示例#31
0
def air_cargo_p3() -> AirCargoProblem:
    # TODO implement Problem 3 definition
    # pass
    cargos = ['C1', 'C2', 'C3', 'C4']
    planes = ['P1', 'P2']
    airports = ['JFK', 'SFO', 'ATL', 'ORD']
    pos = [
        expr('At(C1, SFO)'),
        expr('At(C2, JFK)'),
        expr('At(C3, ATL)'),
        expr('At(C4, ORD)'),
        expr('At(P1, SFO)'),
        expr('At(P2, JFK)'),
    ]
    neg = [
        expr('At(C1, JFK)'),
        expr('At(C1, ATL)'),
        expr('At(C1, ORD)'),
        expr('In(C1, P1)'),
        expr('In(C1, P2)'),
        expr('At(C2, SFO)'),
        expr('At(C2, ATL)'),
        expr('At(C2, ORD)'),
        expr('In(C2, P1)'),
        expr('In(C2, P2)'),
        expr('At(C3, SFO)'),
        expr('At(C3, JFK)'),
        expr('At(C3, ORD)'),
        expr('In(C3, P1)'),
        expr('In(C3, P2)'),
        expr('At(C4, SFO)'),
        expr('At(C4, JFK)'),
        expr('At(C4, ATL)'),
        expr('In(C4, P1)'),
        expr('In(C4, P2)'),
        expr('At(P1, JFK)'),
        expr('At(P1, ATL)'),
        expr('At(P1, ORD)'),
        expr('At(P2, SFO)'),
        expr('At(P2, ATL)'),
        expr('At(P2, ORD)'),
    ]
    init = FluentState(pos, neg)
    goal = [
        expr('At(C1, JFK)'),
        expr('At(C3, JFK)'),
        expr('At(C2, SFO)'),
        expr('At(C4, SFO)'),
    ]
    return AirCargoProblem(cargos, planes, airports, init, goal)
def air_cargo_p2() -> AirCargoProblem:
    # TODO implement Problem 2 definition
    # Init(At(C1, SFO) ∧ At(C2, JFK) ∧ At(C3, ATL) 
    #     ∧ At(P1, SFO) ∧ At(P2, JFK) ∧ At(P3, ATL) 
    #     ∧ Cargo(C1) ∧ Cargo(C2) ∧ Cargo(C3)
    #     ∧ Plane(P1) ∧ Plane(P2) ∧ Plane(P3)
    #     ∧ Airport(JFK) ∧ Airport(SFO) ∧ Airport(ATL))
    # Goal(At(C1, JFK) ∧ At(C2, SFO) ∧ At(C3, SFO))
    cargos = ['C1', 'C2', 'C3']
    planes = ['P1', 'P2', 'P3']
    airports = ['JFK', 'SFO', 'ATL']
    pos = [expr('At(C1, SFO)'),
           expr('At(C2, JFK)'),
           expr('At(C3, ATL)'),
           expr('At(P1, SFO)'),
           expr('At(P2, JFK)'),
           expr('At(P3, ATL)'),
           ]
    neg = [expr('At(C1, JFK)'),
           expr('At(C1, ATL)'),
           expr('At(C2, SFO)'),
           expr('At(C2, ATL)'),
           expr('At(C3, SFO)'),
           expr('At(C3, JFK)'),
           expr('In(C1, P1)'),
           expr('In(C1, P2)'),
           expr('In(C1, P3)'),
           expr('In(C2, P1)'),
           expr('In(C2, P2)'),
           expr('In(C2, P3)'),
           expr('In(C3, P1)'),
           expr('In(C3, P2)'),
           expr('In(C3, P3)'),
           expr('At(P1, JFK)'),
           expr('At(P1, ATL)'),
           expr('At(P2, SFO)'),
           expr('At(P2, ATL)'),
           expr('At(P3, SFO)'),
           expr('At(P3, JFK)'),
           ]
    init = FluentState(pos, neg)
    goal = [expr('At(C1, JFK)'),
            expr('At(C2, SFO)'),
            expr('At(C3, SFO)'),
            ]
    return AirCargoProblem(cargos, planes, airports, init, goal)
示例#33
0
        p = agenda.pop()
        if p == q:
            return True
        if not inferred[p]:
            inferred[p] = True
            for c in KB.clauses_with_premise(p):
                count[c] -= 1
                if count[c] == 0:
                    agenda.append(c.args[1])
    return False


""" [Figure 7.13]
Simple inference in a wumpus world example
"""
wumpus_world_inference = expr("(B11 <=> (P12 | P21))  &  ~B11")
""" [Figure 7.16]
Propositional Logic Forward Chaining example
"""
horn_clauses_KB = PropDefiniteKB()
for s in "P==>Q; (L&M)==>P; (B&L)==>M; (A&P)==>L; (A&B)==>L; A;B".split(';'):
    horn_clauses_KB.tell(expr(s))

# ______________________________________________________________________________
# DPLL-Satisfiable [Figure 7.17]


def dpll_satisfiable(s):
    """Check satisfiability of a propositional sentence.
    This differs from the book code in two ways: (1) it returns a model
    rather than True when it succeeds; this is more useful. (2) The
def air_cargo_p3() -> AirCargoProblem:
    """Init(At(C1, SFO) ∧ At(C2, JFK) ∧ At(C3, ATL) ∧ At(C4, ORD) 
    ∧ At(P1, SFO) ∧ At(P2, JFK) 
    ∧ Cargo(C1) ∧ Cargo(C2) ∧ Cargo(C3) ∧ Cargo(C4)
    ∧ Plane(P1) ∧ Plane(P2)
    ∧ Airport(JFK) ∧ Airport(SFO) ∧ Airport(ATL) ∧ Airport(ORD))
Goal(At(C1, JFK) ∧ At(C3, JFK) ∧ At(C2, SFO) ∧ At(C4, SFO))"""
    cargos = ['C1', 'C2', 'C3', 'C4']
    planes = ['P1', 'P2']
    airports = ['JFK', 'SFO', 'ATL', 'ORD']

    pos = [expr('At(C1, SFO)'),
           expr('At(C2, JFK)'),
           expr('At(C3, ATL)'),
           expr('At(C4, ORD)'),         
           expr('At(P1, SFO)'),
           expr('At(P2, JFK)'),

           ]
    neg = [expr('At(C1, JFK)'),
           expr('At(C1, ATL)'),
           expr('At(C1, ORD)'),
           expr('In(C1, P1)'),
           expr('In(C1, P2)'),


           expr('At(C2, SFO)'),
           expr('At(C2, ATL)'),
           expr('At(C2, ORD)'),
           expr('In(C2, P1)'),
           expr('In(C2, P2)'),

           expr('At(C3, SFO)'),
           expr('At(C3, JFK)'),
           expr('At(C3, ORD)'),    
           expr('In(C3, P1)'),
           expr('In(C3, P2)'),


           expr('At(C4, SFO)'),
           expr('At(C4, JFK)'),
           expr('At(C4, ATL)'),    
           expr('In(C4, P1)'),
           expr('In(C4, P2)'),

           expr('At(P1, ATL)'),
           expr('At(P1, JFK)'),
           expr('At(P2, SFO)'),
           expr('At(P2, ATL)'),
           expr('At(P1, ORD)'),
           expr('At(P2, ORD)'),
           ]
    init = FluentState(pos, neg)
    goal = [expr('At(C1, JFK)'),
            expr('At(C2, SFO)'),
            expr('At(C3, JFK)'),
            expr('At(C4, SFO)'),
            ]

    return AirCargoProblem(cargos, planes, airports, init, goal)
示例#35
0
 def sentence(self):
     return expr(conjunctive_sentence(self.pos, self.neg))
def air_cargo_p3() -> AirCargoProblem:
    # TODO implement Problem 3 definition
    '''
    Init(At(C1, SFO) ∧ At(C2, JFK) ∧ At(C3, ATL) ∧ At(C4, ORD)
    ∧ At(P1, SFO) ∧ At(P2, JFK)

    '''

    cargos = ['C1', 'C2', 'C3', 'C4']
    planes = ['P1', 'P2']
    airports = ['JFK', 'SFO', 'ATL', 'ORD']

    pos = [
        expr('At(C1, SFO)'),
        expr('At(C2, JFK)'),
        expr('At(C3, ATL)'),
        expr('At(C4, ORD)'),
        expr('At(P1, SFO)'),
        expr('At(P2, JFK)')
    ]

    negs = []
    for ca in cargos:
        for pl in planes:
            neg = expr('In({}, {})'.format(ca, pl))
            if neg not in negs and neg not in pos:
                negs.append(neg)
            for ap in airports:
                neg = expr('At({}, {})'.format(pl, ap))
                if neg not in negs and neg not in pos:
                    negs.append(neg)
                neg = expr('At({}, {})'.format(ca, ap))
                if neg not in negs and neg not in pos:
                    negs.append(neg)

    init = FluentState(pos, negs)

    # Goal(At(C1, JFK) ∧ At(C3, JFK) ∧ At(C2, SFO) ∧ At(C4, SFO))
    goal = [
        expr('At(C1, JFK)'),
        expr('At(C2, SFO)'),
        expr('At(C3, JFK)'),
        expr('At(C4, SFO)'),
    ]
    return AirCargoProblem(cargos, planes, airports, init, goal)
def air_cargo_p3() -> AirCargoProblem:
    cargos = ['C1', 'C2', 'C3', 'C4']
    planes = ['P1', 'P2']
    airports = ['SFO', 'JFK', 'ATL', 'ORD']
    pos = [
        expr('At(C1, SFO)'),
        expr('At(C2, JFK)'),
        expr('At(C3, ATL)'),
        expr('At(C4, ORD)'),
        expr('At(P1, SFO)'),
        expr('At(P2, JFK)'),
    ]
    neg = set(
        list(
            chain.from_iterable((expr("In({}, {})".format(c, p)),
                                 expr("At({}, {})".format(c, a)),
                                 expr("At({], {}))".format(p, a)))
                                for c in self.cargos for p in self.planes
                                for a in self.airports))).discard(pos)
    #neg= set([(expr("In({}, {})".format(c, p)), expr("At({}, {})".format(c, a)), expr("At({], {}))".format(p, a))) for c in self.cargos for p in self.planes for a in self.airports]).discard(pos)
    init = FluentState(pos, neg)
    goal = [
        expr('At(C1, JFK)'),
        expr('At(C3, JFK)'),
        expr('At(C2, SFO)'),
        expr('At(C4, SFO)')
    ]
    return AirCargoProblem(cargos, planes, airports, init, goal)
示例#38
0
 def make_action_sentence(self, action, t):
     return Expr("Did")(action[expr('action')], t)
 def test_AC_result(self):
     fs = decode_state(self.p1.result(self.p1.initial, self.act1), self.p1.state_map)
     self.assertTrue(expr('In(C1, P1)') in fs.pos)
     self.assertTrue(expr('At(C1, SFO)') in fs.neg)
def air_cargo_p1() -> AirCargoProblem:

    ##	∧ Cargo(C1) ∧ Cargo(C2)
    ##	∧ Plane(P1) ∧ Plane(P2)
    ##	∧ Airport(JFK) ∧ Airport(SFO))
    #
    cargos = ['C1', 'C2']
    planes = ['P1', 'P2']
    airports = ['JFK', 'SFO']

    ## At(P1, SFO) ∧ At(P2, JFK)
    ## Init(At(C1, SFO) ∧ At(C2, JFK)
    #
    pos = [
        expr('At(C1, SFO)'),
        expr('At(C2, JFK)'),
        expr('At(P1, SFO)'),
        expr('At(P2, JFK)'),
    ]

    # The permutations of possibilities to arrive at the  goal state
    #
    neg = [
        expr('At(C2, SFO)'),
        expr('In(C2, P1)'),
        expr('In(C2, P2)'),
        expr('At(C1, JFK)'),
        expr('In(C1, P1)'),
        expr('In(C1, P2)'),
        expr('At(P1, JFK)'),
        expr('At(P2, SFO)'),
    ]

    init = FluentState(pos, neg)

    ## Goal(At(C1, JFK) ∧ At(C2, SFO))
    #
    goal = [
        expr('At(C1, JFK)'),
        expr('At(C2, SFO)'),
    ]

    return AirCargoProblem(cargos, planes, airports, init, goal)
def air_cargo_p3() -> AirCargoProblem:
    """

    Init(At(C1, SFO) ∧ At(C2, JFK) ∧ At(C3, ATL) ∧ At(C4, ORD)
      ∧ At(P1, SFO) ∧ At(P2, JFK)
      ∧ Cargo(C1) ∧ Cargo(C2) ∧ Cargo(C3) ∧ Cargo(C4)
      ∧ Plane(P1) ∧ Plane(P2)
      ∧ Airport(JFK) ∧ Airport(SFO) ∧ Airport(ATL) ∧ Airport(ORD))
    Goal(At(C1, JFK) ∧ At(C3, JFK) ∧ At(C2, SFO) ∧ At(C4, SFO))

    Returns: AirCargoProblem

    """
    # TODO implement Problem 3 definition
    cargos = ['C1', 'C2', 'C3', 'C4']
    planes = ['P1', 'P2']
    airports = ['JFK', 'SFO', 'ATL', 'ORD']
    pos = [
        expr('At(C1, SFO)'),
        expr('At(C2, JFK)'),
        expr('At(C3, ATL)'),
        expr('At(C4, ORD)'),
        expr('At(P1, SFO)'),
        expr('At(P2, JFK)'),
    ]
    neg = [
        expr('At(C4, JFK)'),
        expr('At(C4, SFO)'),
        expr('At(C4, ATL)'),
        expr('In(C4, P1)'),
        expr('In(C4, P2)'),
        expr('At(C3, JFK)'),
        expr('At(C3, SFO)'),
        expr('At(C3, ORD)'),
        expr('In(C3, P1)'),
        expr('In(C3, P2)'),
        expr('At(C2, ATL)'),
        expr('At(C2, SFO)'),
        expr('At(C2, ORD)'),
        expr('In(C2, P1)'),
        expr('In(C2, P2)'),
        expr('At(C1, JFK)'),
        expr('At(C1, ATL)'),
        expr('At(C1, ORD)'),
        expr('In(C1, P1)'),
        expr('In(C1, P2)'),
        expr('At(P1, JFK)'),
        expr('At(P1, ATL)'),
        expr('At(P1, ORD)'),
        expr('At(P2, SFO)'),
        expr('At(P2, ATL)'),
        expr('At(P2, ORD)'),
    ]
    init = FluentState(pos, neg)
    goal = [
        expr('At(C1, JFK)'),
        expr('At(C2, SFO)'),
        expr('At(C3, JFK)'),
        expr('At(C4, SFO)'),
    ]
    return AirCargoProblem(cargos, planes, airports, init, goal)
def air_cargo_p1() -> AirCargoProblem:
    """
        Problem 1
        Initial State:
            (At(C1, SFO) ∧ At(C2, JFK) 
            ∧ At(P1, SFO) ∧ At(P2, JFK) 
            ∧ Cargo(C1) ∧ Cargo(C2) 
            ∧ Plane(P1) ∧ Plane(P2)
            ∧ Airport(JFK) ∧ Airport(SFO))
        Goal State:
            (At(C1, JFK) ∧ At(C2, SFO))
    """
    cargos = ['C1', 'C2']
    planes = ['P1', 'P2']
    airports = ['JFK', 'SFO']
    pos = [
        expr('At(C1, SFO)'),
        expr('At(C2, JFK)'),
        expr('At(P1, SFO)'),
        expr('At(P2, JFK)'),
    ]
    neg = [
        expr('At(C2, SFO)'),
        expr('In(C2, P1)'),
        expr('In(C2, P2)'),
        expr('At(C1, JFK)'),
        expr('In(C1, P1)'),
        expr('In(C1, P2)'),
        expr('At(P1, JFK)'),
        expr('At(P2, SFO)'),
    ]
    init = FluentState(pos, neg)
    goal = [
        expr('At(C1, JFK)'),
        expr('At(C2, SFO)'),
    ]
    return AirCargoProblem(cargos, planes, airports, init, goal)
def air_cargo_p1() -> AirCargoProblem:
    cargos = ['C1', 'C2']
    planes = ['P1', 'P2']
    airports = ['JFK', 'SFO']
    pos = [expr('At(C1, SFO)'),
           expr('At(C2, JFK)'),
           expr('At(P1, SFO)'),
           expr('At(P2, JFK)'),
           ]
    neg = [expr('At(C2, SFO)'),
           expr('In(C2, P1)'),
           expr('In(C2, P2)'),
           expr('At(C1, JFK)'),
           expr('In(C1, P1)'),
           expr('In(C1, P2)'),
           expr('At(P1, JFK)'),
           expr('At(P2, SFO)'),
           ]
    init = FluentState(pos, neg)
    goal = [expr('At(C1, JFK)'),
            expr('At(C2, SFO)'),
            ]
    return AirCargoProblem(cargos, planes, airports, init, goal)
 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)
def air_cargo_p3() -> AirCargoProblem:
    cargos = ['C1', 'C2', 'C3', 'C4']
    planes = ['P1', 'P2']
    airports = ['SFO', 'JFK', 'ATL', 'ORD']
    pos = [
        expr('At(C1,SFO)'),
        expr('At(C2,JFK)'),
        expr('At(C3,ATL)'),
        expr('At(C4,ORD)'),
        expr('At(P1,SFO)'),
        expr('At(P2,JFK)'),
    ]
    neg = [
        expr('At(C1,JFK)'),
        expr('At(C1,ATL)'),
        expr('At(C1,ORD)'),
        expr('At(C2,SFO)'),
        expr('At(C2,ORD)'),
        expr('At(C2,ATL)'),
        expr('At(C3,SFO)'),
        expr('At(C3,JFK)'),
        expr('At(C3,ORD)'),
        expr('At(C4,JFK)'),
        expr('At(C4,ATL)'),
        expr('At(C4,SFO)'),
        expr('In(C1,P1)'),
        expr('In(C1,P2)'),
        expr('In(C2,P1)'),
        expr('In(C2,P2)'),
        expr('In(C3,P1)'),
        expr('In(C3,P2)'),
        expr('In(C4,P1)'),
        expr('In(C4,P2)'),
        expr('At(P1,JFK)'),
        expr('At(P1,ATL)'),
        expr('At(P1,ORD)'),
        expr('At(P2,SFO)'),
        expr('At(P2,ATL)'),
        expr('At(P2,ORD)'),
    ]

    goal = [
        expr('At(C1,JFK)'),
        expr('At(C2,SFO)'),
        expr('At(C3,JFK)'),
        expr('At(C4,SFO)')
    ]
    initial_state = FluentState(pos, neg)
    return AirCargoProblem(cargos, planes, airports, initial_state, goal)
def air_cargo_p3() -> AirCargoProblem:
    # TODO implement Problem 3 definition
    cargos = ['C1', 'C2', 'C3', 'C4']
    planes = ['P1', 'P2']
    airports = ['JFK', 'SFO', 'ATL', 'ORD']

    pos = [
        expr('At(C1, SFO)'),
        expr('At(C2, JFK)'),
        expr('At(C3, ATL)'),
        expr('At(C4, ORD)'),
        expr('At(P1, SFO)'),
        expr('At(P2, JFK)'),
    ]
    # C2

    neg = [
        expr('At(C2, SFO)'),
        expr('At(C2, ATL)'),
        expr('At(C2, ORD)'),
        expr('In(C2, P1)'),
        expr('In(C2, P2)'),
        # C1
        expr('At(C1, JFK)'),
        expr('At(C1, ATL)'),
        expr('At(C1, ORD)'),
        expr('In(C1, P1)'),
        expr('In(C1, P2)'),
        # C3
        expr('At(C3, JFK)'),
        expr('At(C3, SFO)'),
        expr('At(C3, ORD)'),
        expr('In(C3, P1)'),
        expr('In(C3, P2)'),
        # C4
        expr('At(C4, JFK)'),
        expr('At(C4, SFO)'),
        expr('At(C4, ATL)'),
        expr('In(C4, P1)'),
        expr('In(C4, P2)'),
        # P1
        expr('At(P1, JFK)'),
        expr('At(P1, ATL)'),
        expr('At(P1, ORD)'),
        # P2
        expr('At(P2, SFO)'),
        expr('At(P2, ATL)'),
        expr('At(P2, ORD)'),
    ]

    #neg = create_expr_neg_list(pos, cargos, planes, airports)
    init = FluentState(pos, neg)
    goal = [
        expr('At(C1, JFK)'),
        expr('At(C3, JFK)'),
        expr('At(C2, SFO)'),
        expr('At(C4, SFO)'),
    ]
    return AirCargoProblem(cargos, planes, airports, init, goal)
示例#47
0
 def get_goal():
     return [expr('Have(Cake)'),
             expr('Eaten(Cake)'),
             ]
示例#48
0
 def get_goal():
     return [
         expr('Have(Cake)'),
         expr('Eaten(Cake)'),
     ]
示例#49
0
 def get_init():
     pos = [expr('Have(Cake)'),
            ]
     neg = [expr('Eaten(Cake)'),
            ]
     return FluentState(pos, neg)
 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)