OR-Tools  9.3
Cross

Detailed Description

Definition at line 1042 of file local_search.cc.

Public Member Functions

 Cross (const std::vector< IntVar * > &vars, const std::vector< IntVar * > &secondary_vars, std::function< int(int64_t)> start_empty_path_class)
 
 ~Cross () override
 
bool MakeNeighbor () override
 
std::string DebugString () const override
 
void Reset () override
 
bool SkipUnchanged (int index) const override
 
int64_t Next (int64_t node) const
 Returns the node after node in the current delta. More...
 
int64_t Prev (int64_t node) const
 Returns the node before node in the current delta. More...
 
int64_t Path (int64_t node) const
 Returns the index of the path to which node belongs in the current delta. 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_t & Value (int64_t index) const
 Returns the value in the current assignment of the variable of given index. More...
 
IntVarVar (int64_t index) const
 Returns the variable of given index. More...
 
const int64_t & OldValue (int64_t index) const
 
void SetValue (int64_t index, const int64_t &value)
 
bool Activated (int64_t index) const
 
void Activate (int64_t index)
 
void Deactivate (int64_t 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
 

Protected Member Functions

bool MakeOneNeighbor () override
 This method should not be overridden. Override MakeNeighbor() instead. More...
 
virtual void OnNodeInitialization ()
 Called by OnStart() after initializing node information. More...
 
int64_t BaseNode (int i) const
 Returns the ith base node of the operator. More...
 
int BaseAlternative (int i) const
 Returns the alternative for the ith base node. More...
 
int64_t BaseAlternativeNode (int i) const
 Returns the alternative node for the ith base node. More...
 
int BaseSiblingAlternative (int i) const
 Returns the alternative for the sibling of the ith base node. More...
 
int64_t BaseSiblingAlternativeNode (int i) const
 Returns the alternative node for the sibling of the ith base node. More...
 
int64_t StartNode (int i) const
 Returns the start node of the ith base node. More...
 
const std::vector< int64_t > & path_starts () const
 Returns the vector of path start nodes. More...
 
int PathClass (int i) const
 Returns the class of the 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_t 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_t 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_t base_index)
 Set the next base to increment on next iteration. More...
 
virtual bool ConsiderAlternatives (int64_t base_index) const
 Indicates if alternatives should be considered when iterating over base nodes. More...
 
int64_t OldNext (int64_t node) const
 
int64_t OldPrev (int64_t node) const
 
int64_t OldPath (int64_t node) const
 
bool MoveChain (int64_t before_chain, int64_t chain_end, int64_t 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_t before_chain, int64_t after_chain, int64_t *chain_last)
 Reverses the chain starting after before_chain and ending before after_chain. More...
 
bool MakeActive (int64_t node, int64_t destination)
 Insert the inactive node after destination. More...
 
bool MakeChainInactive (int64_t before_chain, int64_t chain_end)
 Makes the nodes on the chain starting after before_chain and ending at chain_end inactive. More...
 
bool SwapActiveAndInactive (int64_t active, int64_t inactive)
 Replaces active by inactive in the current path, making active inactive. More...
 
void SetNext (int64_t from, int64_t to, int64_t path)
 Sets 'to' to be the node after 'from' on the given path. More...
 
bool IsPathEnd (int64_t node) const
 Returns true if node is the last node on the path; defined by the fact that node is outside the range of the variable array. More...
 
bool IsPathStart (int64_t node) const
 Returns true if node is the first node on the path. More...
 
bool IsInactive (int64_t node) const
 Returns true if node is inactive. More...
 
virtual bool InitPosition () const
 Returns true if the 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...
 
int AddAlternativeSet (const std::vector< int64_t > &alternative_set)
 Handling node alternatives. More...
 
void AddPairAlternativeSets (const std::vector< std::pair< std::vector< int64_t >, std::vector< int64_t > > > &pair_alternative_sets)
 Adds all sets of node alternatives of a vector of alternative pairs. More...
 
int64_t GetActiveInAlternativeSet (int alternative_index) const
 Returns the active node in the given alternative set. More...
 
int64_t GetActiveAlternativeNode (int node) const
 Returns the active node in the alternative set of the given node. More...
 
int GetSiblingAlternativeIndex (int node) const
 Returns the index of the alternative set of the sibling of node. More...
 
