operations_research::PathOperator Class Referenceabstract

Detailed Description

Base class of the local search operators dedicated to path modifications (a path is a set of nodes linked together by arcs).

This family of neighborhoods supposes they are handling next variables representing the arcs (var[i] represents the node immediately after i on a path). Several services are provided:

  • arc manipulators (SetNext(), ReverseChain(), MoveChain())
  • path inspectors (Next(), IsPathEnd())
  • path iterators: operators need a given number of nodes to define a neighbor; this class provides the iteration on a given number of (base) nodes which can be used to define a neighbor (through the BaseNode method) Subclasses only need to override MakeNeighbor to create neighbors using the services above (no direct manipulation of assignments).

Definition at line 1261 of file constraint_solveri.h.

Public Member Functions

 PathOperator (const std::vector< IntVar * > &next_vars, const std::vector< IntVar * > &path_vars, int number_of_base_nodes, bool skip_locally_optimal_paths, std::function< int(int64)> start_empty_path_class)
 Builds an instance of PathOperator from next and path variables. More...
 
 ~PathOperator () override
 
virtual bool MakeNeighbor ()=0
 
void Reset () override
 
bool SkipUnchanged (int index) const override
 
int64 Next (int64 node_index) const
 Returns the index of the node after the node of index node_index in the current assignment. More...
 
int64 Path (int64 node_index) const
 Returns the index of the path to which the node of index node_index belongs in the current assignment. More...
 
int number_of_nexts () const
 Number of next variables. More...
 
bool MakeNextNeighbor (Assignment *delta, Assignment *deltadelta) override
 Redefines MakeNextNeighbor to export a simpler interface. More...
 
bool HoldsDelta () const override
 
void Start (const Assignment *assignment) override
 This method should not be overridden. More...
 
virtual bool IsIncremental () const
 
int Size () const
 
const int64 & Value (int64 index) const
 Returns the value in the current assignment of the variable of given index. More...
 
IntVarVar (int64 index) const
 Returns the variable of given index. More...
 
const int64 & OldValue (int64 index) const
 
void SetValue (int64 index, const int64 &value)
 
bool Activated (int64 index) const
 
void Activate (int64 index)
 
void Deactivate (int64 index)
 
bool ApplyChanges (Assignment *delta, Assignment *deltadelta) const
 
void RevertChanges (bool incremental)
 
void AddVars (const std::vector< IntVar * > &vars)
 
virtual const LocalSearchOperatorSelf () const
 
virtual bool HasFragments () const
 
virtual std::string DebugString () const
 

Protected Member Functions

bool MakeOneNeighbor () override
 This method should not be overridden. Override MakeNeighbor() instead. More...
 
int64 BaseNode (int i) const
 Returns the index of the variable corresponding to the ith base node. More...
 
int64 StartNode (int i) const
 Returns the index of the variable corresponding to the current path of the ith base node. More...
 
const std::vector< int64 > & path_starts () const
 Returns the vector of path start nodes. More...
 
int PathClass (int i) const
 Returns the class of the current path of the ith base node. More...
 
virtual bool RestartAtPathStartOnSynchronize ()
 When the operator is being synchronized with a new solution (when Start() is called), returns true to restart the exploration of the neighborhood from the start of the last paths explored; returns false to restart the exploration at the last nodes visited. More...
 
virtual bool OnSamePathAsPreviousBase (int64 base_index)
 Returns true if a base node has to be on the same path as the "previous" base node (base node of index base_index - 1). More...
 
virtual int64 GetBaseNodeRestartPosition (int base_index)
 Returns the index of the node to which the base node of index base_index must be set to when it reaches the end of a path. More...
 
virtual void SetNextBaseToIncrement (int64 base_index)
 Set the next base to increment on next iteration. More...
 
int64 OldNext (int64 node_index) const
 
int64 OldPath (int64 node_index) const
 
bool MoveChain (int64 before_chain, int64 chain_end, int64 destination)
 Moves the chain starting after the node before_chain and ending at the node chain_end after the node destination. More...
 
