Google OR-Tools v9.11
a fast and portable software suite for combinatorial optimization
Loading...
Searching...
No Matches
operations_research::BaseLns Class Referenceabstract

#include <constraint_solveri.h>

Inheritance diagram for operations_research::BaseLns:
operations_research::IntVarLocalSearchOperator operations_research::LocalSearchOperator operations_research::BaseObject

Public Member Functions

 BaseLns (const std::vector< IntVar * > &vars)
 --— Base Large Neighborhood Search operator --—
 
 ~BaseLns () override
 
virtual void InitFragments ()
 
virtual bool NextFragment ()=0
 
void AppendToFragment (int index)
 
int FragmentSize () const
 
bool HasFragments () const override
 
- Public Member Functions inherited from operations_research::IntVarLocalSearchOperator
 IntVarLocalSearchOperator (const std::vector< IntVar * > &vars, bool keep_inverse_values=false)
 
 ~IntVarLocalSearchOperator () override
 
bool HoldsDelta () const override
 
void Start (const Assignment *assignment) override
 
virtual bool IsIncremental () const
 
int Size () const
 
int64_t Value (int64_t index) const
 
IntVarVar (int64_t index) const
 Returns the variable of given index.
 
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
 --— Base operator class for operators manipulating IntVars --—
 
- Public Member Functions inherited from operations_research::LocalSearchOperator
 LocalSearchOperator ()
 
 ~LocalSearchOperator () override
 
virtual void Reset ()
 
virtual const LocalSearchOperatorSelf () const
 
- Public Member Functions inherited from operations_research::BaseObject
 BaseObject ()
 
 BaseObject (const BaseObject &)=delete
 This type is neither copyable nor movable.
 
BaseObjectoperator= (const BaseObject &)=delete
 
virtual ~BaseObject ()
 
virtual std::string DebugString () const
 

Protected Member Functions

bool MakeOneNeighbor () override
 This method should not be overridden. Override NextFragment() instead.
 
- Protected Member Functions inherited from operations_research::IntVarLocalSearchOperator
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
 

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

Constructor & Destructor Documentation

◆ BaseLns()

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

--— Base Large Neighborhood Search operator --—

Definition at line 108 of file local_search.cc.

◆ ~BaseLns()

operations_research::BaseLns::~BaseLns ( )
override

Definition at line 111 of file local_search.cc.

Member Function Documentation

◆ AppendToFragment()

void operations_research::BaseLns::AppendToFragment ( int index)

Definition at line 128 of file local_search.cc.

◆ FragmentSize()

int operations_research::BaseLns::FragmentSize ( ) const

Definition at line 134 of file local_search.cc.

◆ HasFragments()

bool operations_research::BaseLns::HasFragments ( ) const
inlineoverridevirtual

Reimplemented from operations_research::LocalSearchOperator.

Definition at line 1273 of file constraint_solveri.h.

◆ InitFragments()

void operations_research::BaseLns::InitFragments ( )
virtual

Definition at line 126 of file local_search.cc.

◆ MakeOneNeighbor()

bool operations_research::BaseLns::MakeOneNeighbor ( )
overrideprotectedvirtual

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

Reimplemented from operations_research::IntVarLocalSearchOperator.

Definition at line 113 of file local_search.cc.

◆ NextFragment()

virtual bool operations_research::BaseLns::NextFragment ( )
pure virtual

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