C++ Reference: class SharedResponseManager

This documentation is automatically generated.

Manages the global best response kept by the solver. All functions are thread-safe.
Method
AddSolutionCallback

Return type: int

Arguments: std::function<void(const CpSolverResponse&)> callback

Adds a callback that will be called on each new solution (for statisfiablity problem) or each improving new solution (for an optimization problem). Returns its id so it can be unregistered if needed. Note that currently the class is waiting for the callback to finish before accepting any new updates. That could be changed if needed.

AddUnsatCore

Return type: void

Arguments: const std::vector<int>& core

Adds to the shared response a subset of assumptions that are enough to make the problem infeasible.

BestSolutionInnerObjectiveValue

Return type: IntegerValue

Returns the current best solution inner objective value or kInt64Max if there is no solution.

GetInnerObjectiveLowerBound

Return type: IntegerValue

The "inner" objective is the CpModelProto objective without scaling/offset. Note that these bound correspond to valid bound for the problem of finding a strictly better objective than the current one. Thus the lower bound is always a valid bound for the global problem, but the upper bound is NOT.

GetInnerObjectiveUpperBound

Return type: IntegerValue

GetResponse

Return type: CpSolverResponse

Returns the current solver response. That is the best known response at the time of the call with the best feasible solution and objective bounds. Note that the solver statistics correspond to the last time a better solution was found or SetStatsFromModel() was called.

LoadDebugSolution

Return type: void

Arguments: Model*

This should be called after the model is loaded. It will read the file specified by --cp_model_load_debug_solution and properly fill the model->Get() vector. TODO(user): Note that for now, only the IntegerVariable value are loaded, not the value of the pure Booleans variables.

MutableSolutionsRepository

Return type: SharedSolutionRepository<int64>*

NewSolution

Return type: void

Arguments: const CpSolverResponse& response, Model* model

Reads the new solution from the response and update our state. For an optimization problem, we only do something if the solution is strictly improving. TODO(user): Only the following fields from response are accessed here, we might want a tighter API: - solution_info - solution - solution_lower_bounds and solution_upper_bounds.

NotifyThatImprovingProblemIsInfeasible

Return type: void

Arguments: const std::string& worker_info

Changes the solution to reflect the fact that the "improving" problem is infeasible. This means that if we have a solution, we have proven optimality, otherwise the global problem is infeasible. Note that this shouldn't be called before the solution is actually reported. We check for this case in NewSolution().

PrimalIntegral

Return type: double

Returns the integral of the log of the absolute gap over deterministic time. This is mainly used to compare how fast the gap closes on a particular instance. Or to evaluate how efficient our LNS code is improving solution. Important: To report a proper deterministic integral, we only update it on UpdatePrimalIntegral() which should be called in the main subsolver synchronization loop. Note(user): In the litterature, people use the relative gap to the optimal solution (or the best known one), but this is ill defined in many case (like if the optimal cost is zero), so I prefer this version.

ProblemIsSolved

Return type: bool

Returns true if we found the optimal solution or the problem was proven infeasible. Note that if the gap limit is reached, we will also report OPTIMAL and consider the problem solved.

set_dump_prefix

Return type: void

Arguments: const std::string& dump_prefix

Debug only. Set dump prefix for solutions written to file.

SetGapLimitsFromParameters

Return type: void

Arguments: const SatParameters& parameters

Reports OPTIMAL and stop the search if any gap limit are specified and crossed. By default, we only stop when we have the true optimal, which is well defined since we are solving our pure integer problem exactly.

SetStatsFromModel

Return type: void

Arguments: Model* model

Sets the statistics in the response to the one of the solver inside the given in-memory model. This does nothing if the model is nullptr. TODO(user): Also support merging statistics together.

SharedResponseManager

Arguments: bool log_updates, bool enumerate_all_solutions, const CpModelProto* proto, const WallTimer* wall_timer, SharedTimeLimit* shared_time_limit

If log_updates is true, then all updates to the global "state" will be logged. This class is responsible for our solver log progress.

SolutionsRepository

Return type: const SharedSolutionRepository<int64>&

Returns the underlying solution repository where we keep a set of best solutions.

Synchronize

Return type: void

These functions return the same as the non-synchronized() version but only the values at the last time Synchronize() was called.

SynchronizedInnerObjectiveLowerBound

Return type: IntegerValue

SynchronizedInnerObjectiveUpperBound

Return type: IntegerValue

UnregisterCallback

Return type: void

Arguments: int callback_id

UpdateInnerObjectiveBounds

Return type: void

Arguments: const std::string& worker_info, IntegerValue lb, IntegerValue ub

Updates the inner objective bounds.

UpdatePrimalIntegral

Return type: void