bool ReverseChain (int64 before_chain, int64 after_chain, int64 *chain_last)
 Reverses the chain starting after before_chain and ending before after_chain. More...
 
bool MakeActive (int64 node, int64 destination)
 
bool MakeChainInactive (int64 before_chain, int64 chain_end)
 
void SetNext (int64 from, int64 to, int64 path)
 Sets the to to be the node after from. More...
 
bool IsPathEnd (int64 i) const
 Returns true if i is the last node on the path; defined by the fact that i outside the range of the variable array. More...
 
bool IsInactive (int64 i) const
 Returns true if node is inactive. More...
 
virtual bool InitPosition () const
 Returns true if operator needs to restart its initial position at each call to Start() More...
 
void ResetPosition ()
 Reset the position of the operator to its position when Start() was last called; this can be used to let an operator iterate more than once over the paths. More...
 
void MarkChange (int64 index)
 OnStart() should really be protected, but then SWIG doesn't see it. More...
 

Protected Attributes

const int number_of_nexts_
 
const bool ignore_path_vars_
 
int next_base_to_increment_
 
int num_paths_ = 0
 
std::vector< int64 > start_to_path_
 
std::vector< IntVar * > vars_
 
std::vector< int64 > values_
 
std::vector< int64 > old_values_
 
std::vector< int64 > prev_values_
 
std::vector< int > assignment_indices_
 
Bitset64 activated_
 
Bitset64 was_activated_
 
SparseBitset changes_
 
SparseBitset delta_changes_
 
bool cleared_
 
IntVarLocalSearchHandler var_handler_
 

Constructor & Destructor Documentation

◆ PathOperator()

operations_research::PathOperator::PathOperator ( const std::vector< IntVar * > &  next_vars,
const std::vector< IntVar * > &  path_vars,
int  number_of_base_nodes,
bool  skip_locally_optimal_paths,
std::function< int(int64)>  start_empty_path_class 
)

Builds an instance of PathOperator from next and path variables.

'number_of_base_nodes' is the number of nodes needed to define a neighbor. 'start_empty_path_class' is a callback returning an index such that if c1 = start_empty_path_class(StartNode(p1)), c2 = start_empty_path_class(StartNode(p2)), p1 and p2 are path indices, then if c1 == c2, p1 and p2 are equivalent if they are empty. This is used to remove neighborhood symmetries on equivalent empty paths; for instance if a node cannot be moved to an empty path, then all moves moving the same node to equivalent empty paths will be skipped. 'start_empty_path_class' can be nullptr in which case no symmetries will be removed.

◆ ~PathOperator()

operations_research::PathOperator::~PathOperator ( )
inlineoverride

Definition at line 1280 of file constraint_solveri.h.

Member Function Documentation

◆ Activate()

void operations_research::VarLocalSearchOperator< IntVar , int64 , IntVarLocalSearchHandler >::Activate ( int64  index)
inlineinherited

Definition at line 863 of file constraint_solveri.h.

◆ Activated()

bool operations_research::VarLocalSearchOperator< IntVar , int64 , IntVarLocalSearchHandler >::Activated ( int64  index) const
inlineinherited

Definition at line 862 of file constraint_solveri.h.

◆ AddVars()

void operations_research::VarLocalSearchOperator< IntVar , int64 , IntVarLocalSearchHandler >::AddVars ( const std::vector< IntVar * > &  vars)
inlineinherited

Definition at line 908 of file constraint_solveri.h.

◆ ApplyChanges()

bool operations_research::VarLocalSearchOperator< IntVar , int64 , IntVarLocalSearchHandler >::ApplyChanges ( Assignment delta,
Assignment deltadelta 
) const
inlineinherited

Definition at line 871 of file constraint_solveri.h.

◆ BaseNode()

int64 operations_research::PathOperator::BaseNode ( int  i) const
inlineprotected

Returns the index of the variable corresponding to the ith base node.

Definition at line 1308 of file constraint_solveri.h.

