예제 #1
0
 def goal_test(self, state: str) -> bool:
     kb = PropKB()
     kb.tell(decode_state(state, self.state_map).pos_sentence())
     for clause in self.goal:
         if clause not in kb.clauses:
             return False
     return True
예제 #2
0
 def actions(self, state: str) -> list:  # of Action
     possible_actions = []
     kb = PropKB()
     kb.tell(decode_state(state, self.state_map).pos_sentence())
     for action in self.actions_list:
         is_possible = True
         for clause in action.precond_pos:
             if clause not in kb.clauses:
                 is_possible = False
         for clause in action.precond_neg:
             if clause in kb.clauses:
                 is_possible = False
         if is_possible:
             possible_actions.append(action)
     return possible_actions
 def actions(self, state: str) -> list:
     # TODO Part 2 implement (see PlanningProblem in helpers.planning_problem)
     possible_actions = []
     kb = PropKB()
     kb.tell(decode_state(state, self.state_map).pos_sentence())
     for action in self.actions_list:
         is_possible = True
         for clause in action.precond_pos:
             if clause not in kb.clauses:
                 is_possible = False
         for clause in action.precond_neg:
             if clause in kb.clauses:
                 is_possible = False
         if is_possible:
             possible_actions.append(action)
     return possible_actions
예제 #4
0
 def result(self, state: str, action: Action):
     new_state = FluentState([], [])
     old_state = decode_state(state, self.state_map)
     for fluent in old_state.pos:
         if fluent not in action.effect_rem:
             new_state.pos.append(fluent)
     for fluent in action.effect_add:
         if fluent not in new_state.pos:
             new_state.pos.append(fluent)
     for fluent in old_state.neg:
         if fluent not in action.effect_add:
             new_state.neg.append(fluent)
     for fluent in action.effect_rem:
         if fluent not in new_state.neg:
             new_state.neg.append(fluent)
     return encode_state(new_state, self.state_map)
 def result(self, state: str, action: Action):
     # TODO implement (see PlanningProblem in helpers.planning_problem)
     new_state = FluentState([], [])
     old_state = decode_state(state, self.state_map)
     for fluent in old_state.pos:
         if fluent not in action.effect_rem:
             new_state.pos.append(fluent)
     for fluent in action.effect_add:
         if fluent not in new_state.pos:
             new_state.pos.append(fluent)
     for fluent in old_state.neg:
         if fluent not in action.effect_add:
             new_state.neg.append(fluent)
     for fluent in action.effect_rem:
         if fluent not in new_state.neg:
             new_state.neg.append(fluent)
     return encode_state(new_state, self.state_map)
 def __init__(self,
              problem: PlanningProblem,
              state: str,
              serial_planning=True):
     '''
     :param problem: PlanningProblem (or subclass such as AirCargoProblem or HaveCakeProblem)
     :param state: str (will be in form TFTTFF... representing fluent states)
     :param serial_planning: bool (whether or not to assume that only one action can occur at a time)
     Instance variable calculated:
         fs: FluentState
             the state represented as positive and negative fluent literal lists
         all_actions: list of the PlanningProblem valid ground actions combined with calculated no-op actions
         s_levels: list of sets of PgNode_s, where each set in the list represents an S-level in the planning graph
         a_levels: list of sets of PgNode_a, where each set in the list represents an A-level in the planning graph
     '''
     self.problem = problem
     self.fs = decode_state(state, problem.state_map)
     self.serial = serial_planning
     self.all_actions = self.problem.actions_list + self.noop_actions(
         self.problem.state_map)
     self.s_levels = []
     self.a_levels = []
     self.create_graph()
예제 #7
0
 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)