ankane / or-tools-ruby

Operations research tools for Ruby
Apache License 2.0
173 stars 22 forks source link

Setting a max time for a solver. #8

Closed braindeaf closed 3 years ago

braindeaf commented 3 years ago

I'm trying to find out how to hook into CPModel in order to set in the same way that it does here

https://developers.google.com/optimization/cp/cp_tasks#c++

  // Solving part.
  Model model;

  // Sets a time limit of 10 seconds.
  SatParameters parameters;
  parameters.set_max_time_in_seconds(10.0);
  model.Add(NewSatParameters(parameters));

As far as I can see this isn't available at the moment. Is that right?

Basically, at the moment our solver keeps going and only stops on Ctrl-C and I'd like to see what the result is after 10, or 20 seconds or whatever.

ankane commented 3 years ago

Hey @braindeaf, thanks for reporting! Added to master: https://github.com/ankane/or-tools#setting-solver-limits.

braindeaf commented 3 years ago

Oh wow, I wasn't expecting such an efficient turn around (if at all :p). Thank you very much. This whole solving world is really brain crunching and still pretty magic to me at the moment. Really appreciating the work you've done on this.

ankane commented 3 years ago

No problem. Let me know if you find other features that are missing.

Also, fwiw, I found this video series to be a great intro to linear programming: https://www.youtube.com/watch?v=0TD9EQcheZM (not needed to use the library/solve really interesting problems, but gives an idea about how it works)

braindeaf commented 3 years ago

I will report back if I find anything else of course. I think my biggest problem is getting my head round the concepts. And then translating that back into legible code. Next step is to convert this example into Ruby as this matches many of our requirements, with the exception of evenly spreading out shifts over time.

https://github.com/google/or-tools/blob/master/examples/python/shift_scheduling_sat.py

This will be a fun exercise I hope. Thank you for the video. I'll pop it on now.