OR-Tools  9.6
BaseLnsabstract

Detailed Description

This is the base class for building an Lns operator.

An Lns fragment is a collection of variables which will be relaxed. Fragments are built with NextFragment(), which returns false if there are no more fragments to build. Optionally one can override InitFragments, which is called from LocalSearchOperator::Start to initialize fragment data.

Here's a sample relaxing one variable at a time:

class OneVarLns : public BaseLns { public: OneVarLns(const std::vector<IntVar*>& vars) : BaseLns(vars), index_(0) {} virtual ~OneVarLns() {} virtual void InitFragments() { index_ = 0; } virtual bool NextFragment() { const int size = Size(); if (index_ < size) { AppendToFragment(index_); ++index_; return true; } else { return false; } }

private: int index_; };

Definition at line 1247 of file constraint_solveri.h.

Public Member Functions

 BaseLns (const std::vector< IntVar * > &vars)
 
 ~BaseLns () override
 
virtual void InitFragments ()
 
virtual bool NextFragment ()=0
 
void AppendToFragment (int index)
 
int FragmentSize () const
 
bool HasFragments () const override
 
bool HoldsDelta () const override
 
void Start (const Assignment *assignment) override
 This method should not be overridden. More...
 
virtual bool IsIncremental () const
 
int Size () 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...
 
virtual bool SkipUnchanged (int index) const
 
int64_t OldValue (int64_t index) const
 
int64_t PrevValue (int64_t index) const
 
void SetValue (int64_t index, 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 change_was_incremental)
 
void AddVars (const std::vector< IntVar * > &vars)
 
bool MakeNextNeighbor (Assignment *delta, Assignment *deltadelta) override
 OnStart() should really be protected, but then SWIG doesn't see it. More...
 
virtual void Reset ()
 
virtual const LocalSearchOperatorSelf () const
 
virtual std::string DebugString () const
 

Protected Member Functions

bool MakeOneNeighbor () override
 This method should not be overridden. Override NextFragment() instead. More...
 
int64_t InverseValue (int64_t index) const
 
int64_t OldInverseValue (int64_t index) const
 
void AddToAssignment (IntVar *var, int64_t value, bool active, std::vector< int > *assignment_indices, int64_t index, Assignment *assignment) const
 

Constructor & Destructor Documentation

◆ BaseLns()

BaseLns ( const std::vector< IntVar * > &  vars)
explicit

Definition at line 104 of file local_search.cc.

◆ ~BaseLns()

~BaseLns ( )
override

Definition at line 107 of file local_search.cc.

Member Function Documentation

◆ Activate()

void Activate ( int64_t  index)
inlineinherited

Definition at line 1111 of file constraint_solveri.h.

◆ Activated()

bool Activated ( int64_t  index) const
inlineinherited

Definition at line 1108 of file constraint_solveri.h.

◆ AddToAssignment()

void AddToAssignment ( IntVar var,
int64_t  value,
bool  active,
std::vector< int > *  assignment_indices,
int64_t  index,
Assignment assignment 
) const
inlineprotectedinherited

Definition at line 1188 of file constraint_solveri.h.

◆ AddVars()

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

Definition at line 1149 of file constraint_solveri.h.

◆ AppendToFragment()

void AppendToFragment ( int  index)

Definition at line 124 of file local_search.cc.

◆ ApplyChanges()

bool ApplyChanges ( Assignment delta,
Assignment deltadelta 
) const
inlineinherited

Definition at line 1114 of file constraint_solveri.h.

◆ Deactivate()

void Deactivate ( int64_t  index)
inlineinherited

Definition at line 1112 of file constraint_solveri.h.

◆ DebugString()

virtual std::string DebugString ( ) const
inlinevirtualinherited

