A Java Native Interface for the Ipopt optimization solver. More...
Public Member Functions | |
Ipopt () | |
Creates a new NLP Solver using a default as the DLL name. More... | |
Ipopt (String DLL) | |
Creates a NLP Solver for the given DLL file. More... | |
Ipopt (String path, String DLL) | |
Creates a NLP Solver for the given DLL file and path. More... | |
void | dispose () |
Dispose of the natively allocated memory. More... | |
boolean | create (int n, int m, int nele_jac, int nele_hess, int index_style) |
Create a new problem. More... | |
boolean | setIntegerOption (String keyword, int val) |
Function for setting an integer option. More... | |
boolean | setNumericOption (String keyword, double val) |
Function for setting a number option. More... | |
boolean | setStringOption (String keyword, String val) |
Function for setting a string option. More... | |
int | OptimizeNLP () |
This function actually solve the problem. More... | |
double[] | getVariableValues () |
Gives primal variable values at final point. More... | |
double | getObjectiveValue () |
Gives objective function value at final point. More... | |
int | getStatus () |
Gives Ipopt status of last OptimizeNLP call. More... | |
double[] | getConstraintValues () |
Gives constraint function values at final point. More... | |
double[] | getConstraintMultipliers () |
Gives constraint dual multipliers in final point. More... | |
double[] | getLowerBoundMultipliers () |
Gives dual multipliers for variable lower bounds in final point. More... | |
double[] | getUpperBoundMultipliers () |
Gives dual multipliers for variable upper bounds in final point. More... | |
boolean | get_scaling_parameters (double[] obj_scaling, int n, double[] x_scaling, int m, double[] g_scaling, boolean[] use_x_g_scaling) |
If you using_scaling_parameters = true, this method should be overloaded. More... | |
int | get_number_of_nonlinear_variables () |
When LBFGS hessian approximation is used, this method should be overloaded. More... | |
boolean | get_list_of_nonlinear_variables (int num_nonlin_vars, int[] pos_nonlin_vars) |
When LBFGS hessian approximation is used, this method should be overloaded. More... | |
Static Public Attributes | |
static final int | C_STYLE = 0 |
Use C index style for iRow and jCol vectors. More... | |
static final int | FORTRAN_STYLE = 1 |
Use FORTRAN index style for iRow and jCol vectors. More... | |
static final int | SOLVE_SUCCEEDED = 0 |
The possible Ipopt status return codes: should be kept in sync with Ipopt return codes. More... | |
static final int | ACCEPTABLE_LEVEL = 1 |
static final int | INFEASIBLE_PROBLEM = 2 |
static final int | SEARCH_DIRECTION_TOO_SMALL = 3 |
static final int | DIVERGING_ITERATES = 4 |
static final int | USER_REQUESTED_STOP = 5 |
static final int | ITERATION_EXCEEDED = -1 |
static final int | RESTORATION_FAILED = -2 |
static final int | ERROR_IN_STEP_COMPUTATION = -3 |
static final int | CPUTIME_EXCEEDED = -4 |
static final int | NOT_ENOUGH_DEGREES_OF_FRE = -10 |
static final int | INVALID_PROBLEM_DEFINITION = -11 |
static final int | INVALID_OPTION = -12 |
static final int | INVALID_NUMBER_DETECTED = -13 |
static final int | UNRECOVERABLE_EXCEPTION = -100 |
static final int | NON_IPOPT_EXCEPTION = -101 |
static final int | INSUFFICIENT_MEMORY = -102 |
static final int | INTERNAL_ERROR = -199 |
Protected Member Functions | |
abstract boolean | get_bounds_info (int n, double[] x_l, double[] x_u, int m, double[] g_l, double[] g_u) |
Method to request bounds on the variables and constraints. More... | |
abstract boolean | get_starting_point (int n, boolean init_x, double[] x, boolean init_z, double[] z_L, double[] z_U, int m, boolean init_lambda, double[] lambda) |
Method to request the starting point before iterating. More... | |
abstract boolean | eval_f (int n, double[] x, boolean new_x, double[] obj_value) |
Method to request the value of the objective function. More... | |
abstract boolean | eval_grad_f (int n, double[] x, boolean new_x, double[] grad_f) |
Method to request the gradient of the objective function. More... | |
abstract boolean | eval_g (int n, double[] x, boolean new_x, int m, double[] g) |
Method to request the constraint values. More... | |
abstract boolean | eval_jac_g (int n, double[] x, boolean new_x, int m, int nele_jac, int[] iRow, int[] jCol, double[] values) |
Method to request either the sparsity structure or the values of the Jacobian of the constraints. More... | |
abstract boolean | eval_h (int n, double[] x, boolean new_x, double obj_factor, int m, double[] lambda, boolean new_lambda, int nele_hess, int[] iRow, int[] jCol, double[] values) |
Method to request either the sparsity structure or the values of the Hessian of the Lagrangian. More... | |
void | finalize () throws Throwable |
Private Member Functions | |
native boolean | AddIpoptIntOption (long ipopt, String keyword, int val) |
native boolean | AddIpoptNumOption (long ipopt, String keyword, double val) |
native boolean | AddIpoptStrOption (long ipopt, String keyword, String val) |
native long | CreateIpoptProblem (int n, int m, int nele_jac, int nele_hess, int index_style) |
native void | FreeIpoptProblem (long ipopt) |
native int | OptimizeTNLP (long ipopt, double x[], double g[], double obj_val[], double mult_g[], double mult_x_L[], double mult_x_U[], double callback_grad_f[], double callback_jac_g[], double callback_hess[]) |
Private Attributes | |
long | ipopt |
Pointer to the native optimization object. More... | |
double | callback_grad_f [] |
Callback arguments. More... | |
double | callback_jac_g [] |
double | callback_hess [] |
double | x [] |
Final value of variable values. More... | |
double | obj_val [] = {0.0} |
Final value of objective function. More... | |
double | g [] |
Values of constraint at final point. More... | |
double | mult_x_L [] |
Final multipliers for lower variable bounds. More... | |
double | mult_x_U [] |
Final multipliers for upper variable bounds. More... | |
double | mult_g [] |
Final multipliers for constraints. More... | |
int | status = INVALID_PROBLEM_DEFINITION |
Status returned by the solver. More... | |
A Java Native Interface for the Ipopt optimization solver.
Ipopt is a solver for large scale nonlinear optimization problems (NLP).
The Java Native Interface (JNI) is a programming framework that allows Java code running in the Java Virtual Machine (JVM) to call and be called by native applications (programs specific to a hardware and operating system platform) and libraries written in other languages, such as C and C++.
This class is a JNI hook around the C++ interface of Ipopt, as a consequence it will need a nativelly compiled DLL to run. For more details about Ipopt click here.
The user should subclass this class and implement the abstract methods. At some point before solving the problem the create(int, int, int, int, int) function should be called. For simple cases you can call this function in the constructor of your class.
Once the problem was created, OptimizeNLP() will solve the problem. Objects of this class can be reused to solve different problems, in other words, create(int, int, int, int, int) and OptimizeNLP() can be called multiple times.
Programmers must call dispose() when finished using a Ipopt object, otherwise the nativelly allocated memory will be disposed of only when the JVM call finalize() on it.
Definition at line 44 of file Ipopt.java.
|
inline |
Creates a new NLP Solver using a default as the DLL name.
This expects the the Ipopt DLL can somehow be found and that it has the canoncial name "ipopt" (on Unix, et.al.) or "ipopt-3" or "ipopt-0" (on Windows).
Definition at line 158 of file Ipopt.java.
|
inline |
Creates a NLP Solver for the given DLL file.
The given file must implement the native interface required by this class. The given file must be located in some library search path.
DLL | the name of the DLL (without the extension or any platform dependent prefix). |
Definition at line 199 of file Ipopt.java.
|
inline |
Creates a NLP Solver for the given DLL file and path.
The given file must implement the native interface required by this class.
path | the path where the DLL is found. |
DLL | the name of the DLL (without the extension or any platform dependent prefix). |
Definition at line 214 of file Ipopt.java.
|
private |
|
private |
|
private |
|
private |
|
private |
|
private |
|
protectedpure virtual |
Method to request bounds on the variables and constraints.
The values of n and m that were specified in create() and are passed here for debug checking. Setting a lower bound to a value less than or equal to the value of the option "nlp_lower_bound_inf" will cause Ipopt to assume no lower bound. Likewise, specifying the upper bound above or equal to the value of the option nlp_upper_bound_inf will cause Ipopt to assume no upper bound. These options are set to -1019 and 1019, respectively, by default, but may be modified by changing these options.
n | (in) the number of variablesin the problem |
x_l | (out) the lower bounds for the variables |
x_u | (out) the upper bounds for the variables |
m | (in) the number of constraints in the problem |
g_l | (out) the lower bounds for the constraints |
g_u | (out) the upper bounds for the constraints |
|
protectedpure virtual |
Method to request the starting point before iterating.
The boolean variables indicate whether the algorithm requires to have x, z_L/z_u, and lambda initialized, respectively. If, for some reason, the algorithm requires initializations that cannot be provided, false should be returned and Ipopt will stop. The default options only require initial values for the primal variables.
Note, that the initial values for bound multiplier components for absent bounds are ignored.
n | (in) the number of variables in the problem; it will have the same value that was specified in create() |
init_x | (in) if true, this method must provide an initial value for the primal variables |
x | (out) the initial values for the primal variables |
init_z | (in) if true, this method must provide an initial value for the bound multipliers |
z_L | (out) the initial values for the lower bound multipliers |
z_U | (out) the initial values for the upper bound multipliers |
m | (in) the number of constraints in the problem; it will have the same value that was specified in create() |
init_lambda | (in) if true, this method must provide an initial value for the constraint multipliers |
lambda | (out) the initial values for the constraint multipliers |
|
protectedpure virtual |
Method to request the value of the objective function.
n | (in) the number of variables in the problem; it will have the same value that was specified in create() |
x | (in) the values for the primal variables at which the objective function is to be evaluated |
new_x | (in) false if any evaluation method (eval_* ) was previously called with the same values in x, true otherwise. This can be helpful when users have efficient implementations that calculate multiple outputs at once. Ipopt internally caches results from the TNLP and generally, this flag can be ignored. |
obj_value | (out) storage for the value of the objective function |
|
protectedpure virtual |
Method to request the gradient of the objective function.
n | (in) the number of variables in the problem; it will have the same value that was specified in create() |
x | (in) the values for the primal variables at which the gradient is to be evaluated |
new_x | (in) false if any evaluation method (eval_* ) was previously called with the same values in x, true otherwise; see also eval_f() |
grad_f | (out) array to store values of the gradient of the objective function. The gradient array is in the same order as the variables (i.e., the gradient of the objective with respect to x[2] should be put in grad_f[2] ). |
|
protectedpure virtual |
Method to request the constraint values.
n | (in) the number of variables in the problem; it will have the same value that was specified in create() |
x | (in) the values for the primal variables at which the constraint functions are to be evaluated |
new_x | (in) false if any evaluation method (eval_* ) was previously called with the same values in x, true otherwise; see also eval_f() |
m | (in) the number of constraints in the problem; it will have the same value that was specified in create() |
g | (out) array to store constraint function values, do not add or subtract the bound values. |
|
protectedpure virtual |
Method to request either the sparsity structure or the values of the Jacobian of the constraints.
The Jacobian is the matrix of derivatives where the derivative of the i-th constraint function with respect to the j-th variable is placed in row i and column j.
The arrays iRow and jCol only need to be filled once. If the iRow and jCol arguments are not NULL (first call to this function), then Ipopt expects that the sparsity structure of the Jacobian (the row and column indices only) are written into iRow and jCol. At this call, the arguments x and values will be NULL. If the arguments x and values are not NULL, then Ipopt expects that the value of the Jacobian as calculated from array x is stored in array values (using the same order as used when specifying the sparsity structure). At this call, the arguments iRow and jCol will be NULL.
n | (in) the number of variables in the problem; it will have the same value that was specified in create() |
x | (in) first call: NULL; later calls: the values for the primal variables at which the constraint Jacobian is to be evaluated |
new_x | (in) false if any evaluation method (eval_* ) was previously called with the same values in x, true otherwise; see also eval_f() |
m | (in) the number of constraints in the problem; it will have the same value that was specified in create() |
nele_jac | (in) the number of nonzero elements in the Jacobian; it will have the same value that was specified in create() |
iRow | (out) first call: array of length nele_jac to store the row indices of entries in the Jacobian of the constraints; later calls: NULL |
jCol | (out) first call: array of length nele_jac to store the column indices of entries in the Jacobian of the constraints; later calls: NULL |
values | (out) first call: NULL; later calls: array of length nele_jac to store the values of the entries in the Jacobian of the constraints |
|
protectedpure virtual |
Method to request either the sparsity structure or the values of the Hessian of the Lagrangian.
The Hessian matrix that Ipopt uses is the sum of the Hessian matrices of objective function (multiplied by obj_factor) and each constraint function (multiplied by lambda).
The arrays iRow and jCol only need to be filled once. If the iRow and jCol arguments are not NULL (first call to this function), then Ipopt expects that the sparsity structure of the Hessian (the row and column indices only) are written into iRow and jCol. At this call, the arguments x, lambda, and values will be NULL. If the arguments x, lambda, and values are not NULL, then Ipopt expects that the value of the Hessian as calculated from arrays x and lambda are stored in array values (using the same order as used when specifying the sparsity structure). At this call, the arguments iRow and jCol will be NULL.
As this matrix is symmetric, Ipopt expects that only the lower diagonal entries are specified.
n | (in) the number of variables in the problem; it will have the same value that was specified in create() |
x | (in) first call: NULL; later calls: the values for the primal variables at which the Hessian is to be evaluated |
new_x | (in) false if any evaluation method (eval_* ) was previously called with the same values in x, true otherwise; see also eval_f() |
obj_factor | (in) factor in front of the objective term in the Hessian |
m | (in) the number of constraints in the problem; it will have the same value that was specified in create() |
lambda | (in) the values for the constraint multipliers at which the Hessian is to be evaluated |
new_lambda | (in) false if any evaluation method was previously called with the same values in lambda, true otherwise |
nele_hess | (in) the number of nonzero elements in the Hessian; it will have the same value that was specified in create() |
iRow | (out) first call: array of length nele_hess to store the row indices of entries in the Hessian; later calls: NULL |
jCol | (out) first call: array of length nele_hess to store the column indices of entries in the Hessian; later calls: NULL |
values | (out) first call: NULL; later calls: array of length nele_hess to store the values of the entries in the Hessian |
|
inline |
Dispose of the natively allocated memory.
Programmers must call the dispose method when finished using a Ipopt object.
An JIpopt object can be reused to solve different problems by calling again create(int, int, int, int, int). In this case, you should call the dispose method only when you finished with the object and it is not needed anymore.
Definition at line 439 of file Ipopt.java.
|
inlineprotected |
Definition at line 450 of file Ipopt.java.
|
inline |
Create a new problem.
This is get_nlp_info in the C++ interface.
n | the number of variables in the problem. |
m | the number of constraints in the problem. |
nele_jac | the number of nonzero entries in the Jacobian. |
nele_hess | the number of nonzero entries in the Hessian. |
index_style | the numbering style used for row/col entries in the sparse matrix format (C_STYLE or FORTRAN_STYLE). |
Definition at line 467 of file Ipopt.java.
|
inline |
Function for setting an integer option.
For a list of valid keywords check the Ipopt documentation.
keyword | the option keyword |
val | the value |
Definition at line 505 of file Ipopt.java.
|
inline |
Function for setting a number option.
For a list of valid keywords check the Ipopt documentation.
keyword | the option keyword |
val | the value |
Definition at line 525 of file Ipopt.java.
|
inline |
Function for setting a string option.
For a list of valid keywords check the Ipopt documentation.
keyword | the option keyword |
val | the value |
Definition at line 545 of file Ipopt.java.
|
inline |
This function actually solve the problem.
The solve status returned is one of the constant fields of this class, e.g. SOLVE_SUCCEEDED. For more details about the valid solve status check the Ipopt documentation.
Definition at line 567 of file Ipopt.java.
|
inline |
Gives primal variable values at final point.
Definition at line 579 of file Ipopt.java.
|
inline |
Gives objective function value at final point.
Definition at line 587 of file Ipopt.java.
|
inline |
Gives Ipopt status of last OptimizeNLP call.
Definition at line 597 of file Ipopt.java.
|
inline |
Gives constraint function values at final point.
Definition at line 605 of file Ipopt.java.
|
inline |
Gives constraint dual multipliers in final point.
Definition at line 613 of file Ipopt.java.
|
inline |
Gives dual multipliers for variable lower bounds in final point.
Definition at line 621 of file Ipopt.java.
|
inline |
Gives dual multipliers for variable upper bounds in final point.
Definition at line 629 of file Ipopt.java.
|
inline |
If you using_scaling_parameters = true, this method should be overloaded.
To instruct IPOPT to use scaling values for variables, the first element of use_x_g_scaling should be set. To instruct IPOPT to use scaling values for constraints, the second element of use_x_g_scaling should be set.
obj_scaling | double[1] to store a scaling factor for the objective (negative value leads to maximizing the objective function) |
n | the number of variables in the problem |
x_scaling | array to store the scaling factors for the variables |
m | the number of constraints in the problem |
g_scaling | array to store the scaling factors for the constraints |
use_x_g_scaling | boolean[2] to store whether scaling factors for variables (1st entry) and constraints (2nd entry) should be used |
Definition at line 648 of file Ipopt.java.
|
inline |
When LBFGS hessian approximation is used, this method should be overloaded.
Definition at line 663 of file Ipopt.java.
|
inline |
When LBFGS hessian approximation is used, this method should be overloaded.
num_nonlin_vars | number of nonlinear variables and length of pos_nonlin_vars array |
pos_nonlin_vars | the indices of all nonlinear variables |
Definition at line 675 of file Ipopt.java.
|
static |
Use C index style for iRow and jCol vectors.
Definition at line 96 of file Ipopt.java.
|
static |
Use FORTRAN index style for iRow and jCol vectors.
Definition at line 99 of file Ipopt.java.
|
static |
The possible Ipopt status return codes: should be kept in sync with Ipopt return codes.
Definition at line 102 of file Ipopt.java.
|
static |
Definition at line 103 of file Ipopt.java.
|
static |
Definition at line 104 of file Ipopt.java.
|
static |
Definition at line 105 of file Ipopt.java.
|
static |
Definition at line 106 of file Ipopt.java.
|
static |
Definition at line 107 of file Ipopt.java.
|
static |
Definition at line 108 of file Ipopt.java.
|
static |
Definition at line 109 of file Ipopt.java.
|
static |
Definition at line 110 of file Ipopt.java.
|
static |
Definition at line 111 of file Ipopt.java.
|
static |
Definition at line 112 of file Ipopt.java.
|
static |
Definition at line 113 of file Ipopt.java.
|
static |
Definition at line 114 of file Ipopt.java.
|
static |
Definition at line 115 of file Ipopt.java.
|
static |
Definition at line 116 of file Ipopt.java.
|
static |
Definition at line 117 of file Ipopt.java.
|
static |
Definition at line 118 of file Ipopt.java.
|
static |
Definition at line 119 of file Ipopt.java.
|
private |
Pointer to the native optimization object.
Definition at line 122 of file Ipopt.java.
|
private |
Callback arguments.
Definition at line 125 of file Ipopt.java.
|
private |
Definition at line 126 of file Ipopt.java.
|
private |
Definition at line 127 of file Ipopt.java.
|
private |
Final value of variable values.
Definition at line 130 of file Ipopt.java.
|
private |
Final value of objective function.
Definition at line 133 of file Ipopt.java.
|
private |
Values of constraint at final point.
Definition at line 136 of file Ipopt.java.
|
private |
Final multipliers for lower variable bounds.
Definition at line 139 of file Ipopt.java.
|
private |
Final multipliers for upper variable bounds.
Definition at line 142 of file Ipopt.java.
|
private |
Final multipliers for constraints.
Definition at line 145 of file Ipopt.java.
|
private |
Status returned by the solver.
Definition at line 148 of file Ipopt.java.