public final class ExpressionsBasedModel extends Object
Lets you construct optimisation problems by combining (mathematical) expressions in terms of variables. Each expression or variable can be a constraint and/or contribute to the objective function. An expression or variable is turned into a constraint by setting a lower and/or upper limit. Use ModelEntity.lower(Number), ModelEntity.upper(Number) or ModelEntity.level(Number). An expression or variable is made part of (contributing to) the objective function by setting a contribution weight. Use ModelEntity.weight(Number).
You may think of variables as simple (the simplest possible) expressions, and of expressions as weighted combinations of variables. They are both model entities and it is as such they can be turned into constraints and set to contribute to the objective function. Alternatively you may choose to disregard the fact that variables are model entities and simply treat them as index values. In this case everything (constraints and objective) needs to be defined using expressions.
Basic instructions:
When using this class you do not need to worry about which solver will actually be used. The docs of the various solvers describe requirements on input formats and similar. This is handled for you and should absolutely NOT be considered here! Compared to using the various solvers directly this class actually does something for you:
Different solvers can be used, and ojAlgo comes with collection built in. The default built-in solvers can handle anythimng you can model with a couple of restrictions:
Modifier and Type | Class and Description |
---|---|
static class |
ExpressionsBasedModel.Integration<S extends Optimisation.Solver> |
static class |
ExpressionsBasedModel.Intermediate |
static class |
ExpressionsBasedModel.Presolver |
Optimisation.Constraint, Optimisation.Model, Optimisation.Objective, Optimisation.Options, Optimisation.Result, Optimisation.Solver, Optimisation.State
Modifier and Type | Field and Description |
---|---|
Optimisation.Options |
options |
Constructor and Description |
---|
ExpressionsBasedModel() |
ExpressionsBasedModel(Collection<? extends Variable> variables) |
ExpressionsBasedModel(Optimisation.Options someOptions) |
ExpressionsBasedModel(Variable... variables) |
public final Optimisation.Options options
public ExpressionsBasedModel()
public ExpressionsBasedModel(Collection<? extends Variable> variables)
public ExpressionsBasedModel(Optimisation.Options someOptions)
public ExpressionsBasedModel(Variable... variables)
public static boolean addFallbackSolver(ExpressionsBasedModel.Integration<?> integration)
@Deprecated public static boolean addIntegration(ExpressionsBasedModel.Integration<?> integration)
addPreferredSolver(Integration)
or
addFallbackSolver(Integration)
insteadpublic static boolean addPreferredSolver(ExpressionsBasedModel.Integration<?> integration)
public static boolean addPresolver(ExpressionsBasedModel.Presolver presolver)
public static void clearIntegrations()
public static void clearPresolvers()
public static boolean removeIntegration(ExpressionsBasedModel.Integration<?> integration)
public static boolean removePresolver(ExpressionsBasedModel.Presolver presolver)
public Expression addExpression()
public Expression addExpression(String name)
public void addSpecialOrderedSet(Collection<Variable> orderedSet, int type, Expression linkedTo)
public void addSpecialOrderedSet(Collection<Variable> orderedSet, int min, int max)
max
and min
parameter values.orderedSet
- The set members in correct order. Each of these variables must be binary.min
- The minimum number of binary varibales in the set that must be "ON" (Set this to 0 if there
is no minimum.)max
- The SOS type or maximum number of binary varibales in the set that may be "ON"public Variable addVariable()
public void addVariable(Variable variable)
public void addVariables(Collection<? extends Variable> variables)
public void addVariables(Variable[] variables)
public Stream<Variable> bounds()
public Stream<Expression> constraints()
public ExpressionsBasedModel copy()
public int countExpressions()
public int countVariables()
public void dispose()
Optimisation.Model
public Expression generateCut(Expression constraint, Optimisation.Result solution)
public Expression getExpression(String name)
public Collection<Expression> getExpressions()
public Set<Structure1D.IntIndex> getFixedVariables()
public List<Variable> getFreeVariables()
public List<Variable> getIntegerVariables()
public List<Variable> getNegativeVariables()
public List<Variable> getPositiveVariables()
public Variable getVariable(int index)
public Variable getVariable(Structure1D.IntIndex index)
public Optimisation.Result getVariableValues()
public Optimisation.Result getVariableValues(NumberContext validationContext)
public int indexOf(Variable variable)
public int indexOfFreeVariable(int globalIndex)
globalIndex
- General, global, variable indexpublic int indexOfFreeVariable(Structure1D.IntIndex variableIndex)
public int indexOfFreeVariable(Variable variable)
public int indexOfIntegerVariable(int globalIndex)
globalIndex
- General, global, variable indexpublic int indexOfIntegerVariable(Structure1D.IntIndex variableIndex)
public int indexOfIntegerVariable(Variable variable)
public int indexOfNegativeVariable(int globalIndex)
globalIndex
- General, global, variable indexpublic int indexOfNegativeVariable(Structure1D.IntIndex variableIndex)
public int indexOfNegativeVariable(Variable variable)
public int indexOfPositiveVariable(int globalIndex)
globalIndex
- General, global, variable indexpublic int indexOfPositiveVariable(Structure1D.IntIndex variableIndex)
public int indexOfPositiveVariable(Variable variable)
public boolean isAnyConstraintQuadratic()
@Deprecated public boolean isAnyExpressionQuadratic()
isAnyConstraintQuadratic()
or isAnyObjectiveQuadratic()
insteadpublic boolean isAnyObjectiveQuadratic()
public boolean isAnyVariableFixed()
public boolean isAnyVariableInteger()
public boolean isWorkCopy()
public void limitObjective(BigDecimal lower, BigDecimal upper)
public Optimisation.Result maximise()
public Optimisation.Result minimise()
public Expression objective()
ModelEntity.weight(Number)
/ModelEntity.weight(Number)
on one or more variables and/or
expressions.public ExpressionsBasedModel.Intermediate prepare()
The general recommendation is to NOT call this method directly. Instead you should use/call
maximise()
or minimise()
.
The primary use case for this method is as a callback method for solvers that iteratively modifies the model and solves at each iteration point.
With direct usage of this method:
public ExpressionsBasedModel relax(boolean inPlace)
public ExpressionsBasedModel simplify()
public ExpressionsBasedModel snapshot()
public boolean validate()
Optimisation.Model.validate()
public boolean validate(Access1D<BigDecimal> solution)
public boolean validate(Access1D<BigDecimal> solution, NumberContext context)
public boolean validate(Access1D<BigDecimal> solution, NumberContext context, BasicLogger.Printer appender)
public boolean validate(Access1D<BigDecimal> solution, BasicLogger.Printer appender)
public boolean validate(NumberContext context)
public boolean validate(NumberContext context, BasicLogger.Printer appender)
public boolean validate(BasicLogger.Printer appender)
public final boolean isMaximisation()
public final boolean isMinimisation()
public final void setMaximisation()
public final void setMinimisation()
protected final void setMaximisation(boolean maximisation)
protected final void setMinimisation(boolean minimisation)
Copyright © 2019 Optimatika. All rights reserved.