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 Object implements IntegerStrategy
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.
  • Field Details

    • 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 List<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 Details

  • Method Details

    • 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 interface IntegerStrategy
      Returns:
      The tolerance context used to determine if the gap is too small or not
    • getGMICutConfiguration

      public IntegerStrategy.GMICutConfiguration getGMICutConfiguration()
      Specified by:
      getGMICutConfiguration in interface IntegerStrategy
    • getIntegralityTolerance

      public NumberContext getIntegralityTolerance()
      Description copied from interface: IntegerStrategy
      Used to determine if a variable value is integer or not
      Specified by:
      getIntegralityTolerance in interface IntegerStrategy
    • getWorkerPriorities

      public List<Comparator<NodeKey>> getWorkerPriorities()
      Description copied from interface: IntegerStrategy
      There will be 1 worker thread per item in the returned List. The Comparator instances need not be unique. Used to prioritise among the nodes waiting to be evaluated.
      Specified by:
      getWorkerPriorities in interface IntegerStrategy
    • newModelStrategy

      public ModelStrategy newModelStrategy(ExpressionsBasedModel model)
      Specified by:
      newModelStrategy in interface IntegerStrategy
    • toString

      public final String toString()
      Overrides:
      toString in class 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<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 check
      found - 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 the Optimisation.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 index
      displacement - variable's fractional value
      found - 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.