Open TeXitoi opened 3 years ago
A partial implementation is in Merge Request #31
This adds a solution handler that is called on newly encountered solutions (or improvements in optimization). The search can not yet be stopped (more details below).
The reference implementation https://github.com/google/or-tools/blob/stable/ortools/sat/docs/solver.md?plain=1#L472 states
Please note that it does not work in parallel (i. e. parameter
num_search_workers
> 1).
As mentioned in the ticket #9, it might be desirable to use Fn
instead of FnMut
. As I interpret the above that the search does not work in parallel anyway, it does not seem to matter whether we use Fn
or FnMut
. The implementation right now uses FnMut
, but we can easily change that.
Now it gets weird. I have played around with this based on the reference implementation, but something very strange seems to happen with the C++ part.
Problem: completely unrelated code starts to exibit SIGSEGV when extra_model.GetOrCreate<operations_research::TimeLimit>()
is included.
E.g. the tests/bool_cst.rs
starts to exhibit a SIGSEGV which does not use the new cp_sat_wrapper_solve_with_parameters_and_handler
but the unchanged cp_sat_wrapper_solve
. It seems to fail in the absl
library in absl/container/internal/raw_hash_set.h
in line 1562. It does not fail when using e.g. GetOrCreate<bool>()
, but fails using TimeLimit
as the generic.
I have no idea what is going on, how unrelated code can fail just because a (never used) function call is included in another function. Maybe some C++-magic of generics that affects the Model
globally... Any ideas are appreciated.
need a function in ffi in the form of
Must check if FnMut is possible (CP-SAT must guarantee that the handler will not be called in parallel in any case), else we will use a
Fn
.It must be SAFE! panic safe in particular.
need also the corresponding function in the builder.