◆ Deactivate()

void operations_research::VarLocalSearchOperator< IntVar , int64 , IntVarLocalSearchHandler >::Deactivate ( int64  index)
inlineinherited

Definition at line 867 of file constraint_solveri.h.

◆ DebugString()

virtual std::string operations_research::BaseObject::DebugString ( ) const
inlinevirtualinherited

Reimplemented in operations_research::Pack, operations_research::Assignment, operations_research::SequenceVar, operations_research::RegularLimit, operations_research::SearchLimit, operations_research::OptimizeVar, operations_research::SolutionCollector, operations_research::IntVarIterator, operations_research::Constraint, operations_research::CPFeasibilityFilter, operations_research::Demon, operations_research::DecisionBuilder, operations_research::Decision, operations_research::ChristofidesFilteredDecisionBuilder, operations_research::ParallelSavingsFilteredDecisionBuilder, operations_research::PropagationBaseObject, operations_research::SequentialSavingsFilteredDecisionBuilder, operations_research::ComparatorCheapestAdditionFilteredDecisionBuilder, operations_research::EvaluatorCheapestAdditionFilteredDecisionBuilder, operations_research::LocalCheapestInsertionFilteredDecisionBuilder, operations_research::GlobalCheapestInsertionFilteredDecisionBuilder, operations_research::ArrayWithOffset< T >, operations_research::SearchLog, operations_research::BooleanVar, operations_research::LocalSearchMonitor, operations_research::PropagationMonitor, operations_research::LocalSearchFilterManager, operations_research::PathWithPreviousNodesOperator, operations_research::DelayedCallMethod2< T, P, Q >, operations_research::DelayedCallMethod1< T, P >, operations_research::DelayedCallMethod0< T >, operations_research::CallMethod3< T, P, Q, R >, operations_research::CallMethod2< T, P, Q >, operations_research::CallMethod1< T, P >, operations_research::ExchangeSubtrip, operations_research::RelocateSubtrip, operations_research::CallMethod0< T >, operations_research::PairNodeSwapActiveOperator< swap_first >, operations_research::RelocateExpensiveChain, operations_research::IndexPairSwapActiveOperator, operations_research::SwapIndexPairOperator, operations_research::PairExchangeRelocateOperator, operations_research::PairExchangeOperator, operations_research::LightPairRelocateOperator, operations_research::PairRelocateOperator, operations_research::MakePairInactiveOperator, operations_research::MakePairActiveOperator, and operations_research::MakeRelocateNeighborsOperator.

Definition at line 3093 of file constraint_solver.h.

◆ GetBaseNodeRestartPosition()

virtual int64 operations_research::PathOperator::GetBaseNodeRestartPosition ( int  base_index)
inlineprotectedvirtual

Returns the index of the node to which the base node of index base_index must be set to when it reaches the end of a path.

By default, it is set to the start of the current path. When this method is called, one can only assume that base nodes with indices < base_index have their final position.

Reimplemented in operations_research::PairNodeSwapActiveOperator< swap_first >, operations_research::PairExchangeRelocateOperator, operations_research::PairRelocateOperator, and operations_research::MakePairActiveOperator.

Definition at line 1340 of file constraint_solveri.h.

◆ HasFragments()

virtual bool operations_research::LocalSearchOperator::HasFragments ( ) const
inlinevirtualinherited

Reimplemented in operations_research::BaseLns.

Definition at line 815 of file constraint_solveri.h.

◆ HoldsDelta()

bool operations_research::VarLocalSearchOperator< IntVar , int64 , IntVarLocalSearchHandler >::HoldsDelta ( ) const
inlineoverridevirtualinherited

Reimplemented from operations_research::LocalSearchOperator.

Definition at line 830 of file constraint_solveri.h.

◆ InitPosition()

virtual bool operations_research::PathOperator::InitPosition ( ) const
inlineprotectedvirtual

Returns true if operator needs to restart its initial position at each call to Start()

Definition at line 1388 of file constraint_solveri.h.

