Class Problem
- All Implemented Interfaces:
AutoCloseable
- Direct Known Subclasses:
OCP
This class supports problems of the form:
minₓ f(x)
subject to cₑ(x) = 0
cᵢ(x) ≥ 0
where f(x) is the scalar cost function, x is the vector of decision variables (variables the solver can tweak to minimize the cost function), cᵢ(x) are the inequality constraints, and cₑ(x) are the equality constraints. Constraints are equations or inequalities of the decision variables that constrain what values the solver is allowed to use when searching for an optimal solution.
The nice thing about this class is users don't have to put their system in the form shown above manually; they can write it in natural mathematical form and it'll be converted for them.
-
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptionvoidaddCallback(Predicate<IterationInfo> callback) Adds a callback to be called at the beginning of each solver iteration.voidClears the registered callbacks.voidclose()Returns the cost function's type.Creates a decision variable in the optimization problem.decisionVariable(int rows) Creates a column vector of decision variables in the optimization problem.decisionVariable(int rows, int cols) Creates a matrix of decision variables in the optimization problem.Returns the type of the highest order equality constraint.Returns the type of the highest order inequality constraint.voidTells the solver to maximize the output of the given objective function.voidmaximize(VariableMatrix objective) Tells the solver to maximize the output of the given objective function.voidTells the solver to minimize the output of the given cost function.voidminimize(VariableMatrix cost) Tells the solver to minimize the output of the given cost function.solve()Solves the optimization problem.Solves the optimization problem.voidsubjectTo(EqualityConstraints constraint) Tells the solver to solve the problem while satisfying the given equality constraint.voidsubjectTo(InequalityConstraints constraint) Tells the solver to solve the problem while satisfying the given inequality constraint.symmetricDecisionVariable(int rows) Creates a symmetric matrix of decision variables in the optimization problem.
-
Constructor Details
-
Problem
public Problem()Construct the optimization problem.
-
-
Method Details
-
close
- Specified by:
closein interfaceAutoCloseable
-
decisionVariable
Creates a decision variable in the optimization problem.Decision variables have an initial value of zero.
- Returns:
- A decision variable in the optimization problem.
-
decisionVariable
Creates a column vector of decision variables in the optimization problem.Decision variables have an initial value of zero.
- Parameters:
rows- Number of column vector rows.- Returns:
- A column vector of decision variables in the optimization problem.
-
decisionVariable
Creates a matrix of decision variables in the optimization problem.Decision variables have an initial value of zero.
- Parameters:
rows- Number of matrix rows.cols- Number of matrix columns.- Returns:
- A matrix of decision variables in the optimization problem.
-
symmetricDecisionVariable
Creates a symmetric matrix of decision variables in the optimization problem.Variable instances are reused across the diagonal, which helps reduce problem dimensionality.
Decision variables have an initial value of zero.
- Parameters:
rows- Number of matrix rows.- Returns:
- A symmetric matrix of decision varaibles in the optimization problem.
-
minimize
Tells the solver to minimize the output of the given cost function.Note that this is optional. If only constraints are specified, the solver will find the closest solution to the initial conditions that's in the feasible set.
- Parameters:
cost- The cost function to minimize.
-
minimize
Tells the solver to minimize the output of the given cost function.Note that this is optional. If only constraints are specified, the solver will find the closest solution to the initial conditions that's in the feasible set.
- Parameters:
cost- The cost function to minimize. An assertion is raised if the VariableMatrix isn't 1x1.
-
maximize
Tells the solver to maximize the output of the given objective function.Note that this is optional. If only constraints are specified, the solver will find the closest solution to the initial conditions that's in the feasible set.
- Parameters:
objective- The objective function to maximize.
-
maximize
Tells the solver to maximize the output of the given objective function.Note that this is optional. If only constraints are specified, the solver will find the closest solution to the initial conditions that's in the feasible set.
- Parameters:
objective- The objective function to maximize. An assertion is raised if the VariableMatrix isn't 1x1.
-
subjectTo
Tells the solver to solve the problem while satisfying the given equality constraint.- Parameters:
constraint- The constraint to satisfy.
-
subjectTo
Tells the solver to solve the problem while satisfying the given inequality constraint.- Parameters:
constraint- The constraint to satisfy.
-
costFunctionType
Returns the cost function's type.- Returns:
- The cost function's type.
-
equalityConstraintType
Returns the type of the highest order equality constraint.- Returns:
- The type of the highest order equality constraint.
-
inequalityConstraintType
Returns the type of the highest order inequality constraint.- Returns:
- The type of the highest order inequality constraint.
-
solve
Solves the optimization problem. The solution will be stored in the original variables used to construct the problem.- Returns:
- The solver status.
-
solve
Solves the optimization problem. The solution will be stored in the original variables used to construct the problem.- Parameters:
options- Solver options.- Returns:
- The solver status.
-
addCallback
Adds a callback to be called at the beginning of each solver iteration.The callback for this overload should return bool.
- Parameters:
callback- The callback. Returning true from the callback causes the solver to exit early with the solution it has so far.
-
clearCallbacks
Clears the registered callbacks.
-