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
This base class contains some model/problem specific data required by the
IntegerSolver
. The
"strategies" are implemented in subclasses. If you plan to implement a custom strategy it may be helpful to
extend ModelStrategy.AbstractStrategy
instead.-
Nested Class Summary
Nested ClassesModifier and TypeClassDescriptionstatic class
When implementing your ownModelStrategy
extending this abstract class is a good starting point.(package private) static final class
Nested classes/interfaces inherited from interface org.ojalgo.optimisation.integer.IntegerStrategy
IntegerStrategy.ConfigurableStrategy, IntegerStrategy.GMICutConfiguration
-
Field Summary
FieldsModifier and TypeFieldDescriptionprotected boolean
Indicates if cut generation is turned on, or not.private final int[]
One entry per integer variable, the entry is the global index of that integer variableprivate final Optimisation.Sense
private final IntegerStrategy
private final List
<Comparator<NodeKey>> Fields inherited from interface org.ojalgo.optimisation.integer.IntegerStrategy
DEFAULT
-
Constructor Summary
ConstructorsModifierConstructorDescriptionprotected
ModelStrategy
(ExpressionsBasedModel model, IntegerStrategy strategy) -
Method Summary
Modifier and TypeMethodDescriptionprotected int
The MIP gap is the difference between the best integer solution found so far and a node's relaxed non-integer solution.protected int
getIndex
(int idx) The variable's global indexUsed to determine if a variable value is integer or notThere will be 1 worker thread per item in the returnedList
.protected abstract ModelStrategy
initialise
(MultiaryFunction.TwiceDifferentiable<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
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 foundprotected abstract double
toComparable
(int idx, double displacement, boolean found) Convert the fraction to something "comparable" used to determine which variable to branch on.final String
toString()
-
Field Details
-
myIndices
private final int[] myIndicesOne entry per integer variable, the entry is the global index of that integer variable -
myOptimisationSense
-
myStrategy
-
myWorkerPriorities
-
cutting
protected boolean cuttingIndicates if cut generation is turned on, or not. On by default. Algorithms can turn off when/if no longer useful.
-
-
Constructor Details
-
ModelStrategy
-
-
Method Details
-
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
- Specified by:
getGMICutConfiguration
in interfaceIntegerStrategy
-
getIntegralityTolerance
Description copied from interface:IntegerStrategy
Used to determine if a variable value is integer or not- Specified by:
getIntegralityTolerance
in interfaceIntegerStrategy
-
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
- Specified by:
newModelStrategy
in interfaceIntegerStrategy
-
toString
-
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<Double> function, Access1D<?> point) Called, once, at the very beginning of the solve process. -
isCutRatherThanBranch
protected abstract boolean isCutRatherThanBranch(double displacement, boolean found) -
isDirect
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
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
Called everytime a node/subproblem is found to be infeasible -
markInteger
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.
-