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 TypeMethodDescriptionvoidappendToFragment(int index) voiddelete()protected voidfinalize()intstatic longbooleanvoidbooleanprotected voidstatic longswigRelease(BaseLns obj) voidvoidMethods 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, varMethods inherited from class com.google.ortools.constraintsolver.LocalSearchOperator
EnterSearch, getCPtr, nextNeighbor, reset, swigReleaseMethods 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:
finalizein classIntVarLocalSearchOperator
-
delete
public void delete()- Overrides:
deletein classIntVarLocalSearchOperator
-
swigDirectorDisconnect
protected void swigDirectorDisconnect()- Overrides:
swigDirectorDisconnectin classIntVarLocalSearchOperator
-
swigReleaseOwnership
public void swigReleaseOwnership()- Overrides:
swigReleaseOwnershipin classIntVarLocalSearchOperator
-
swigTakeOwnership
public void swigTakeOwnership()- Overrides:
swigTakeOwnershipin classIntVarLocalSearchOperator
-
initFragments
public void initFragments() -
nextFragment
public boolean nextFragment() -
appendToFragment
public void appendToFragment(int index) -
fragmentSize
public int fragmentSize() -
HasFragments
public boolean HasFragments()- Overrides:
HasFragmentsin classLocalSearchOperator
-