int64_t GetActiveAlternativeSibling (int node) const
 Returns the active node in the alternative set of the sibling of the given node. More...
 
bool CheckChainValidity (int64_t before_chain, int64_t chain_end, int64_t exclude) const
 Returns true if the chain is a valid path without cycles from before_chain to chain_end and does not contain exclude. More...
 
bool IsInverseValue (int64_t index) const
 
int64_t InverseValue (int64_t index) const
 
int64_t OldInverseValue (int64_t index) const
 
void SetInverseValue (int64_t index, int64_t value)
 
void SetOldInverseValue (int64_t index, int64_t value)
 
void MarkChange (int64_t 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_t > start_to_path_
 
std::vector< IntVar * > vars_
 
std::vector< int64_t > values_
 
std::vector< int64_t > old_values_
 
std::vector< int64_t > 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

◆ Cross()

Cross ( const std::vector< IntVar * > &  vars,
const std::vector< IntVar * > &  secondary_vars,
std::function< int(int64_t)>  start_empty_path_class 
)
inline

Definition at line 1044 of file local_search.cc.

◆ ~Cross()

~Cross ( )
inlineoverride

Definition at line 1049 of file local_search.cc.

Member Function Documentation

◆ Activate()

void Activate ( int64_t  index)
inlineinherited

Definition at line 850 of file constraint_solveri.h.

◆ Activated()

bool Activated ( int64_t  index) const
inlineinherited

Definition at line 849 of file constraint_solveri.h.

◆ AddAlternativeSet()

int AddAlternativeSet ( const std::vector< int64_t > &  alternative_set)
inlineprotectedinherited

Handling node alternatives.

Adds a set of node alternatives to the neighborhood. No node can be in two altrnatives.

Definition at line 1519 of file constraint_solveri.h.

◆ AddPairAlternativeSets()

void AddPairAlternativeSets ( const std::vector< std::pair< std::vector< int64_t >, std::vector< int64_t > > > &  pair_alternative_sets)
inlineprotectedinherited

Adds all sets of node alternatives of a vector of alternative pairs.

No node can be in two altrnatives.

Definition at line 1532 of file constraint_solveri.h.

◆ AddVars()

void AddVars ( const std::vector< IntVar * > &  vars)
inlineinherited

Definition at line 895 of file constraint_solveri.h.

◆ ApplyChanges()

bool ApplyChanges ( Assignment delta,
Assignment deltadelta 
) const
inlineinherited

Definition at line 858 of file constraint_solveri.h.

◆ BaseAlternative()

int BaseAlternative ( int  i) const
inlineprotectedinherited

Returns the alternative for the ith base node.

Definition at line 1388 of file constraint_solveri.h.

◆ BaseAlternativeNode()

int64_t BaseAlternativeNode ( int  i) const
inlineprotectedinherited

Returns the alternative node for the ith base node.

Definition at line 1390 of file constraint_solveri.h.

◆ BaseNode()

int64_t BaseNode ( int  i) const
inlineprotectedinherited

Returns the ith base node of the operator.

Definition at line 1386 of file constraint_solveri.h.

◆ BaseSiblingAlternative()

int BaseSiblingAlternative ( int  i) const
inlineprotectedinherited

Returns the alternative for the sibling of the ith base node.

Definition at line 1398 of file constraint_solveri.h.

◆ BaseSiblingAlternativeNode()

int64_t BaseSiblingAlternativeNode ( int  i) const
inlineprotectedinherited

Returns the alternative node for the sibling of the ith base node.

Definition at line 1402 of file constraint_solveri.h.

◆ CheckChainValidity()

bool CheckChainValidity ( int64_t  before_chain,
int64_t  chain_end,
int64_t  exclude 
) const
protectedinherited

Returns true if the chain is a valid path without cycles from before_chain to chain_end and does not contain exclude.

Definition at line 839 of file local_search.cc.

◆ ConsiderAlternatives()

virtual bool ConsiderAlternatives ( int64_t  base_index) const
inlineprotectedvirtualinherited

Indicates if alternatives should be considered when iterating over base nodes.

Reimplemented in PairRelocateOperator.

Definition at line 1452 of file constraint_solveri.h.

◆ Deactivate()

void Deactivate ( int64_t  index)
inlineinherited

Definition at line 854 of file constraint_solveri.h.

◆ DebugString()

std::string DebugString ( ) const
inlineoverridevirtual

Reimplemented from BaseObject.

Definition at line 1052 of file local_search.cc.

◆ GetActiveAlternativeNode()

int64_t GetActiveAlternativeNode ( int  node) const
inlineprotectedinherited

Returns the active node in the alternative set of the given node.

Definition at line 1549 of file constraint_solveri.h.

◆ GetActiveAlternativeSibling()

int64_t GetActiveAlternativeSibling ( int  node) const
inlineprotectedinherited

Returns the active node in the alternative set of the sibling of the given node.

Definition at line 1560 of file constraint_solveri.h.

◆ GetActiveInAlternativeSet()

int64_t GetActiveInAlternativeSet ( int  alternative_index) const
inlineprotectedinherited

Returns the active node in the given alternative set.

Definition at line 1543 of file constraint_solveri.h.

◆ GetBaseNodeRestartPosition()

virtual int64_t GetBaseNodeRestartPosition ( int  base_index)
inlineprotectedvirtualinherited

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 TwoOpt, MakeChainInactiveOperator, MakePairActiveOperator, PairRelocateOperator, PairExchangeRelocateOperator, and PairNodeSwapActiveOperator< swap_first >.

Definition at line 1442 of file constraint_solveri.h.

◆ GetSiblingAlternativeIndex()

int GetSiblingAlternativeIndex ( int  node) const
inlineprotectedinherited

Returns the index of the alternative set of the sibling of node.

Definition at line 1553 of file constraint_solveri.h.

◆ HasFragments()

virtual bool HasFragments ( ) const
inlinevirtualinherited

Reimplemented in BaseLns, and PathLns.

Definition at line 802 of file constraint_solveri.h.

◆ HoldsDelta()

bool HoldsDelta ( ) const
inlineoverridevirtualinherited

Reimplemented from LocalSearchOperator.

Definition at line 817 of file constraint_solveri.h.

◆ InitPosition()

virtual bool InitPosition ( ) const
inlineprotectedvirtualinherited

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

Definition at line 1510 of file constraint_solveri.h.

◆ InverseValue()

int64_t InverseValue ( int64_t  index) const
inlineprotectedinherited

Definition at line 1066 of file constraint_solveri.h.

◆ IsInactive()

bool IsInactive ( int64_t  node) const
inlineprotectedinherited

Returns true if node is inactive.

Definition at line 1504 of file constraint_solveri.h.

◆ IsIncremental()

virtual bool IsIncremental ( ) const
inlinevirtualinherited

Reimplemented in TwoOpt.

Definition at line 833 of file constraint_solveri.h.

◆ IsInverseValue()

bool IsInverseValue ( int64_t  index) const
inlineprotectedinherited

Definition at line 1061 of file constraint_solveri.h.

◆ IsPathEnd()

bool IsPathEnd ( int64_t  node) const
inlineprotectedinherited

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

Definition at line 1498 of file constraint_solveri.h.

◆ IsPathStart()

bool IsPathStart ( int64_t  node) const
inlineprotectedinherited

Returns true if node is the first node on the path.

Definition at line 1501 of file constraint_solveri.h.

◆ MakeActive()

bool MakeActive ( int64_t  node,
int64_t  destination 
)
protectedinherited

Insert the inactive node after destination.

Definition at line 458 of file local_search.cc.

◆ MakeChainInactive()

bool MakeChainInactive ( int64_t  before_chain,
int64_t  chain_end 
)
protectedinherited

Makes the nodes on the chain starting after before_chain and ending at chain_end inactive.

Definition at line 468 of file local_search.cc.

◆ MakeNeighbor()

bool MakeNeighbor ( )
overridevirtual

Implements PathOperator.

Definition at line 1055 of file local_search.cc.

◆ MakeNextNeighbor()

bool 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 LocalSearchOperator.

Reimplemented in SwapIndexPairOperator, IndexPairSwapActiveOperator, and PairNodeSwapActiveOperator< swap_first >.

Definition at line 76 of file local_search.cc.

◆ MakeOneNeighbor()

bool MakeOneNeighbor ( )
overrideprotectedvirtualinherited

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

Reimplemented from IntVarLocalSearchOperator.

Reimplemented in BaseInactiveNodeToPathOperator, TSPLns, MakePairActiveOperator, and RelocateExpensiveChain.

Definition at line 388 of file local_search.cc.

◆ MarkChange()

void MarkChange ( int64_t  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 919 of file constraint_solveri.h.

◆ MoveChain()

bool MoveChain ( int64_t  before_chain,
int64_t  chain_end,
int64_t  destination 
)
protectedinherited

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

Definition at line 412 of file local_search.cc.

◆ Next()

int64_t Next ( int64_t  node) const
inlineinherited

Returns the node after node in the current delta.

Definition at line 1356 of file constraint_solveri.h.

◆ number_of_nexts()

int number_of_nexts ( ) const
inlineinherited

Number of next variables.

Definition at line 1375 of file constraint_solveri.h.

◆ OldInverseValue()

int64_t OldInverseValue ( int64_t  index) const
inlineprotectedinherited

Definition at line 1068 of file constraint_solveri.h.

◆ OldNext()

int64_t OldNext ( int64_t  node) const
inlineprotectedinherited

Definition at line 1454 of file constraint_solveri.h.

◆ OldPath()

int64_t OldPath ( int64_t  node) const
inlineprotectedinherited

Definition at line 1464 of file constraint_solveri.h.

◆ OldPrev()

int64_t OldPrev ( int64_t  node) const
inlineprotectedinherited

Definition at line 1459 of file constraint_solveri.h.

◆ OldValue()

const int64_t & OldValue ( int64_t  index) const
inlineinherited

Definition at line 844 of file constraint_solveri.h.

◆ OnNodeInitialization()

virtual void OnNodeInitialization ( )
inlineprotectedvirtualinherited

Called by OnStart() after initializing node information.

Should be overridden instead of OnStart() to avoid calling PathOperator::OnStart explicitly.

Definition at line 1383 of file constraint_solveri.h.

◆ OnSamePathAsPreviousBase()

virtual bool OnSamePathAsPreviousBase ( int64_t  base_index)
inlineprotectedvirtualinherited

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 TwoOpt, Relocate, MakeChainInactiveOperator, MakePairActiveOperator, PairRelocateOperator, PairExchangeRelocateOperator, and PairNodeSwapActiveOperator< swap_first >.

Definition at line 1436 of file constraint_solveri.h.

◆ Path()

int64_t Path ( int64_t  node) const
inlineinherited

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

Only returns a valid value if path variables are taken into account.

Definition at line 1370 of file constraint_solveri.h.

◆ path_starts()

const std::vector< int64_t > & path_starts ( ) const
inlineprotectedinherited

Returns the vector of path start nodes.

Definition at line 1414 of file constraint_solveri.h.

◆ PathClass()

int PathClass ( int  i) const
inlineprotectedinherited

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

Definition at line 1416 of file constraint_solveri.h.

◆ Prev()

int64_t Prev ( int64_t  node) const
inlineinherited

Returns the node before node in the current delta.

Definition at line 1362 of file constraint_solveri.h.

◆ Reset()

void Reset ( )
overridevirtualinherited

Reimplemented from LocalSearchOperator.

Definition at line 379 of file local_search.cc.

◆ ResetPosition()

void ResetPosition ( )
inlineprotectedinherited

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 1514 of file constraint_solveri.h.

◆ RestartAtPathStartOnSynchronize()

virtual bool RestartAtPathStartOnSynchronize ( )
inlineprotectedvirtualinherited

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 MakePairActiveOperator, and PairNodeSwapActiveOperator< swap_first >.

Definition at line 1429 of file constraint_solveri.h.

◆ ReverseChain()

bool ReverseChain ( int64_t  before_chain,
int64_t  after_chain,
int64_t *  chain_last 
)
protectedinherited

Reverses the chain starting after before_chain and ending before after_chain.

Definition at line 435 of file local_search.cc.

◆ RevertChanges()

void RevertChanges ( bool  incremental)
inlineinherited

Definition at line 882 of file constraint_solveri.h.

◆ Self()

virtual const LocalSearchOperator * Self ( ) const
inlinevirtualinherited

Definition at line 800 of file constraint_solveri.h.

◆ SetInverseValue()

void SetInverseValue ( int64_t  index,
int64_t  value 
)
inlineprotectedinherited

Definition at line 1072 of file constraint_solveri.h.

◆ SetNext()

void SetNext ( int64_t  from,
int64_t  to,
int64_t  path 
)
inlineprotectedinherited

Sets 'to' to be the node after 'from' on the given path.

Definition at line 1486 of file constraint_solveri.h.

◆ SetNextBaseToIncrement()

virtual void SetNextBaseToIncrement ( int64_t  base_index)
inlineprotectedvirtualinherited

Set the next base to increment on next iteration.

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

Definition at line 1447 of file constraint_solveri.h.

◆ SetOldInverseValue()

void SetOldInverseValue ( int64_t  index,
int64_t  value 
)
inlineprotectedinherited

Definition at line 1076 of file constraint_solveri.h.

◆ SetValue()

void SetValue ( int64_t  index,
const int64_t &  value 
)
inlineinherited

Definition at line 845 of file constraint_solveri.h.

◆ Size()

int Size ( ) const
inlineinherited

Definition at line 834 of file constraint_solveri.h.

◆ SkipUnchanged()

bool SkipUnchanged ( int  index) const
overridevirtualinherited

◆ Start()

void Start ( const Assignment assignment)
inlineoverridevirtualinherited

This method should not be overridden.

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

Implements LocalSearchOperator.

Definition at line 820 of file constraint_solveri.h.

◆ StartNode()

int64_t StartNode ( int  i) const
inlineprotectedinherited

Returns the start node of the ith base node.

Definition at line 1412 of file constraint_solveri.h.

◆ SwapActiveAndInactive()

bool SwapActiveAndInactive ( int64_t  active,
int64_t  inactive 
)
protectedinherited

Replaces active by inactive in the current path, making active inactive.

Definition at line 485 of file local_search.cc.

◆ Value()

const int64_t & Value ( int64_t  index) const
inlineinherited

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

Definition at line 837 of file constraint_solveri.h.

◆ Var()

IntVar * Var ( int64_t  index) const
inlineinherited

Returns the variable of given index.

Definition at line 842 of file constraint_solveri.h.

Member Data Documentation

◆ activated_

Bitset64 activated_
protectedinherited

Definition at line 929 of file constraint_solveri.h.

◆ assignment_indices_

std::vector<int> assignment_indices_
mutableprotectedinherited

Definition at line 928 of file constraint_solveri.h.

◆ changes_

SparseBitset changes_
protectedinherited

Definition at line 931 of file constraint_solveri.h.

◆ cleared_

bool cleared_
protectedinherited

Definition at line 933 of file constraint_solveri.h.

◆ delta_changes_

SparseBitset delta_changes_
protectedinherited

Definition at line 932 of file constraint_solveri.h.

◆ ignore_path_vars_

const bool ignore_path_vars_
protectedinherited

Definition at line 1573 of file constraint_solveri.h.

◆ next_base_to_increment_

int next_base_to_increment_
protectedinherited

Definition at line 1574 of file constraint_solveri.h.

◆ num_paths_

int num_paths_ = 0
protectedinherited

Definition at line 1575 of file constraint_solveri.h.

◆ number_of_nexts_

const int number_of_nexts_
protectedinherited

Definition at line 1572 of file constraint_solveri.h.

◆ old_values_

std::vector<int64_t > old_values_
protectedinherited

Definition at line 926 of file constraint_solveri.h.

◆ prev_values_

std::vector<int64_t > prev_values_
protectedinherited

Definition at line 927 of file constraint_solveri.h.

◆ start_to_path_

std::vector<int64_t> start_to_path_
protectedinherited

Definition at line 1576 of file constraint_solveri.h.

◆ values_

std::vector<int64_t > values_
protectedinherited

Definition at line 925 of file constraint_solveri.h.

◆ var_handler_

IntVarLocalSearchHandler var_handler_
protectedinherited

Definition at line 934 of file constraint_solveri.h.

◆ vars_

std::vector<IntVar *> vars_
protectedinherited

Definition at line 924 of file constraint_solveri.h.

◆ was_activated_

Bitset64 was_activated_
protectedinherited

Definition at line 930 of file constraint_solveri.h.


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