public class OptimizationProblem extends Object
Constructor and Description |
---|
OptimizationProblem()
Creates an optimization problem object
|
Modifier and Type | Method and Description |
---|---|
String |
about()
Returns an informative string about the JOM library
|
Expression |
addConstraint(String expression)
Adds (an array of) constraints to the optimization problem.
|
Expression |
addConstraint(String expression,
String identifier)
Adds (an array of) constraints to the optimization problem.
|
void |
addDecisionVariable(String name,
boolean isInteger,
int[] size)
Same as addDecisionVariable(name, isInteger, size, null, null);
|
void |
addDecisionVariable(String name,
boolean isInteger,
int[] size,
double[] x_l,
double[] x_u)
Adds an array of decision variables to the optimization problem
|
void |
addDecisionVariable(String name,
boolean isInteger,
int[] size,
double x_l,
double x_u)
addDecisionVariable(String name, boolean isInteger, int[] size, DoubleMatrixND x_l, DoubleMatrixND x_u), but now the lower (upper) bounds
for all the decision variables in the array are equal to x_l (x_u).
|
void |
addDecisionVariable(String name,
boolean isInteger,
int[] size,
cern.colt.matrix.tdouble.DoubleMatrix1D x_l,
cern.colt.matrix.tdouble.DoubleMatrix1D x_u)
Adds an array of decision variables to the optimization problem
|
void |
addDecisionVariable(String name,
boolean isInteger,
int[] size,
DoubleMatrixND x_l,
DoubleMatrixND x_u)
Adds an array of decision variables to the optimization problem
|
boolean |
feasibleSolutionDoesNotExist()
Returns true if the problem was attempted to be solved, and the solver declares that the problem has no feasible solutions.
|
boolean |
foundUnboundedSolution()
Returns true if the problem was attempted to be solved, and the solver declares that the problem is unbounded.
|
double |
getBestOptimalityBound()
Returns the best optimality bound found by the solver.
|
DoubleMatrixND |
getInputParameter(String name)
Obtains the value (an array of doubles) of the input parameter previously set
|
DoubleMatrixND |
getMultiplierOfLowerBoundConstraintToPrimalVariables(String decisionVariableName)
Returns the multipliers of the automatic constraints: \(x_l \leq varName\) added to the problem, where \(x_l\) is the array of lower bounds provided,
associated to the decision variable.
|
DoubleMatrixND |
getMultiplierOfUpperBoundConstraintToPrimalVariables(String decisionVariableName)
Returns the multipliers of the automatic constraints: \(varName \leq x_u\) added to the problem, where \(x_u\) is the array of upper bounds provided,
associated to the decision variable.
|
DoubleMatrixND |
getMultipliersOfConstraint(String constraintIdentifier)
Returns the multipliers of the given constraint
|
int |
getNumLinearScalarConstraints()
Gets the number of scalar constraints in the problem that are linear (with integer variables or not).
|
int |
getNumNonLinearScalarConstraints()
Gets the number of scalar constraints in the problem that are non linear (with integer variables or not).
|
int |
getNumScalarDecisionVariables()
Gets the number of scalar decision variables.
|
Expression |
getObjectiveFunction()
Gets the objective function expression set in the problem
|
double |
getOptimalCost()
Returns the cost of the solution obtained by the solver
|
DoubleMatrixND |
getPrimalSolution(String decisionVariable)
Returns the primal solution obtained after solving the problem for the given (array of) decision variables.
|
DoubleMatrixND |
getSlackOfConstraint(String constraintIdentifier)
Returns the slack of the given constraints.
|
boolean |
isInputParameter(String name)
Returns true if the given name corresponds to an input parameter defined for the problem
|
boolean |
isIntegerProblem()
Returns true if the problem has one or more decision variables constrained to be integer, false otherwise
|
boolean |
isLinearProblem()
Returns true if the problem is linear (with some/all integer variables or not).
|
boolean |
isToMinimize()
Returns true if the current objective function has already been defined, and the problem is set as a minimization problem
|
Expression |
parseExpression(String expression)
Help function (not needed usually for solving optimization problems) to generate an Expression object from its String representation.
|
void |
resetTimer()
Resets the timers that track the amount of time involved in each part of the computation, to write the time report with the
|
void |
setInitialSolution(String decisionVariableName,
double initialValue)
Sets the initial solution of the optimization algorithm solving the problem (can be used for setting the starting solution in IPOPT solver).
|
void |
setInitialSolution(String decisionVariableName,
DoubleMatrixND initialValue)
Sets the initial solution of the optimization algorithm solving the problem (to be used by some solvers like IPOPT).
|
void |
setInputParameter(String name,
Collection<? extends Number> values,
String rowColumnVector)
Sets the value of the (arrayed) input parameter identified by its name.
|
void |
setInputParameter(String name,
double value)
Sets the value of the (arrayed) input parameter identified by its name.
|
void |
setInputParameter(String name,
double[][] values)
Sets the value of the (arrayed) input parameter identified by its name.
|
void |
setInputParameter(String name,
double[] values,
String rowColumnVector)
Sets the value of the (arrayed) input parameter identified by its name.
|
void |
setInputParameter(String name,
cern.colt.matrix.tdouble.DoubleMatrix1D values,
String rowColumnVector)
Sets the value of the (arrayed) input parameter identified by its name.
|
void |
setInputParameter(String name,
cern.colt.matrix.tdouble.DoubleMatrix2D array)
Sets the value of the (arrayed) input parameter identified by its name.
|
void |
setInputParameter(String name,
DoubleMatrixND array)
Sets the value of the (arrayed) input parameter identified by its name.
|
void |
setInputParameter(String name,
int value)
Sets the value of the (arrayed) input parameter identified by its name.
|
void |
setInputParameter(String name,
int[] values,
String rowColumnVector)
Sets the value of the (arrayed) input parameter identified by its name.
|
void |
setInputParameter(String name,
String expression)
Sets the value of the (arrayed) input parameter identified by its name.
|
Expression |
setObjectiveFunction(String minMax,
String expression)
Sets the objective function of the optimization problem, and its direction (maximice or minimice).
|
boolean |
solutionIsFeasible()
Returns true if the problem was solved, and the solution obtained is feasible.
|
boolean |
solutionIsOptimal()
Returns true if the problem was solved, and the solution obtained is optimal according to the solver.
|
void |
solve(String solverName,
Object... paramValuePairs)
Calls the indicated solver to solve the optimization problem in its current state (e.g. current objective function and input parameters
set).
|
String |
timeReport()
Return a printed report with the time spended in the different parts of the problem: defining the variables, objective, constraints and
solving.
|
String |
toString()
Returns a formatted string with some information of the optimization problem
|
public OptimizationProblem()
public String about()
public Expression addConstraint(String expression)
expression
- The string expression of the constraint.public Expression addConstraint(String expression, String identifier)
expression
- The string expression of the constraint.identifier
- A unique string given to identify this constraintpublic void addDecisionVariable(String name, boolean isInteger, int[] size)
name
- Name of the array of decision variables, as it will used in the expressions.isInteger
- True if the decision variables in the array are all constrained to be integersize
- One coordinate per dimension of the array, each coordinate is the size of the array in the respective dimension.public void addDecisionVariable(String name, boolean isInteger, int[] size, double x_l, double x_u)
name
- Name of the array of decision variables, as it will used in the expressions.isInteger
- True if the decision variables in the array are all constrained to be integersize
- One coordinate per dimension of the array, each coordinate is the size of the array in the respective dimension.x_l
- The lower bounds of the variables are created as new DoubleMatrixND (size,x_l)x_u
- The upper bounds of the variables are created as new DoubleMatrixND (size,x_u)public void addDecisionVariable(String name, boolean isInteger, int[] size, double[] x_l, double[] x_u)
name
- Name of the array of decision variables, as it will used in the expressions.isInteger
- True if the decision variables in the array are all constrained to be integersize
- One coordinate per dimension of the array, each coordinate is the size of the array in the respective dimension.x_l
- The lower bounds of the variables are created as new DoubleMatrixND (size,x_l)x_u
- The upper bounds of the variables are created as new DoubleMatrixND (size,x_u)public void addDecisionVariable(String name, boolean isInteger, int[] size, cern.colt.matrix.tdouble.DoubleMatrix1D x_l, cern.colt.matrix.tdouble.DoubleMatrix1D x_u)
name
- Name of the array of decision variables, as it will used in the expressions.isInteger
- True if the decision variables in the array are all constrained to be integersize
- One coordinate per dimension of the array, each coordinate is the size of the array in the respective dimension.x_l
- The lower bounds of the variables are created as new DoubleMatrixND (size,x_l)x_u
- The upper bounds of the variables are created as new DoubleMatrixND (size,x_u)public void addDecisionVariable(String name, boolean isInteger, int[] size, DoubleMatrixND x_l, DoubleMatrixND x_u)
name
- Name of the array of decision variables, as it will used in the expressions.isInteger
- True if the decision variables in the array are all constrained to be integersize
- One coordinate per dimension of the array, each coordinate is the size of the array in the respective dimension.x_l
- An array of doubles of the same size of the decision variables, with the lower bounds of the variables.x_u
- An array of doubles of the same size of the decision variables, with the upper bounds of the variables.public boolean feasibleSolutionDoesNotExist()
public boolean foundUnboundedSolution()
public DoubleMatrixND getInputParameter(String name)
name
- Name of the input parameter as it appears in the expressionspublic DoubleMatrixND getMultiplierOfLowerBoundConstraintToPrimalVariables(String decisionVariableName)
decisionVariableName
- The name of the decision variablepublic DoubleMatrixND getMultiplierOfUpperBoundConstraintToPrimalVariables(String decisionVariableName)
decisionVariableName
- The name of the decision variablepublic DoubleMatrixND getMultipliersOfConstraint(String constraintIdentifier)
constraintIdentifier
- The unique identifier of the constraintpublic int getNumLinearScalarConstraints()
public int getNumNonLinearScalarConstraints()
public int getNumScalarDecisionVariables()
public Expression getObjectiveFunction()
public double getOptimalCost()
public double getBestOptimalityBound()
-Double.MAX_VALUE
is returned in
minimization problems, and Double.MAX_VALUE
is returned in maximization problems.public DoubleMatrixND getPrimalSolution(String decisionVariable)
decisionVariable
- The name of the decision variablepublic DoubleMatrixND getSlackOfConstraint(String constraintIdentifier)
constraintIdentifier
- Id of the constrainpublic boolean isInputParameter(String name)
name
- Name of the input parameterpublic boolean isIntegerProblem()
public boolean isLinearProblem()
public boolean isToMinimize()
public Expression parseExpression(String expression)
expression
- The string expression.public void resetTimer()
public void setInitialSolution(String decisionVariableName, double initialValue)
decisionVariableName
- Name of the decision variableinitialValue
- Initial solution. All the scalar decision variables in the array of decision variables have this same initial value.public void setInitialSolution(String decisionVariableName, DoubleMatrixND initialValue)
decisionVariableName
- Name of the decision variableinitialValue
- Initial solution. Array of the same size as the decision variablepublic void setInputParameter(String name, double value)
name
- Name of the input parameter as it appears in the expressions.value
- The scalar value of the input parameter, converted to an N-DIM array object of size (1,1)public void setInputParameter(String name, double[] values, String rowColumnVector)
name
- Name of the input parameter as it appears in the expressions.values
- The 1D array of values of the input parameter, converted to an N-DIM array object of size (1,values.length)rowColumnVector
- "row" for a row vector, "column" for a column vectorpublic void setInputParameter(String name, cern.colt.matrix.tdouble.DoubleMatrix1D values, String rowColumnVector)
name
- Name of the input parameter as it appears in the expressions.values
- The 1D array of values of the input parameter, converted to an N-DIM array object of size (1,values.length)rowColumnVector
- "row" for a row vector, "column" for a column vectorpublic void setInputParameter(String name, Collection<? extends Number> values, String rowColumnVector)
name
- Name of the input parameter as it appears in the expressions.values
- A collection with values of type Number (e.g. Double, Integer, Long...) of the input parameterrowColumnVector
- "row" for a row vector, "column" for a column vectorpublic void setInputParameter(String name, double[][] values)
name
- Name of the input parameter as it appears in the expressions.values
- The 2D array of values of the input parameter, converted to an N-DIM array object of the same sizepublic void setInputParameter(String name, DoubleMatrixND array)
name
- Name of the input parameter as it appears in the expressions.array
- The array of values of the input parameterpublic void setInputParameter(String name, cern.colt.matrix.tdouble.DoubleMatrix2D array)
name
- Name of the input parameter as it appears in the expressions.array
- The array of values of the input parameterpublic void setInputParameter(String name, int value)
name
- Name of the input parameter as it appears in the expressions.value
- The scalar value of the input parameter, casted to double, and converted to an N-DIM array object of size (1,1)public void setInputParameter(String name, int[] values, String rowColumnVector)
name
- Name of the input parameter as it appears in the expressions.values
- The 1D array of values of the input parameter, casted to double, and converted to an N-DIM array object of size (1,values
.length)rowColumnVector
- "row" for a row vector, "column" for a column vectorpublic void setInputParameter(String name, String expression)
name
- Name of the input parameter as it appears in the expressions.expression
- array The expression is evaluated using a common parseExpression. If it is not constant, an Exception is raised.public Expression setObjectiveFunction(String minMax, String expression)
minMax
- "Minimize" if the target is to minimize this expression, "Maximize" if the target is to maximize this expressionexpression
- The string expression of the objective function, that should successfully parsed as an scalar expression of the decision
variables and input parameters of the problempublic boolean solutionIsFeasible()
public boolean solutionIsOptimal()
public void solve(String solverName, Object... paramValuePairs)
solverName
- The name of the solver to be used. Current supported solvers are GLPK (solverName "glpk") and CPLEX (solverName "cplex")
for mixed integer linear problems
and IPOPT (solverName "ipopt") for non-linear non-integer problems.paramValuePairs
- Parameters to be passed to the solver to tune its operation. An even number of Object objects is
to be passed. For each object pair, first Object must be a String with the name of the parameter, second a general Object with its value.
If no name-value pairs are set, solver default values are used. For the "solverLibraryName" parameter, passing a value equal to an empty
string ""
is equivalent to not passing this parameter.
See the documentation for further information.public String timeReport()
Copyright © 2016. All rights reserved.