Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add callbacks to pickup_vrp ortools solver #149

Merged
merged 3 commits into from
Jan 30, 2024

Conversation

nhuet
Copy link
Contributor

@nhuet nhuet commented Jan 25, 2024

  • We plug the callbacks to ortools solver by making use of SearchMonitor object
    NB: the on_step_end() is plugged here in the AtSolution() ortools hook. Which means an iteration for d-o Callback corresponds to finding a feasible solution for ortools routing solver.
  • We remove n_solutions parameters from init_solve() as
    • it did not work as intended (should have stopped the solve process after finding n_solutions solutions);
    • it caused segfault when early stopping with callbacks the solve.
  • We implement a NbIterationStopper callback which will stops the optimization when a given number of iterations is reached.
    NB: when using it with ORToolsGPDP, it will correspond to the number solutions found as we hooked in AtSolution(). So this will replace the previous n_solutions parameters.
  • We add tests for ortools solver using such callbacks

- replace AddAtSolutionCallback by AddSearchMonitor
- make RoutingMonitor derive from SearchMonitor
- override/implement AtSolution, EnterSearch, ExitSearch
- plug user-defined callbacks into it
- stop search by raising a dedicated exception (returning False in
  AtSolution does not work, because other SearchMonitor's created at
  solver init according to searchparameters make the search continue
  anyway)
- remove n_solutions from init_model() parameters: is was used for setting
  searchParameters.number_of_solutions_to_collect but
  - it causes segfault error when raising an exception in SearchMonitor
  - it seems not being working as expected (no workingexample found with it)
    see https://stackoverflow.com/questions/57424868/how-to-collect-more-than-one-solution-google-or-tools-tsp
    that use a workaround to collect solutions
- add a test with ortools solver + callbacks

AtSolution() seems to be the simpler place to hook on_step() callback:
we can choose to stop there and the number of found solutions can
simulate a number of iterations.
- use solve() instead of solve_intern()
- remove n_solutions
- decrease time_limit in tests to accelerate them
This will replace previous `n_solutions` arg in `ORToolsGPDP`. See new
test in tests/generic_tools/callbacks/test_ortools_with_callbacks.py.
@nhuet nhuet marked this pull request as ready for review January 29, 2024 09:19
@g-poveda g-poveda merged commit 228df8f into airbus:master Jan 30, 2024
15 of 16 checks passed
@nhuet nhuet deleted the ortools-callbacks branch January 30, 2024 12:26
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants