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

Commits on Jan 29, 2024

  1. Use SearchMonitor to hook user callbacks at different solve() stages

    - 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.
    nhuet committed Jan 29, 2024
    Configuration menu
    Copy the full SHA
    66021bc View commit details
    Browse the repository at this point in the history
  2. Update tests and examples with new api

    - use solve() instead of solve_intern()
    - remove n_solutions
    - decrease time_limit in tests to accelerate them
    nhuet committed Jan 29, 2024
    Configuration menu
    Copy the full SHA
    234ecc5 View commit details
    Browse the repository at this point in the history
  3. Add a callback to stop solve when a max number of iterations is reached

    This will replace previous `n_solutions` arg in `ORToolsGPDP`. See new
    test in tests/generic_tools/callbacks/test_ortools_with_callbacks.py.
    nhuet committed Jan 29, 2024
    Configuration menu
    Copy the full SHA
    ac67dda View commit details
    Browse the repository at this point in the history