Class ExpressionsBasedModel.Integration<S extends Optimisation.Solver>
- All Implemented Interfaces:
Optimisation, Optimisation.Integration<ExpressionsBasedModel, S>
- Direct Known Subclasses:
ConvexSolver.ModelIntegration, GomorySolver.ModelIntegration, IntegerSolver.ModelIntegration, LinearSolver.ModelIntegration, ServiceIntegration
- Enclosing class:
ExpressionsBasedModel
Optimisation.Integrations by providing some default implementations and helper methods
for common cases.
The defaults assume that the solver state and model state (variable indices) are identical.
The helper methods are for the very common case when the solver only works with free (not eliminated by the pre-solver) variables, and need to map between the solver state and the full model state.
- Author:
- apete
-
Nested Class Summary
Nested classes/interfaces inherited from interface Optimisation
Optimisation.Constraint, Optimisation.ConstraintType, Optimisation.Environment, Optimisation.Integration<M,S>, Optimisation.Model, Optimisation.Objective, Optimisation.Options, Optimisation.ProblemStructure, Optimisation.Result, Optimisation.Sense, Optimisation.Solver, Optimisation.State -
Field Summary
Fields inherited from interface Optimisation
ENVIRONMENT -
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptionprotected static doublecomputeReducedCostFromMultipliers(ExpressionsBasedModel model, int variableIndex, Optimisation.Result solverState) Reconstructs a model-level reduced cost from first principles:rc_v = c_v - Σ a_iv · λ_i, using the variable's objective coefficient and the constraint multipliers reported onsolverState.protected static Optimisation.ResultexpandFreeToFull(Optimisation.Result solverState, ExpressionsBasedModel model, DenseArray.Factory<?, ?> factory) protected static Optimisation.ResultexpandFreeToFull(Optimisation.Result solverState, ExpressionsBasedModel model, DenseArray.Factory<?, ?> factory, Optional<Supplier<Access1D<?>>> reducedGradient) protected static Optimisation.ResultexpandFreeToFull(Optimisation.Result solverState, ExpressionsBasedModel model, DenseArray.Factory<?, ?> factory, Optional<Supplier<Access1D<?>>> reducedGradient, Optimisation.Sense solverSense) final Optimisation.ResultDeprecated.v57 Not needed.protected intgetIndexInSolver(ExpressionsBasedModel model, Variable variable) This implementation returns the index of the variable in the model.protected static intgetIndexOfFreeInSolver(ExpressionsBasedModel model, Variable variable) protected static doubleReads themodel-sense objective offset.invalid reference
stashed
protected Optimisation.SenseSome solvers are hard-wired to solve either min or max problems.protected static final booleanisSwitch(ExpressionsBasedModel model, ExpressionsBasedModel.IntegrationProperty property) prepareSolverCandidate(Optimisation.Result candidateModelState, ExpressionsBasedModel model) Preserves the historical kick-starter behaviour: when no candidate is supplied one is derived (cheaply) from the model, then converted to solver state.protected static Optimisation.ResultreduceFullToFree(Optimisation.Result modelState, ExpressionsBasedModel model, DenseArray.Factory<?, ?> factory) protected static final voidsetSwitch(ExpressionsBasedModel model, ExpressionsBasedModel.IntegrationProperty property, boolean value) toModelState(Optimisation.Result solverState, ExpressionsBasedModel model) The reverse oftoSolverState(Optimisation.Result, ExpressionsBasedModel).toSolverState(Optimisation.Result modelState, ExpressionsBasedModel model) This default implementation assumes the solver state and model state are identical, and simply returns the supplied model state.withCapabilityPredicate(Predicate<ExpressionsBasedModel> capabilityPredicate) Use this to limit the cases where thisOptimisation.Integrationwould be used.withOptionsModifier(Consumer<Optimisation.Options> optionsModifier) Intercept and modify theOptimisation.Optionsinstance before building the solver.Methods inherited from class Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, waitMethods inherited from interface Optimisation.Integration
build, isCapable
-
Constructor Details
-
Integration
public Integration()
-
-
Method Details
-
computeReducedCostFromMultipliers
protected static double computeReducedCostFromMultipliers(ExpressionsBasedModel model, int variableIndex, Optimisation.Result solverState) Reconstructs a model-level reduced cost from first principles:rc_v = c_v - Σ a_iv · λ_i, using the variable's objective coefficient and the constraint multipliers reported onsolverState. Useful for variables that the solver doesn't see (eliminated by presolve), and for solver paths whose internal index space prevents direct pass-through of the rc.Returned value is in the same sense the multipliers are expressed in (i.e. typically MIN, the solver's internal sense). Callers should negate for MAX models if appropriate.
-
expandFreeToFull
protected static Optimisation.Result expandFreeToFull(Optimisation.Result solverState, ExpressionsBasedModel model, DenseArray.Factory<?, ?> factory) -
expandFreeToFull
protected static Optimisation.Result expandFreeToFull(Optimisation.Result solverState, ExpressionsBasedModel model, DenseArray.Factory<?, ?> factory, Optional<Supplier<Access1D<?>>> reducedGradient) -
expandFreeToFull
protected static Optimisation.Result expandFreeToFull(Optimisation.Result solverState, ExpressionsBasedModel model, DenseArray.Factory<?, ?> factory, Optional<Supplier<Access1D<?>>> reducedGradient, Optimisation.Sense solverSense) - Parameters:
solverSense- theOptimisation.Sensethe solver internally optimises in (usually fixed per solver — most simplex/QP solvers minimise). If this differs from the model'soptimisation sense, the reduced gradient values are negated when mapped back to the model so that callers always see them in the model's sense.
-
getIndexOfFreeInSolver
-
getObjectiveAdjustment
Reads themodel-sense objective offset. Returns 0 if nothing has been stashed.invalid reference
stashed
-
isSwitch
protected static final boolean isSwitch(ExpressionsBasedModel model, ExpressionsBasedModel.IntegrationProperty property) -
reduceFullToFree
protected static Optimisation.Result reduceFullToFree(Optimisation.Result modelState, ExpressionsBasedModel model, DenseArray.Factory<?, ?> factory) -
setSwitch
protected static final void setSwitch(ExpressionsBasedModel model, ExpressionsBasedModel.IntegrationProperty property, boolean value) -
extractSolverState
Deprecated.v57 Not needed. UseprepareSolverCandidate(org.ojalgo.optimisation.Optimisation.Result, ExpressionsBasedModel)insteadDescription copied from interface:Optimisation.IntegrationExtract state from the model and convert it to solver state.- Specified by:
extractSolverStatein interfaceOptimisation.Integration<ExpressionsBasedModel, S extends Optimisation.Solver>
-
prepareSolverCandidate
public Optimisation.Result prepareSolverCandidate(Optimisation.Result candidateModelState, ExpressionsBasedModel model) Preserves the historical kick-starter behaviour: when no candidate is supplied one is derived (cheaply) from the model, then converted to solver state. Solvers that ignore the kick-starter should override this to always returnnull.- Specified by:
prepareSolverCandidatein interfaceOptimisation.Integration<ExpressionsBasedModel, S extends Optimisation.Solver>
-
toModelState
public Optimisation.Result toModelState(Optimisation.Result solverState, ExpressionsBasedModel model) The reverse oftoSolverState(Optimisation.Result, ExpressionsBasedModel).- Specified by:
toModelStatein interfaceOptimisation.Integration<ExpressionsBasedModel, S extends Optimisation.Solver>- See Also:
-
toSolverState
public Optimisation.Result toSolverState(Optimisation.Result modelState, ExpressionsBasedModel model) This default implementation assumes the solver state and model state are identical, and simply returns the supplied model state.In any case where the set of variables present in the solver does not match what's in the model one-to-one, this method and its reciprocal
toModelState(Optimisation.Result, ExpressionsBasedModel)needs to be overridden with custom mapping implementations.A very common case is when the solver only works with free (not eliminated by the pre-solver) variables. There are helper methods to do just that.
- Specified by:
toSolverStatein interfaceOptimisation.Integration<ExpressionsBasedModel, S extends Optimisation.Solver>- See Also:
-
withCapabilityPredicate
public final ExpressionsBasedModel.Integration<S> withCapabilityPredicate(Predicate<ExpressionsBasedModel> capabilityPredicate) Use this to limit the cases where thisOptimisation.Integrationwould be used.Returns a new Integration instance where the supplied
Predicateneeds to test true in addition to the underlyingOptimisation.Integration.isCapable(Optimisation.Model). -
withOptionsModifier
public final ExpressionsBasedModel.Integration<S> withOptionsModifier(Consumer<Optimisation.Options> optionsModifier) Intercept and modify theOptimisation.Optionsinstance before building the solver. -
getIndexInSolver
This implementation returns the index of the variable in the model. Override if you need something else. The utilitygetIndexOfFreeInSolver(ExpressionsBasedModel, Variable)can be used if the solver only works with free variables.- Returns:
- The index with which one can reference parameters related to this variable in the solver.
-
getSolverSense
Some solvers are hard-wired to solve either min or max problems. (Typically ojAlgo's built-in solvers are implemented that way.) If that's the case this method should indicate what the convention is. Returning null indicates there is no convention/hard-wire, and the solver will either min or max depending what's specified.When the solver's sense is hard-wired some things, like the sign of the optimal value or the reduced costs, may have to be adjusted.
Since this was a late addition to this class a default implementation was needed, and null is commonly the correct return value for 3:d party solvers.
-