Reimplemented in SymmetryManager, IntVarFilteredDecisionBuilder, ExchangeSubtrip, RelocateSubtrip, PairNodeSwapActiveOperator< swap_first >, RelocateExpensiveChain, FilteredHeuristicCloseNodesLNSOperator, FilteredHeuristicExpensiveChainLNSOperator, RelocatePathAndHeuristicInsertUnperformedOperator, FilteredHeuristicPathLNSOperator, IndexPairSwapActiveOperator, SwapIndexPairOperator, PairExchangeRelocateOperator, PairExchangeOperator, LightPairRelocateOperator, GroupPairAndRelocateOperator, PairRelocateOperator, MakePairInactiveOperator, MakePairActiveOperator, SwapActiveToShortestPathOperator, MakeRelocateNeighborsOperator, GlobalVehicleBreaksConstraint, Dimension, LocalSearchPhaseParameters, FindOneNeighbor, LocalSearchProfiler, NeighborhoodLimit, PathLns, LinKernighan, TSPLns, TSPOpt, ExtendedSwapActiveOperator, SwapActiveOperator, MakeChainInactiveOperator, RelocateAndMakeInactiveOperator, MakeInactiveOperator, MakeActiveAndRelocate, RelocateAndMakeActiveOperator, MakeActiveOperator, Cross, Exchange, Relocate, TwoOpt, PiecewiseLinearExpr, IfThenElseCt, DemonProfiler, ArrayWithOffset< T >, SearchLog, BooleanVar, LocalSearchMonitor, PropagationMonitor, LocalSearchFilterManager, LightIntIntFunctionElementCt< F >, LightIntFunctionElementCt< F >, DelayedCallMethod2< T, P, Q >, DelayedCallMethod1< T, P >, DelayedCallMethod0< T >, CallMethod3< T, P, Q, R >, CallMethod2< T, P, Q >, CallMethod1< T, P >, CallMethod0< T >, Pack, Assignment, SequenceVar, RegularLimit, SearchLimit, OptimizeVar, SolutionCollector, IntVarIterator, Constraint, Demon, ProfiledDecisionBuilder, DecisionBuilder, Decision, PropagationBaseObject, LocalSearchMonitorPrimary, and Trace.

Definition at line 3251 of file constraint_solver.h.

◆ FragmentSize()

int FragmentSize ( ) const

Definition at line 130 of file local_search.cc.

◆ HasFragments()

bool HasFragments ( ) const
inlineoverridevirtual

Reimplemented from LocalSearchOperator.

Definition at line 1255 of file constraint_solveri.h.

◆ HoldsDelta()

bool HoldsDelta ( ) const
inlineoverridevirtualinherited

Reimplemented from LocalSearchOperator.

Definition at line 1066 of file constraint_solveri.h.

◆ InitFragments()

void InitFragments ( )
virtual

Definition at line 122 of file local_search.cc.

◆ InverseValue()

int64_t InverseValue ( int64_t  index) const
inlineprotectedinherited

Definition at line 1181 of file constraint_solveri.h.

◆ IsIncremental()

virtual bool IsIncremental ( ) const
inlinevirtualinherited

Reimplemented in TwoOpt.

Definition at line 1089 of file constraint_solveri.h.

◆ MakeNextNeighbor()

bool MakeNextNeighbor ( Assignment delta,
Assignment deltadelta 
)
overridevirtualinherited

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). 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 PairNodeSwapActiveOperator< swap_first >, IndexPairSwapActiveOperator, and SwapIndexPairOperator.

Definition at line 79 of file local_search.cc.

◆ MakeOneNeighbor()

bool MakeOneNeighbor ( )
overrideprotectedvirtual

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

Reimplemented from IntVarLocalSearchOperator.

Definition at line 109 of file local_search.cc.

◆ NextFragment()

virtual bool NextFragment ( )
pure virtual

◆ OldInverseValue()

int64_t OldInverseValue ( int64_t  index) const
inlineprotectedinherited

Definition at line 1184 of file constraint_solveri.h.

◆ OldValue()

int64_t OldValue ( int64_t  index) const
inlineinherited

Definition at line 1101 of file constraint_solveri.h.

◆ PrevValue()

int64_t PrevValue ( int64_t  index) const
inlineinherited

Definition at line 1102 of file constraint_solveri.h.

◆ Reset()

virtual void Reset ( )
inlinevirtualinherited

Reimplemented in PathOperator.

Definition at line 918 of file constraint_solveri.h.

◆ RevertChanges()

void RevertChanges ( bool  change_was_incremental)
inlineinherited

Definition at line 1138 of file constraint_solveri.h.

◆ Self()

virtual const LocalSearchOperator* Self ( ) const
inlinevirtualinherited

Definition at line 920 of file constraint_solveri.h.

◆ SetValue()

void SetValue ( int64_t  index,
int64_t  value 
)
inlineinherited

Definition at line 1105 of file constraint_solveri.h.

◆ Size()

int Size ( ) const
inlineinherited

Definition at line 1091 of file constraint_solveri.h.

◆ SkipUnchanged()

virtual bool SkipUnchanged ( int  index) const
inlinevirtualinherited

Reimplemented in PathOperator.

Definition at line 1100 of file constraint_solveri.h.

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

◆ Value()

int64_t Value ( int64_t  index) const
inlineinherited

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

Definition at line 1094 of file constraint_solveri.h.

◆ Var()

IntVar* Var ( int64_t  index) const
inlineinherited

Returns the variable of given index.

Definition at line 1099 of file constraint_solveri.h.


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