aiplan4eu / unified-planning

The AIPlan4EU Unified Planning Library
Apache License 2.0
192 stars 41 forks source link

MultiAgentProblem with IntType fluents causing recursion error when solved using fmap #589

Closed AndrewJamesTurner closed 7 months ago

AndrewJamesTurner commented 7 months ago

Hi,

I am getting a runtime recursion error when solving (fmap) a simple multi-agent problem which uses fluents of IntType.

I will include below a simplified version of the program which cases the same error, a print out of the program to be solved, and the python runtime error message.

Any help would be much appreciated - and apologies in advance if I am doing something obviously wrong (I am fairly new to the unified-planning library)

Thanks

Example program:

from unified_planning.shortcuts import Dot, InstantaneousAction, Fluent, IntType, OneshotPlanner, Equals
from unified_planning.model.multi_agent import MultiAgentProblem, Agent

problem = MultiAgentProblem("Multi Agent")

robot_a = Agent("robot_a", problem)
robot_b = Agent("robot_b", problem)

pos = Fluent("pos", IntType())

move_0 = InstantaneousAction("move_0")
move_0.add_precondition(Equals(pos, 0))
move_0.add_effect(pos, 1)

move_1 = InstantaneousAction("move_1")
move_1.add_precondition(Equals(pos, 1))
move_1.add_effect(pos, 2)

robot_a.add_public_fluent(pos, default_initial_value=False)
robot_a.add_action(move_0)
robot_a.add_action(move_1)

robot_b.add_public_fluent(pos, default_initial_value=False)
robot_b.add_action(move_0)
robot_b.add_action(move_1)

problem.add_agent(robot_a)
problem.add_agent(robot_b)

problem.set_initial_value(Dot(robot_a, pos), 0)
problem.set_initial_value(Dot(robot_b, pos), 1)

problem.add_goal(Equals(Dot(robot_a, pos), 2))
problem.add_goal(Equals(Dot(robot_b, pos), 2))

print(problem)

with OneshotPlanner(name="fmap") as planner:
    result = planner.solve(problem)

Printed problem:

problem name = Multi Agent

environment fluents = [
]

agents = [
  Agent name = robot_a

private fluents = [
]

public fluents = [
 integer pos
]

actions = [
 action move_0 {
    preconditions = [
      (pos == 0)
    ]
    effects = [
      pos := 1
    ]
  }
 action move_1 {
    preconditions = [
      (pos == 1)
    ]
    effects = [
      pos := 2
    ]
  }
]

private goals = [
]

public goals = [
]

  Agent name = robot_b

private fluents = [
]

public fluents = [
 integer pos
]

actions = [
 action move_0 {
    preconditions = [
      (pos == 0)
    ]
    effects = [
      pos := 1
    ]
  }
 action move_1 {
    preconditions = [
      (pos == 1)
    ]
    effects = [
      pos := 2
    ]
  }
]

private goals = [
]

public goals = [
]

]

initial values = [
  robot_a.pos := 0
  robot_b.pos := 1
]

goals = [
  (robot_a.pos == 2)
  (robot_b.pos == 2)
]

Error message:

  File "/home/andy/Documents/code/python/play/task-and-motion-planning/env/lib/python3.12/site-packages/unified_planning/model/multi_agent/ma_problem.py", line 342, in kind
    self._update_problem_kind_fluent(fluent)
  File "/home/andy/Documents/code/python/play/task-and-motion-planning/env/lib/python3.12/site-packages/unified_planning/model/multi_agent/ma_problem.py", line 396, in _update_problem_kind_fluent
    self.kind.set_fluents_type("INT_FLUENTS")
    ^^^^^^^^^
  File "/home/andy/Documents/code/python/play/task-and-motion-planning/env/lib/python3.12/site-packages/unified_planning/model/multi_agent/ma_problem.py", line 342, in kind
    self._update_problem_kind_fluent(fluent)
  File "/home/andy/Documents/code/python/play/task-and-motion-planning/env/lib/python3.12/site-packages/unified_planning/model/multi_agent/ma_problem.py", line 396, in _update_problem_kind_fluent
    self.kind.set_fluents_type("INT_FLUENTS")
    ^^^^^^^^^
  File "/home/andy/Documents/code/python/play/task-and-motion-planning/env/lib/python3.12/site-packages/unified_planning/model/multi_agent/ma_problem.py", line 342, in kind
    self._update_problem_kind_fluent(fluent)
  File "/home/andy/Documents/code/python/play/task-and-motion-planning/env/lib/python3.12/site-packages/unified_planning/model/multi_agent/ma_problem.py", line 396, in _update_problem_kind_fluent
    self.kind.set_fluents_type("INT_FLUENTS")
    ^^^^^^^^^
  File "/home/andy/Documents/code/python/play/task-and-motion-planning/env/lib/python3.12/site-packages/unified_planning/model/multi_agent/ma_problem.py", line 342, in kind
    self._update_problem_kind_fluent(fluent)
  File "/home/andy/Documents/code/python/play/task-and-motion-planning/env/lib/python3.12/site-packages/unified_planning/model/multi_agent/ma_problem.py", line 384, in _update_problem_kind_fluent
    self._update_problem_kind_type(fluent.type)
                                   ^^^^^^^^^^^
RecursionError: maximum recursion depth exceeded
alvalentini commented 7 months ago

Hi @AndrewJamesTurner, thanks for the issue! I fixed the recursion error in #590!

AndrewJamesTurner commented 7 months ago

@alvalentini - I much appreciate the fast response, look forward to trying it out :)