◆ IsInactive()

bool operations_research::PathOperator::IsInactive ( int64  i) const
inlineprotected

Returns true if node is inactive.

Definition at line 1384 of file constraint_solveri.h.

◆ IsIncremental()

virtual bool operations_research::VarLocalSearchOperator< IntVar , int64 , IntVarLocalSearchHandler >::IsIncremental ( ) const
inlinevirtualinherited

Definition at line 846 of file constraint_solveri.h.

◆ IsPathEnd()

bool operations_research::PathOperator::IsPathEnd ( int64  i) const
inlineprotected

Returns true if i is the last node on the path; defined by the fact that i outside the range of the variable array.

Definition at line 1381 of file constraint_solveri.h.

◆ MakeActive()

bool operations_research::PathOperator::MakeActive ( int64  node,
int64  destination 
)
protected

◆ MakeChainInactive()

bool operations_research::PathOperator::MakeChainInactive ( int64  before_chain,
int64  chain_end 
)
protected

◆ MakeNeighbor()

◆ MakeNextNeighbor()

bool operations_research::IntVarLocalSearchOperator::MakeNextNeighbor ( Assignment delta,
Assignment deltadelta 
)
overridevirtualinherited

Redefines MakeNextNeighbor to export a simpler interface.

The calls to ApplyChanges() and RevertChanges() are factored in this method, hiding both delta and deltadelta from subclasses which only need to override MakeOneNeighbor(). Therefore this method should not be overridden. Override MakeOneNeighbor() instead.

Implements operations_research::LocalSearchOperator.

Reimplemented in operations_research::PairNodeSwapActiveOperator< swap_first >, operations_research::IndexPairSwapActiveOperator, operations_research::SwapIndexPairOperator, and operations_research::MakePairActiveOperator.

◆ MakeOneNeighbor()

bool operations_research::PathOperator::MakeOneNeighbor ( )
overrideprotectedvirtual

This method should not be overridden. Override MakeNeighbor() instead.

Reimplemented from operations_research::IntVarLocalSearchOperator.

Reimplemented in operations_research::RelocateExpensiveChain.

◆ MarkChange()

void operations_research::VarLocalSearchOperator< IntVar , int64 , IntVarLocalSearchHandler >::MarkChange ( int64  index)
inlineprotectedinherited

OnStart() should really be protected, but then SWIG doesn't see it.

So we make it public, but only subclasses should access to it (to override it).

Definition at line 932 of file constraint_solveri.h.

◆ MoveChain()

bool operations_research::PathOperator::MoveChain ( int64  before_chain,
int64  chain_end,
int64  destination 
)
protected

Moves the chain starting after the node before_chain and ending at the node chain_end after the node destination.

◆ Next()

int64 operations_research::PathOperator::Next ( int64  node_index) const
inline

Returns the index of the node after the node of index node_index in the current assignment.

Definition at line 1289 of file constraint_solveri.h.

◆ number_of_nexts()

int operations_research::PathOperator::number_of_nexts ( ) const
inline

Number of next variables.

Definition at line 1301 of file constraint_solveri.h.

◆ OldNext()

int64 operations_research::PathOperator::OldNext ( int64  node_index) const
inlineprotected

Definition at line 1349 of file constraint_solveri.h.

◆ OldPath()

int64 operations_research::PathOperator::OldPath ( int64  node_index) const
inlineprotected

Definition at line 1354 of file constraint_solveri.h.

◆ OldValue()

const int64 & operations_research::VarLocalSearchOperator< IntVar , int64 , IntVarLocalSearchHandler >::OldValue ( int64  index) const
inlineinherited

Definition at line 857 of file constraint_solveri.h.

◆ OnSamePathAsPreviousBase()

virtual bool operations_research::PathOperator::OnSamePathAsPreviousBase ( int64  base_index)
inlineprotectedvirtual

Returns true if a base node has to be on the same path as the "previous" base node (base node of index base_index - 1).

