airbus / discrete-optimization

Discrete Optimization is a python library to ease the definition and re-use of discrete optimization problems and solvers.
MIT License
42 stars 11 forks source link

CP Solver section in the RCPSP-5 Constraint Programming notebook giving a blank outout #350

Open dadleyAD opened 2 weeks ago

dadleyAD commented 2 weeks ago

The CP Solver section in the RCPSP-5 Constraint Programming.ipynb notebook is not working but simply giving a empty output (len(results) is empty) when the following is run. The Knapsack Constraint Programming section also suffers from this issue.

solver = CpRcpspSolver(problem=rcpsp_problem, cp_solver_name=CpSolverName.CHUFFED)
solver.init_model()
parameters_cp = ParametersCp.default()
results = solver.solve(parameters_cp=parameters_cp, time_limit=20)

In addition the following warning is displayed WARNING:discrete_optimization.generic_tools.cp_tools:local variable 'proc' referenced before assignment

Using latest master branch (394926e59bc40086affc1c700015f92bea7bf043), windows 10, minizinc-python 0.9.0 and minizinc version 2.8.7

Likely an error with the minizinc-python bindings or possibly an update in minizinc itself

nhuet commented 2 weeks ago

I was not able to reproduce with debian 12, minizinc-python 0.9.0 and minizinc version 2.8.7. I will try on windows but I have access only to a windows 11 laptop...

nhuet commented 1 week ago

I did reproduce it on windows. Actually the code itself works if launched from a python script. This is the call to the minizinc solver from within a jupyter notebook under windows which is not working. On linux/macos, we patch asyncio via nest_asyncio.apply() so that minizinc can use an async loop from within the jupyter async loop. But it seems this is not working properly on windows.

So i suggest that you use colab for instance to test the notebook (https://colab.research.google.com/github/airbus/discrete-optimization/blob/master/notebooks/RCPSP%20tutorials/RCPSP-5%20Constraint%20Programming.ipynb) and then that you use the library (the part using minizinc solvers) in scripts rather inside notebooks for now on windows.

(See https://github.com/MiniZinc/minizinc-python/issues/38)