optapy / optapy

OptaPy is an AI constraint solver for Python to optimize planning and scheduling problems.

Home Page:https://www.optapy.org/

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

Launch two solver in a row make the second one crash

adrdv opened this issue · comments

commented

Hello,
I have a problem that I split into two parts.
When I run a first solver with the first part, then at the end a second solver with the second part. The second one crashes systematically with the error : java.lang.RuntimeException: java.lang.IllegalArgumentException: OptaPySolver does not exist in global scope
The strangest thing is that if I change the order of my problems it is always the one I put first that works.
As if running the solver twice would cause it to crash.
Is this a known bug ?

Can you post what code you are running so I can try to replicate it? You should be able to solve multiple time, like so:

solver = solver_factory_create(solver_config).buildSolver()
solution = solver.solve(generate_problem())
solver.solve(solution)

# OR

solver_1 = solver_factory_create(solver_config_1).buildSolver()
solution_1 = solver_1.solve(generate_problem())


solver_2 = solver_factory_create(solver_config_2).buildSolver()
solution_2 = solver_2.solve(solution_1)
commented

Hello,
Thanks for your answer.
I have found the issue who came from a constraint that was using a macro but can't have access since it was outside the scope.
I didn't understand why it works the first time but I have fix the issue.
But I think that the error displayed were not very helpful, for example I did not know what line causes trouble.

That have to do with the fact that the code is not actually executing in Python, but rather Java. Because of this, we lose what source line cause the issue and the original exception, meaning we have to put a generic error message (see jpype-project/jpype#1047). I'll try to improve this in the future (constraints should be able to give the source line, since they are translated; but I probably cannot show a better error message if it occurs outside of constraints/inside code executed in Python that is called from Java).