Google OR-Tools v9.11
a fast and portable software suite for combinatorial optimization
|
#include <cp_model_lns.h>
Public Member Functions | |
NeighborhoodGeneratorHelper (CpModelProto const *model_proto, SatParameters const *parameters, SharedResponseManager *shared_response, SharedBoundsManager *shared_bounds=nullptr) | |
bool | TaskIsAvailable () override |
SubSolver interface. | |
std::function< void()> | GenerateTask (int64_t) override |
void | Synchronize () override |
Neighborhood | FixGivenVariables (const CpSolverResponse &base_solution, const absl::flat_hash_set< int > &variables_to_fix) const |
Neighborhood | RelaxGivenVariables (const CpSolverResponse &initial_solution, const std::vector< int > &relaxed_variables) const |
Neighborhood | FixAllVariables (const CpSolverResponse &initial_solution) const |
Neighborhood | FullNeighborhood () const |
Returns a neighborhood that correspond to the full problem. | |
Neighborhood | NoNeighborhood () const |
void | AddSolutionHinting (const CpSolverResponse &initial_solution, CpModelProto *model_proto) const |
bool | IsActive (int var) const ABSL_SHARED_LOCKS_REQUIRED(graph_mutex_) |
std::vector< int > | ActiveVariables () const |
Returns the list of "active" variables. | |
int | NumActiveVariables () const |
std::vector< int > | ActiveObjectiveVariables () const |
bool | DifficultyMeansFullNeighborhood (double difficulty) const |
const std::vector< int > & | ActiveVariablesWhileHoldingLock () const ABSL_SHARED_LOCKS_REQUIRED(graph_mutex_) |
std::vector< int > | ActiveObjectiveVariablesWhileHoldingLock () const ABSL_SHARED_LOCKS_REQUIRED(graph_mutex_) |
const CompactVectorVector< int, int > & | ConstraintToVar () const ABSL_SHARED_LOCKS_REQUIRED(graph_mutex_) |
const CompactVectorVector< int, int > & | VarToConstraint () const ABSL_SHARED_LOCKS_REQUIRED(graph_mutex_) |
absl::Span< const int > | TypeToConstraints (ConstraintProto::ConstraintCase type) const |
Returns all the constraints indices of a given type. | |
std::vector< int > | KeepActiveIntervals (absl::Span< const int > unfiltered_intervals, const CpSolverResponse &initial_solution) const |
std::vector< int > | GetActiveIntervals (const CpSolverResponse &initial_solution) const |
std::vector< std::pair< int, int > > | GetActiveRectangles (const CpSolverResponse &initial_solution) const |
std::vector< std::vector< int > > | GetUniqueIntervalSets () const |
std::vector< std::vector< int > > | GetRoutingPaths (const CpSolverResponse &initial_solution) const |
std::vector< std::pair< int, int > > | GetSchedulingPrecedences (const absl::flat_hash_set< int > &ignored_intervals, const CpSolverResponse &initial_solution, absl::BitGenRef random) const |
CpModelProto | UpdatedModelProtoCopy () const |
Returns a copy of the problem proto with updated domains. | |
const CpModelProto & | ModelProto () const |
const SatParameters & | Parameters () const |
const SharedResponseManager & | shared_response () const |
Public Member Functions inherited from operations_research::sat::SubSolver | |
SubSolver (absl::string_view name, SubsolverType type) | |
virtual | ~SubSolver ()=default |
virtual bool | IsDone () |
double | deterministic_time () const |
std::string | name () const |
Returns the name of this SubSolver. Used in logs. | |
SubsolverType | type () const |
Returns the type of the subsolver. | |
void | AddTaskDuration (double duration_in_seconds) |
void | AddTaskDeterministicDuration (double deterministic_duration) |
std::string | TimingInfo () const |
std::string | DeterministicTimingInfo () const |
Public Attributes | |
absl::Mutex | graph_mutex_ |
Additional Inherited Members | |
Public Types inherited from operations_research::sat::SubSolver | |
enum | SubsolverType { FULL_PROBLEM , FIRST_SOLUTION , INCOMPLETE , HELPER } |
Contains pre-computed information about a given CpModelProto that is meant to be used to generate LNS neighborhood. This class can be shared between more than one generator in order to reduce memory usage.
Definition at line 94 of file cp_model_lns.h.
operations_research::sat::NeighborhoodGeneratorHelper::NeighborhoodGeneratorHelper | ( | CpModelProto const * | model_proto, |
SatParameters const * | parameters, | ||
SharedResponseManager * | shared_response, | ||
SharedBoundsManager * | shared_bounds = nullptr ) |
Initialize proto memory.
Definition at line 68 of file cp_model_lns.cc.
|
inline |
Definition at line 154 of file cp_model_lns.h.
|
inline |
Returns the vector of active objective variables. The graph_mutex_ must be locked before calling this method.
Definition at line 177 of file cp_model_lns.h.
|
inline |
Returns the list of "active" variables.
Definition at line 142 of file cp_model_lns.h.
|
inline |
Returns the vector of active variables. The graph_mutex_ must be locked before calling this method.
Definition at line 170 of file cp_model_lns.h.
void operations_research::sat::NeighborhoodGeneratorHelper::AddSolutionHinting | ( | const CpSolverResponse & | initial_solution, |
CpModelProto * | model_proto ) const |
Adds solution hinting to the neighborhood from the value of the initial solution.
Set the current solution as a hint.
Definition at line 1117 of file cp_model_lns.cc.
|
inline |
Constraints <-> Variables graph. Important:
Definition at line 188 of file cp_model_lns.h.
|
inline |
Definition at line 161 of file cp_model_lns.h.
Neighborhood operations_research::sat::NeighborhoodGeneratorHelper::FixAllVariables | ( | const CpSolverResponse & | initial_solution | ) | const |
Returns a trivial model by fixing all active variables to the initial solution values.
Definition at line 1152 of file cp_model_lns.cc.
Neighborhood operations_research::sat::NeighborhoodGeneratorHelper::FixGivenVariables | ( | const CpSolverResponse & | base_solution, |
const absl::flat_hash_set< int > & | variables_to_fix ) const |
Returns the LNS fragment where the given variables are fixed to the value they take in the given solution.
Fill in neighborhood.delta all variable domains.
We only copy the name in debug mode.
If under the updated domain, the base solution is no longer valid, We should probably regenerate this neighborhood. But for now we just do a best effort and take the closest value.
Fill some statistic fields and detect if we cover a full component.
If the objective domain might cut the optimal solution, we cannot exploit the connected components. We compute this outside the mutex to avoid any deadlock risk.
Definition at line 1007 of file cp_model_lns.cc.
Neighborhood operations_research::sat::NeighborhoodGeneratorHelper::FullNeighborhood | ( | ) | const |
Returns a neighborhood that correspond to the full problem.
Definition at line 388 of file cp_model_lns.cc.
|
inlineoverridevirtual |
Returns a task to run. The task_id is just an ever increasing counter that correspond to the number of total calls to GenerateTask().
This is only called by the main thread.
Implements operations_research::sat::SubSolver.
Definition at line 103 of file cp_model_lns.h.
std::vector< int > operations_research::sat::NeighborhoodGeneratorHelper::GetActiveIntervals | ( | const CpSolverResponse & | initial_solution | ) | const |
Returns the list of indices of active interval constraints according to the initial_solution and the parameter lns_focus_on_performed_intervals. If true, this method returns the list of performed intervals in the solution. If false, it returns all intervals of the model.
Definition at line 443 of file cp_model_lns.cc.
std::vector< std::pair< int, int > > operations_research::sat::NeighborhoodGeneratorHelper::GetActiveRectangles | ( | const CpSolverResponse & | initial_solution | ) | const |
Returns the list of active rectangles appearing in no_overlap_2d constraints according to the initial_solution and the parameter lns_focus_on_performed_intervals. If true, this method returns the list of performed rectangles in the solution. If false, it returns all rectangles of the model.
Definition at line 450 of file cp_model_lns.cc.
std::vector< std::vector< int > > operations_research::sat::NeighborhoodGeneratorHelper::GetRoutingPaths | ( | const CpSolverResponse & | initial_solution | ) | const |
Returns one sub-vector per circuit or per single vehicle circuit in a routes constraints. Each circuit is non empty, and does not contain any self-looping arcs. Path are sorted, starting from the arc with the lowest tail index, and going in sequence up to the last arc before the circuit is closed. Each entry correspond to the arc literal on the circuit.
Collect arcs.
Skip unselected arcs.
Ignore self loops.
Unroll the path.
Collect route starts and arcs.
Skip unselected arcs.
Ignore self loops.
Unroll all routes.
Definition at line 922 of file cp_model_lns.cc.
std::vector< std::pair< int, int > > operations_research::sat::NeighborhoodGeneratorHelper::GetSchedulingPrecedences | ( | const absl::flat_hash_set< int > & | ignored_intervals, |
const CpSolverResponse & | initial_solution, | ||
absl::BitGenRef | random ) const |
Returns all precedences extracted from the scheduling constraint and the initial solution. The precedences will be sorted by the natural order the pairs of integers.
Definition at line 898 of file cp_model_lns.cc.
std::vector< std::vector< int > > operations_research::sat::NeighborhoodGeneratorHelper::GetUniqueIntervalSets | ( | ) | const |
Returns the set of unique intervals list appearing in a no_overlap, cumulative, or as a dimension of a no_overlap_2d constraint.
Definition at line 475 of file cp_model_lns.cc.
bool operations_research::sat::NeighborhoodGeneratorHelper::IsActive | ( | int | var | ) | const |
Indicates if the variable can be frozen. It happens if the variable is non constant, and if it is a decision variable, or if focus_on_decision_variables is false.
Definition at line 378 of file cp_model_lns.cc.
std::vector< int > operations_research::sat::NeighborhoodGeneratorHelper::KeepActiveIntervals | ( | absl::Span< const int > | unfiltered_intervals, |
const CpSolverResponse & | initial_solution ) const |
Filters a vector of intervals against the initial_solution, and returns only the active intervals.
Definition at line 431 of file cp_model_lns.cc.
|
inline |
The initial problem.
Definition at line 249 of file cp_model_lns.h.
Neighborhood operations_research::sat::NeighborhoodGeneratorHelper::NoNeighborhood | ( | ) | const |
Returns a neighborhood that will just be skipped. It usually indicate that the generator failed to generated a neighborhood.
Definition at line 400 of file cp_model_lns.cc.
|
inline |
Definition at line 149 of file cp_model_lns.h.
|
inline |
Definition at line 250 of file cp_model_lns.h.
Neighborhood operations_research::sat::NeighborhoodGeneratorHelper::RelaxGivenVariables | ( | const CpSolverResponse & | initial_solution, |
const std::vector< int > & | relaxed_variables ) const |
Returns the LNS fragment which will relax all inactive variables and all variables in relaxed_variables.
Definition at line 1135 of file cp_model_lns.cc.
|
inline |
Definition at line 252 of file cp_model_lns.h.
|
overridevirtual |
Synchronizes with the external world from this SubSolver point of view. Also incorporate the results of the latest completed tasks if any.
Note(user): The intended implementation for determinism is that tasks update asynchronously (and so non-deterministically) global "shared" classes, but this global state is incorporated by the Subsolver only when Synchronize() is called.
This is only called by the main thread in Subsolver creation order.
This can mean two things: 1/ This variable is a normal one and the problem is UNSAT or 2/ This variable is optional, and its associated literal must be set to false.
Currently, we wait for any full solver to pick the crossing bounds and do the correct stuff on their own. We do not want to have empty domain in the proto as this would means INFEASIBLE. So we just ignore such bounds here.
Only trigger the computation if needed.
Implements operations_research::sat::SubSolver.
Definition at line 93 of file cp_model_lns.cc.
|
inlineoverridevirtual |
SubSolver interface.
Implements operations_research::sat::SubSolver.
Definition at line 102 of file cp_model_lns.h.
|
inline |
Returns all the constraints indices of a given type.
Definition at line 198 of file cp_model_lns.h.
CpModelProto operations_research::sat::NeighborhoodGeneratorHelper::UpdatedModelProtoCopy | ( | ) | const |
Returns a copy of the problem proto with updated domains.
Definition at line 1160 of file cp_model_lns.cc.
|
inline |
Definition at line 192 of file cp_model_lns.h.
|
mutable |
Definition at line 261 of file cp_model_lns.h.