Useful to limit neighborhood exploration to nodes on the same path. it's currently way more complicated to implement.

Reimplemented in operations_research::PairNodeSwapActiveOperator< swap_first >, operations_research::PairExchangeRelocateOperator, operations_research::PairRelocateOperator, and operations_research::MakePairActiveOperator.

Definition at line 1334 of file constraint_solveri.h.

◆ Path()

int64 operations_research::PathOperator::Path ( int64  node_index) const
inline

Returns the index of the path to which the node of index node_index belongs in the current assignment.

Definition at line 1296 of file constraint_solveri.h.

◆ path_starts()

const std::vector<int64>& operations_research::PathOperator::path_starts ( ) const
inlineprotected

Returns the vector of path start nodes.

Definition at line 1313 of file constraint_solveri.h.

◆ PathClass()

int operations_research::PathOperator::PathClass ( int  i) const
inlineprotected

Returns the class of the current path of the ith base node.

Definition at line 1315 of file constraint_solveri.h.

◆ Reset()

void operations_research::PathOperator::Reset ( )
overridevirtual

◆ ResetPosition()

void operations_research::PathOperator::ResetPosition ( )
inlineprotected

Reset the position of the operator to its position when Start() was last called; this can be used to let an operator iterate more than once over the paths.

Definition at line 1392 of file constraint_solveri.h.

◆ RestartAtPathStartOnSynchronize()

virtual bool operations_research::PathOperator::RestartAtPathStartOnSynchronize ( )
inlineprotectedvirtual

When the operator is being synchronized with a new solution (when Start() is called), returns true to restart the exploration of the neighborhood from the start of the last paths explored; returns false to restart the exploration at the last nodes visited.

This is used to avoid restarting on base nodes which have changed paths, leading to potentially skipping neighbors.

Reimplemented in operations_research::PairNodeSwapActiveOperator< swap_first >, and operations_research::MakePairActiveOperator.

Definition at line 1328 of file constraint_solveri.h.

◆ ReverseChain()

bool operations_research::PathOperator::ReverseChain ( int64  before_chain,
int64  after_chain,
int64 *  chain_last 
)
protected

Reverses the chain starting after before_chain and ending before after_chain.

◆ RevertChanges()

void operations_research::VarLocalSearchOperator< IntVar , int64 , IntVarLocalSearchHandler >::RevertChanges ( bool  incremental)
inlineinherited

Definition at line 895 of file constraint_solveri.h.

◆ Self()

virtual const LocalSearchOperator* operations_research::LocalSearchOperator::Self ( ) const
inlinevirtualinherited

Definition at line 813 of file constraint_solveri.h.

◆ SetNext()

void operations_research::PathOperator::SetNext ( int64  from,
int64  to,
int64  path 
)
inlineprotected

Sets the to to be the node after from.

Definition at line 1370 of file constraint_solveri.h.

◆ SetNextBaseToIncrement()

virtual void operations_research::PathOperator::SetNextBaseToIncrement ( int64  base_index)
inlineprotectedvirtual

Set the next base to increment on next iteration.

All base > base_index will be reset to their start value.

Definition at line 1345 of file constraint_solveri.h.

◆ SetValue()

void operations_research::VarLocalSearchOperator< IntVar , int64 , IntVarLocalSearchHandler >::SetValue ( int64  index,
const int64 &  value 
)
inlineinherited

Definition at line 858 of file constraint_solveri.h.

◆ Size()

int operations_research::VarLocalSearchOperator< IntVar , int64 , IntVarLocalSearchHandler >::Size ( ) const
inlineinherited

Definition at line 847 of file constraint_solveri.h.

◆ SkipUnchanged()

bool operations_research::PathOperator::SkipUnchanged ( int  index) const
overridevirtual

◆ Start()

void operations_research::VarLocalSearchOperator< IntVar , int64 , IntVarLocalSearchHandler >::Start ( const Assignment assignment)
inlineoverridevirtualinherited

This method should not be overridden.

Override OnStart() instead which is called before exiting this method.

