Google OR-Tools v9.12
a fast and portable software suite for combinatorial optimization
Loading...
Searching...
No Matches
operations_research::LocalSearchState Class Reference

#include <constraint_solveri.h>

Classes

class  Variable
 

Public Member Functions

 DEFINE_STRONG_INT_TYPE (VariableDomainId, int)
 
 DEFINE_STRONG_INT_TYPE (ConstraintId, int)
 
VariableDomainId AddVariableDomain (int64_t relaxed_min, int64_t relaxed_max)
 Adds a variable domain to this state, returns a handler to the new domain.
 
bool RelaxVariableDomain (VariableDomainId domain_id)
 Relaxes the domain, returns false iff the domain was already relaxed.
 
bool TightenVariableDomainMin (VariableDomainId domain_id, int64_t value)
 
bool TightenVariableDomainMax (VariableDomainId domain_id, int64_t value)
 
int64_t VariableDomainMin (VariableDomainId domain_id) const
 
int64_t VariableDomainMax (VariableDomainId domain_id) const
 
void ChangeRelaxedVariableDomain (VariableDomainId domain_id, int64_t min, int64_t max)
 
void PropagateRelax (VariableDomainId domain_id)
 Propagation of all events.
 
bool PropagateTighten (VariableDomainId domain_id)
 
Variable MakeVariable (VariableDomainId domain_id)
 
Variable MakeVariableWithRelaxedDomain (int64_t min, int64_t max)
 
void Commit ()
 
void Revert ()
 
bool StateIsFeasible () const
 
void AddWeightedSumConstraint (const std::vector< VariableDomainId > &input_domain_ids, const std::vector< int64_t > &input_weights, int64_t input_offset, VariableDomainId output_domain_id)
 Adds a constraint that output = input_offset + sum_i weight_i * input_i.
 
void CompileConstraints ()
 

Static Public Member Functions

static Variable DummyVariable ()
 Makes a variable with no state, this is meant as a placeholder.
 

Detailed Description

A LocalSearchState is a container for variables with domains that can be relaxed and tightened, saved and restored. It represents the solution state of a local search engine, and allows it to go from solution to solution by relaxing some variables to form a new subproblem, then tightening those variables to move to a new solution representation. That state may be saved to an internal copy, or reverted to the last saved internal copy. Relaxing a variable returns its bounds to their initial state. Tightening a variable's bounds may make its min larger than its max, in that case, the tightening function will return false, and the state will be marked as invalid. No other operations than Revert() can be called on an invalid state: in particular, an invalid state cannot be saved.

Definition at line 2799 of file constraint_solveri.h.

Member Function Documentation

◆ AddVariableDomain()

VariableDomainId operations_research::LocalSearchState::AddVariableDomain ( int64_t relaxed_min,
int64_t relaxed_max )

Adds a variable domain to this state, returns a handler to the new domain.

Definition at line 2988 of file local_search.cc.

◆ AddWeightedSumConstraint()

void operations_research::LocalSearchState::AddWeightedSumConstraint ( const std::vector< VariableDomainId > & input_domain_ids,
const std::vector< int64_t > & input_weights,
int64_t input_offset,
VariableDomainId output_domain_id )

Adds a constraint that output = input_offset + sum_i weight_i * input_i.

Store domain/constraint dependencies.

Store constraint.

Definition at line 3177 of file local_search.cc.

◆ ChangeRelaxedVariableDomain()

void operations_research::LocalSearchState::ChangeRelaxedVariableDomain ( VariableDomainId domain_id,
int64_t min,
int64_t max )

Definition at line 3067 of file local_search.cc.

◆ Commit()

void operations_research::LocalSearchState::Commit ( )
Todo
(user): When the class has more users, find a threshold ratio of saved/total domains under which a sparse clear would be more efficient for both Commit() and Revert().

Clear domains trail.

Clear constraint trail.

Definition at line 3087 of file local_search.cc.

◆ CompileConstraints()

void operations_research::LocalSearchState::CompileConstraints ( )

Precomputes which domain change triggers which constraint(s). Should be run after adding all constraints, before any Relax()/Tighten().

Definition at line 3203 of file local_search.cc.

◆ DEFINE_STRONG_INT_TYPE() [1/2]

operations_research::LocalSearchState::DEFINE_STRONG_INT_TYPE ( ConstraintId ,
int  )

◆ DEFINE_STRONG_INT_TYPE() [2/2]

operations_research::LocalSearchState::DEFINE_STRONG_INT_TYPE ( VariableDomainId ,
int  )

◆ DummyVariable()

LocalSearchState::Variable operations_research::LocalSearchState::DummyVariable ( )
static

Makes a variable with no state, this is meant as a placeholder.

Definition at line 3009 of file local_search.cc.

◆ MakeVariable()

LocalSearchState::Variable operations_research::LocalSearchState::MakeVariable ( VariableDomainId domain_id)

Makes a variable, an object with restricted operations on the underlying domain identified by domain_id: only Relax, Tighten and Min/Max read operations are available.

Definition at line 2998 of file local_search.cc.

◆ MakeVariableWithRelaxedDomain()

LocalSearchState::Variable operations_research::LocalSearchState::MakeVariableWithRelaxedDomain ( int64_t min,
int64_t max )

Makes a variable from an interval without going through a domain_id. Can be used when no direct manipulation of the domain is needed.

Definition at line 3003 of file local_search.cc.

◆ PropagateRelax()

void operations_research::LocalSearchState::PropagateRelax ( VariableDomainId domain_id)

Propagation of all events.

Definition at line 3378 of file local_search.cc.

◆ PropagateTighten()

bool operations_research::LocalSearchState::PropagateTighten ( VariableDomainId domain_id)

Definition at line 3388 of file local_search.cc.

◆ RelaxVariableDomain()

bool operations_research::LocalSearchState::RelaxVariableDomain ( VariableDomainId domain_id)

Relaxes the domain, returns false iff the domain was already relaxed.

Definition at line 3013 of file local_search.cc.

◆ Revert()

void operations_research::LocalSearchState::Revert ( )

Revert trailed domains.

Revert trailed constraints.

Definition at line 3100 of file local_search.cc.

◆ StateIsFeasible()

bool operations_research::LocalSearchState::StateIsFeasible ( ) const
inline

Definition at line 2829 of file constraint_solveri.h.

◆ TightenVariableDomainMax()

bool operations_research::LocalSearchState::TightenVariableDomainMax ( VariableDomainId domain_id,
int64_t value )

Definition at line 3055 of file local_search.cc.

◆ TightenVariableDomainMin()

bool operations_research::LocalSearchState::TightenVariableDomainMin ( VariableDomainId domain_id,
int64_t value )

Definition at line 3043 of file local_search.cc.

◆ VariableDomainMax()

int64_t operations_research::LocalSearchState::VariableDomainMax ( VariableDomainId domain_id) const

Definition at line 3038 of file local_search.cc.

◆ VariableDomainMin()

int64_t operations_research::LocalSearchState::VariableDomainMin ( VariableDomainId domain_id) const

Definition at line 3033 of file local_search.cc.


The documentation for this class was generated from the following files: