When multiple actions have the same pre-condition, the primary action has to precede the dependent actions. However, the current behavior seems to be that the primary action is placed arbitrarily in the plan step wherein some actions are placed ahead even if the pre-condition is not met.
from action import Action
from planner import Planner
class Action1(Action):
effects = {"FIRST": True}
preconditions = {}
class Action2(Action):
effects = {"SECOND": True}
preconditions = {"FIRST": True}
class Action3(Action):
effects = {"THIRD": True}
preconditions = {"FIRST": True, "SECOND": True}
class Action4(Action):
effects = {"FOURTH": True}
preconditions = {"FIRST": True, "THIRD": True}
if __name__ == "__main__":
world_state = {"FIRST": False, "SECOND": False, "THIRD": False, "FOURTH": False}
goal_state = {"FOURTH": True}
print("Initial State:", world_state)
print("Goal State: ", goal_state)
actions = [Action1(), Action2(), Action3(), Action4()]
planner = Planner(world_state, actions)
plan = planner.find_plan(goal_state)
plan_str = 'PLAN:\n'
for ix, step in enumerate(plan):
plan_str += "....."*(ix+1) + str(step.action) + '\n'
print(plan_str)