Implements operations_research::LocalSearchOperator.

Definition at line 833 of file constraint_solveri.h.

◆ StartNode()

int64 operations_research::PathOperator::StartNode ( int  i) const
inlineprotected

Returns the index of the variable corresponding to the current path of the ith base node.

Definition at line 1311 of file constraint_solveri.h.

◆ Value()

const int64 & operations_research::VarLocalSearchOperator< IntVar , int64 , IntVarLocalSearchHandler >::Value ( int64  index) const
inlineinherited

Returns the value in the current assignment of the variable of given index.

Definition at line 850 of file constraint_solveri.h.

◆ Var()

IntVar * operations_research::VarLocalSearchOperator< IntVar , int64 , IntVarLocalSearchHandler >::Var ( int64  index) const
inlineinherited

Returns the variable of given index.

Definition at line 855 of file constraint_solveri.h.

Member Data Documentation

◆ activated_

Bitset64 operations_research::VarLocalSearchOperator< IntVar , int64 , IntVarLocalSearchHandler >::activated_
protectedinherited

Definition at line 942 of file constraint_solveri.h.

◆ assignment_indices_

std::vector<int> operations_research::VarLocalSearchOperator< IntVar , int64 , IntVarLocalSearchHandler >::assignment_indices_
mutableprotectedinherited

Definition at line 941 of file constraint_solveri.h.

◆ changes_

SparseBitset operations_research::VarLocalSearchOperator< IntVar , int64 , IntVarLocalSearchHandler >::changes_
protectedinherited

Definition at line 944 of file constraint_solveri.h.

◆ cleared_

bool operations_research::VarLocalSearchOperator< IntVar , int64 , IntVarLocalSearchHandler >::cleared_
protectedinherited

Definition at line 946 of file constraint_solveri.h.

◆ delta_changes_

SparseBitset operations_research::VarLocalSearchOperator< IntVar , int64 , IntVarLocalSearchHandler >::delta_changes_
protectedinherited

Definition at line 945 of file constraint_solveri.h.

◆ ignore_path_vars_

const bool operations_research::PathOperator::ignore_path_vars_
protected

Definition at line 1395 of file constraint_solveri.h.

◆ next_base_to_increment_

int operations_research::PathOperator::next_base_to_increment_
protected

Definition at line 1396 of file constraint_solveri.h.

◆ num_paths_

int operations_research::PathOperator::num_paths_ = 0
protected

Definition at line 1397 of file constraint_solveri.h.

◆ number_of_nexts_

const int operations_research::PathOperator::number_of_nexts_
protected

Definition at line 1394 of file constraint_solveri.h.

◆ old_values_

std::vector<int64 > operations_research::VarLocalSearchOperator< IntVar , int64 , IntVarLocalSearchHandler >::old_values_
protectedinherited

Definition at line 939 of file constraint_solveri.h.

◆ prev_values_

std::vector<int64 > operations_research::VarLocalSearchOperator< IntVar , int64 , IntVarLocalSearchHandler >::prev_values_
protectedinherited

Definition at line 940 of file constraint_solveri.h.

◆ start_to_path_

std::vector<int64> operations_research::PathOperator::start_to_path_
protected

Definition at line 1398 of file constraint_solveri.h.

◆ values_

std::vector<int64 > operations_research::VarLocalSearchOperator< IntVar , int64 , IntVarLocalSearchHandler >::values_
protectedinherited

Definition at line 938 of file constraint_solveri.h.

◆ var_handler_

Definition at line 947 of file constraint_solveri.h.

◆ vars_

std::vector<IntVar *> operations_research::VarLocalSearchOperator< IntVar , int64 , IntVarLocalSearchHandler >::vars_
protectedinherited

Definition at line 937 of file constraint_solveri.h.

◆ was_activated_

Bitset64 operations_research::VarLocalSearchOperator< IntVar , int64 , IntVarLocalSearchHandler >::was_activated_
protectedinherited

Definition at line 943 of file constraint_solveri.h.


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