Package org.ojalgo.optimisation.integer
Class ModelStrategy
- 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.AbstractStrategy
instead.
-
-
Nested Class Summary
Nested Classes Modifier and Type Class Description static class
ModelStrategy.AbstractStrategy
When implementing your ownModelStrategy
extending this abstract class is a good starting point.(package private) static class
ModelStrategy.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 boolean
cutting
Indicates if cut generation is turned on, or not.private int[]
myIndices
One entry per integer variable, the entry is the global index of that integer variableprivate Optimisation.Sense
myOptimisationSense
private IntegerStrategy
myStrategy
private java.util.List<java.util.Comparator<NodeKey>>
myWorkerPriorities
-
Fields inherited from interface org.ojalgo.optimisation.integer.IntegerStrategy
DEFAULT
-
-
Constructor Summary
Constructors Modifier Constructor Description protected
ModelStrategy(ExpressionsBasedModel model, IntegerStrategy strategy)
-
Method Summary
All Methods Instance Methods Abstract Methods Concrete Methods Modifier and Type Method Description protected int
countIntegerVariables()
int
countUniqueStrategies()
NumberContext
getGapTolerance()
The MIP gap is the difference between the best integer solution found so far and a node's relaxed non-integer solution.IntegerStrategy.GMICutConfiguration
getGMICutConfiguration()
protected int
getIndex(int idx)
The variable's global indexNumberContext
getIntegralityTolerance()
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 ModelStrategy
initialise(MultiaryFunction.TwiceDifferentiable<java.lang.Double> function, Access1D<?> point)
Called, once, at the very beginning of the solve process.protected abstract boolean
isCutRatherThanBranch(double displacement, boolean found)
protected abstract boolean
isDirect(NodeKey node, boolean found)
This method will be called twice when branching – once for each of the new nodes created by branching.protected boolean
isGoodEnough(Optimisation.Result bestResultSoFar, double relaxedNodeValue)
Is the node's result good enough to continue branching? (Compare the node's objective function value with the that of the best integer solution found so far.)protected abstract void
markInfeasible(NodeKey key, boolean found)
Called everytime a node/subproblem is found to be infeasibleprotected abstract void
markInteger(NodeKey key, Optimisation.Result result)
Called everytime a new integer solution is foundModelStrategy
newModelStrategy(ExpressionsBasedModel model)
protected abstract double
toComparable(int idx, double displacement, boolean found)
Convert the fraction to something "comparable" used to determine which variable to branch on.java.lang.String
toString()
-
-
-
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:
countUniqueStrategies
in interfaceIntegerStrategy
-
getGapTolerance
public NumberContext getGapTolerance()
Description copied from interface:IntegerStrategy
The 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:
getGapTolerance
in interfaceIntegerStrategy
- Returns:
- The tolerance context used to determine if the gap is too small or not
-
getGMICutConfiguration
public IntegerStrategy.GMICutConfiguration getGMICutConfiguration()
- Specified by:
getGMICutConfiguration
in interfaceIntegerStrategy
-
getIntegralityTolerance
public NumberContext getIntegralityTolerance()
Description copied from interface:IntegerStrategy
Used to determine if a variable value is integer or not- Specified by:
getIntegralityTolerance
in interfaceIntegerStrategy
-
getWorkerPriorities
public java.util.List<java.util.Comparator<NodeKey>> getWorkerPriorities()
Description copied from interface:IntegerStrategy
There will be 1 worker thread per item in the returnedList
. TheComparator
instances need not be unique. Used to prioritise among the nodes waiting to be evaluated.- Specified by:
getWorkerPriorities
in interfaceIntegerStrategy
-
newModelStrategy
public ModelStrategy newModelStrategy(ExpressionsBasedModel model)
- Specified by:
newModelStrategy
in interfaceIntegerStrategy
-
toString
public final java.lang.String toString()
- Overrides:
toString
in classjava.lang.Object
-
countIntegerVariables
protected int countIntegerVariables()
-
getIndex
protected int getIndex(int idx)
The variable's global index- Parameters:
idx
- Index among the integer variables
-
initialise
protected abstract ModelStrategy initialise(MultiaryFunction.TwiceDifferentiable<java.lang.Double> function, Access1D<?> point)
Called, once, at the very beginning of the solve process.
-
isCutRatherThanBranch
protected abstract boolean isCutRatherThanBranch(double displacement, boolean found)
-
isDirect
protected abstract boolean isDirect(NodeKey node, boolean found)
This method will be called twice when branching – once for each of the new nodes created by branching. In most cases you only want to return true for (at most) one of those new branches. Always returning true for both the new nodes will cause excessive memory consumption.- Parameters:
node
- The node to checkfound
- Is an integer solution already found?- Returns:
- true if this node should be evaluated directly (not deferred)
-
isGoodEnough
protected boolean isGoodEnough(Optimisation.Result bestResultSoFar, double relaxedNodeValue)
Is the node's result good enough to continue branching? (Compare the node's objective function value with the that of the best integer solution found so far.)
-
markInfeasible
protected abstract void markInfeasible(NodeKey key, boolean found)
Called everytime a node/subproblem is found to be infeasible
-
markInteger
protected abstract void markInteger(NodeKey key, Optimisation.Result result)
Called everytime a new integer solution is found
-
toComparable
protected abstract double toComparable(int idx, double displacement, boolean found)
Convert the fraction to something "comparable" used to determine which variable to branch on. If a variable is at an integer value or not is determined by theOptimisation.Options.feasibility
property. If an integer variable is not at an integer value, then this method is invoked to obtain a value that is then used to copare with that of other integer variables with fractional values. The variable with the max "comparable" is picked for branching.- Parameters:
idx
- Integer variable indexdisplacement
- variable's fractional valuefound
- Is an integer solution already found?- Returns:
- Value used to compare variables when determining which to branch on. Larger value means more likelyn to branch on this.
-
-