Class BaseLns
java.lang.Object
com.google.ortools.constraintsolver.BaseObject
com.google.ortools.constraintsolver.LocalSearchOperator
com.google.ortools.constraintsolver.IntVarLocalSearchOperator
com.google.ortools.constraintsolver.BaseLns
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_;
};
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_;
};
-
Field Summary
Fields inherited from class com.google.ortools.constraintsolver.BaseObject
swigCMemOwn
-
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptionvoid
appendToFragment
(int index) void
delete()
protected void
finalize()
int
static long
boolean
void
boolean
protected void
static long
swigRelease
(BaseLns obj) void
void
Methods inherited from class com.google.ortools.constraintsolver.IntVarLocalSearchOperator
activate, activated, addVars, ApplyChanges, deactivate, getCPtr, HoldsDelta, isIncremental, oldValue, oneNeighbor, onStart, PrevValue, RevertChanges, setValue, size, SkipUnchanged, start, swigRelease, value, var
Methods inherited from class com.google.ortools.constraintsolver.LocalSearchOperator
EnterSearch, getCPtr, nextNeighbor, reset, swigRelease
Methods inherited from class com.google.ortools.constraintsolver.BaseObject
getCPtr, swigRelease, toString
-
Constructor Details
-
BaseLns
public BaseLns(long cPtr, boolean cMemoryOwn) -
BaseLns
-
-
Method Details
-
getCPtr
-
swigRelease
-
finalize
protected void finalize()- Overrides:
finalize
in classIntVarLocalSearchOperator
-
delete
public void delete()- Overrides:
delete
in classIntVarLocalSearchOperator
-
swigDirectorDisconnect
protected void swigDirectorDisconnect()- Overrides:
swigDirectorDisconnect
in classIntVarLocalSearchOperator
-
swigReleaseOwnership
public void swigReleaseOwnership()- Overrides:
swigReleaseOwnership
in classIntVarLocalSearchOperator
-
swigTakeOwnership
public void swigTakeOwnership()- Overrides:
swigTakeOwnership
in classIntVarLocalSearchOperator
-
initFragments
public void initFragments() -
nextFragment
public boolean nextFragment() -
appendToFragment
public void appendToFragment(int index) -
fragmentSize
public int fragmentSize() -
HasFragments
public boolean HasFragments()- Overrides:
HasFragments
in classLocalSearchOperator
-