- java.lang.Object
-
- org.ojalgo.optimisation.integer.ModelStrategy
-
- All Implemented Interfaces:
IntegerStrategy
- Direct Known Subclasses:
ModelStrategy.AbstractStrategy,ModelStrategy.DefaultStrategy
public abstract class ModelStrategy extends java.lang.Object implements IntegerStrategy
This base class contains some model/problem specific data required by theIntegerSolver. The "strategies" are implemented in subclasses. If you plan to implement a custom strategy it may be helpful to extendModelStrategy.AbstractStrategyinstead.
-
-
Nested Class Summary
Nested Classes Modifier and Type Class Description static classModelStrategy.AbstractStrategyWhen implementing your ownModelStrategyextending this abstract class is a good starting point.(package private) static classModelStrategy.DefaultStrategy-
Nested classes/interfaces inherited from interface org.ojalgo.optimisation.integer.IntegerStrategy
IntegerStrategy.ConfigurableStrategy, IntegerStrategy.GMICutConfiguration
-
-
Field Summary
Fields Modifier and Type Field Description protected booleancuttingIndicates if cut generation is turned on, or not.private int[]myIndicesOne entry per integer variable, the entry is the global index of that integer variableprivate Optimisation.SensemyOptimisationSenseprivate IntegerStrategymyStrategyprivate java.util.List<java.util.Comparator<NodeKey>>myWorkerPriorities-
Fields inherited from interface org.ojalgo.optimisation.integer.IntegerStrategy
DEFAULT
-
-
Constructor Summary
Constructors Modifier Constructor Description protectedModelStrategy(ExpressionsBasedModel model, IntegerStrategy strategy)
-
Method Summary
All Methods Instance Methods Abstract Methods Concrete Methods Modifier and Type Method Description protected intcountIntegerVariables()intcountUniqueStrategies()NumberContextgetGapTolerance()The MIP gap is the difference between the best integer solution found so far and a node's relaxed non-integer solution.IntegerStrategy.GMICutConfigurationgetGMICutConfiguration()protected intgetIndex(int idx)NumberContextgetIntegralityTolerance()Used to determine if a variable value is integer or notjava.util.List<java.util.Comparator<NodeKey>>getWorkerPriorities()There will be 1 worker thread per item in the returnedList.protected abstract ModelStrategyinitialise(MultiaryFunction.TwiceDifferentiable<java.lang.Double> function, Access1D<?> point)protected abstract booleanisCutRatherThanBranch(NodeKey nodeKey, int branchIntegerIndex, double variableValue, double nodeValue, Optimisation.Result bestResultSoFar)Decide if cuts should be attempted at this node.protected booleanisGoodEnough(Optimisation.Result bestResultSoFar, double relaxedNodeValue)(package private) booleanisMinimisation()protected abstract voidmarkInfeasible(NodeKey key, boolean found, double incumbentValue)protected abstract voidmarkInteger(NodeKey key, Optimisation.Result result)ModelStrategynewModelStrategy(ExpressionsBasedModel model)protected abstract voidonCutFailure()Called when cut generation produced no cuts (default: disable further cutting).protected abstract voidonCutSuccess(NodeKey nodeKey)Called when cut generation added at least one cut (default: no-op).protected abstract voidonNodeSolved(NodeKey key, Optimisation.Result child, double childObj, boolean minimisation)Hook to update pseudo-costs after a node is solved.protected abstract doublescoreBranch(int idx, double distanceDown, double distanceUp, boolean found)protected abstract doublescoreBranchDown(int idx, double distanceDown, boolean found)protected abstract doublescoreBranchUp(int idx, double distanceUp, boolean found)java.lang.StringtoString()
-
-
-
Field Detail
-
myIndices
private final int[] myIndices
One entry per integer variable, the entry is the global index of that integer variable
-
myOptimisationSense
private final Optimisation.Sense myOptimisationSense
-
myStrategy
private final IntegerStrategy myStrategy
-
myWorkerPriorities
private final java.util.List<java.util.Comparator<NodeKey>> myWorkerPriorities
-
cutting
protected boolean cutting
Indicates if cut generation is turned on, or not. On by default. Algorithms can turn off when/if no longer useful.
-
-
Constructor Detail
-
ModelStrategy
protected ModelStrategy(ExpressionsBasedModel model, IntegerStrategy strategy)
-
-
Method Detail
-
countUniqueStrategies
public int countUniqueStrategies()
- Specified by:
countUniqueStrategiesin interfaceIntegerStrategy
-
getGapTolerance
public NumberContext getGapTolerance()
Description copied from interface:IntegerStrategyThe MIP gap is the difference between the best integer solution found so far and a node's relaxed non-integer solution. The relative MIP gap is that difference divided by the optimal value (approximated by the currently best integer solution). If the gap (absolute or relative) is too small, then the corresponding branch is terminated as it is deemed unlikely or too "expensive" to find better integer solutions there.- Specified by:
getGapTolerancein interfaceIntegerStrategy- Returns:
- The tolerance context used to determine if the gap is too small or not
-
getGMICutConfiguration
public IntegerStrategy.GMICutConfiguration getGMICutConfiguration()
- Specified by:
getGMICutConfigurationin interfaceIntegerStrategy
-
getIntegralityTolerance
public NumberContext getIntegralityTolerance()
Description copied from interface:IntegerStrategyUsed to determine if a variable value is integer or not- Specified by:
getIntegralityTolerancein interfaceIntegerStrategy
-
getWorkerPriorities
public java.util.List<java.util.Comparator<NodeKey>> getWorkerPriorities()
Description copied from interface:IntegerStrategyThere will be 1 worker thread per item in the returnedList. TheComparatorinstances need not be unique. Used to prioritise among the nodes waiting to be evaluated.- Specified by:
getWorkerPrioritiesin interfaceIntegerStrategy
-
newModelStrategy
public ModelStrategy newModelStrategy(ExpressionsBasedModel model)
- Specified by:
newModelStrategyin interfaceIntegerStrategy
-
toString
public final java.lang.String toString()
- Overrides:
toStringin classjava.lang.Object
-
countIntegerVariables
protected int countIntegerVariables()
-
getIndex
protected int getIndex(int idx)
-
initialise
protected abstract ModelStrategy initialise(MultiaryFunction.TwiceDifferentiable<java.lang.Double> function, Access1D<?> point)
-
isCutRatherThanBranch
protected abstract boolean isCutRatherThanBranch(NodeKey nodeKey, int branchIntegerIndex, double variableValue, double nodeValue, Optimisation.Result bestResultSoFar)
Decide if cuts should be attempted at this node.
-
isGoodEnough
protected boolean isGoodEnough(Optimisation.Result bestResultSoFar, double relaxedNodeValue)
-
markInfeasible
protected abstract void markInfeasible(NodeKey key, boolean found, double incumbentValue)
-
markInteger
protected abstract void markInteger(NodeKey key, Optimisation.Result result)
-
onCutFailure
protected abstract void onCutFailure()
Called when cut generation produced no cuts (default: disable further cutting).
-
onCutSuccess
protected abstract void onCutSuccess(NodeKey nodeKey)
Called when cut generation added at least one cut (default: no-op).
-
onNodeSolved
protected abstract void onNodeSolved(NodeKey key, Optimisation.Result child, double childObj, boolean minimisation)
Hook to update pseudo-costs after a node is solved.
-
scoreBranch
protected abstract double scoreBranch(int idx, double distanceDown, double distanceUp, boolean found)
-
scoreBranchDown
protected abstract double scoreBranchDown(int idx, double distanceDown, boolean found)
-
scoreBranchUp
protected abstract double scoreBranchUp(int idx, double distanceUp, boolean found)
-
isMinimisation
boolean isMinimisation()
-
-