ankane / or-tools-ruby

Operations research tools for Ruby
Apache License 2.0
171 stars 20 forks source link

stop_search missing #46

Open glenbray opened 1 year ago

glenbray commented 1 year ago

Hey, so I was trying to convert this code from Python to Ruby using the following employee scheduling guide here. Towards the end, the Python calls StopSearch, but this isn't available in this lib.

Duno if this is the right approach but I had some success adding this definition into constraint.cpp

#include <ortools/sat/swig_helper.h>
using operations_research::sat::SolutionCallback;

Rice::define_class_under<SolutionCallback>(m, "SolutionCallback")
  .define_method("stop_search", &SolutionCallback::StopSearch);

then Updating cp_solver_solution_callback.rb to:

class CpSolverSolutionCallback < SolutionCallback

I could at least call the stop_search function in the NursesPartialSolutionPrinter from the guide. But I got stuck with the atomic bool here:

https://github.com/google/or-tools/blob/5425dedcfbb22cb74c636c1374a9b5ad684b1eb5/ortools/sat/swig_helper.cc#L90

The CPP stuff is a bit beyond me, to be honest 😢.

Any chance the stop_search method could get added?

ankane commented 1 year ago

Hi @glenbray, thanks for the suggestion. Added in the commit above.

ankane commented 1 year ago

Seeing segfaults on Ubuntu - need to dig into it more.