Ipopt 3.12.10

- Main Page
- Classes
- Files

- File List
- File Members

All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros
Ipopt.java
Go to the documentation of this file.
1
9 package org.coinor;
10
11 import java.io.File;
12
47 public abstract class Ipopt
48 {
50 private native boolean AddIpoptIntOption(long ipopt, String keyword, int val);
51
53 private native boolean AddIpoptNumOption(long ipopt, String keyword, double val);
54
56 private native boolean AddIpoptStrOption(long ipopt, String keyword, String val);
57
59 private native long CreateIpoptProblem(int n,int m,
60 int nele_jac, int nele_hess, int index_style);
61
63 private native void FreeIpoptProblem(long ipopt);
64
66 private native int OptimizeTNLP(long ipopt,
67 double x[], double g[],
68 double obj_val[], double mult_g[], double mult_x_L[], double mult_x_U[],
69 double callback_grad_f[], double callback_jac_g[], double callback_hess[]);
70
71
73 public static final String DLLNAME = "jipopt";
75 public static final String DLLPATH = "lib";
76
78 public final static int C_STYLE = 0;
80 public final static int FORTRAN_STYLE = 1;
81
83 public final static int SOLVE_SUCCEEDED = 0;
84 public final static int ACCEPTABLE_LEVEL = 1;
85 public final static int INFEASIBLE_PROBLEM = 2;
86 public final static int SEARCH_DIRECTION_TOO_SMALL = 3;
87 public final static int DIVERGING_ITERATES = 4;
88 public final static int USER_REQUESTED_STOP = 5;
89 public final static int ITERATION_EXCEEDED = -1;
90 public final static int RESTORATION_FAILED = -2;
91 public final static int ERROR_IN_STEP_COMPUTATION = -3;
92 public final static int CPUTIME_EXCEEDED = -4;
93 public final static int NOT_ENOUGH_DEGREES_OF_FRE = -10;
94 public final static int INVALID_PROBLEM_DEFINITION = -11;
95 public final static int INVALID_OPTION = -12;
96 public final static int INVALID_NUMBER_DETECTED = -13;
97 public final static int UNRECOVERABLE_EXCEPTION = -100;
98 public final static int NON_IPOPT_EXCEPTION = -101;
99 public final static int INSUFFICIENT_MEMORY = -102;
100 public final static int INTERNAL_ERROR = -199;
101
103 private long ipopt;
104
106 private double callback_grad_f[];
107 private double callback_jac_g[];
108 private double callback_hess[];
109
111 private double x[];
112
114 private double obj_val[] = {0.0};
115
117 private double g[];
118
120 private double mult_x_L[];
121
123 private double mult_x_U[];
124
126 private double mult_g[];
127
129 private int status = INVALID_PROBLEM_DEFINITION;
130
135 public Ipopt()
136 {
137 this(DLLPATH, DLLNAME);
138 }
139
148 public Ipopt(String path, String DLL)
149 {
150 // Loads the library
151 File file = new File(path, System.mapLibraryName(DLL));
152 System.load(file.getAbsolutePath());
153 }
154
156 abstract protected boolean get_bounds_info(int n, double[] x_l, double[] x_u,
157 int m, double[] g_l, double[] g_u);
158
160 abstract protected boolean get_starting_point(int n, boolean init_x, double[] x,
161 boolean init_z, double[] z_L, double[] z_U,
162 int m, boolean init_lambda, double[] lambda);
163
165 abstract protected boolean eval_f(int n, double[] x, boolean new_x, double[] obj_value);
166
168 abstract protected boolean eval_grad_f(int n, double[] x, boolean new_x, double[] grad_f);
169
171 abstract protected boolean eval_g(int n, double[] x, boolean new_x, int m, double[] g);
172
174 abstract protected boolean eval_jac_g(int n, double[] x, boolean new_x,
175 int m, int nele_jac, int[] iRow, int[] jCol, double[] values);
176
178 abstract protected boolean eval_h(int n, double[] x, boolean new_x, double obj_factor,
179 int m, double[] lambda, boolean new_lambda,
180 int nele_hess, int[] iRow, int[] jCol,
181 double[] values);
182
192 public void dispose()
193 {
194 // dispose the native implementation
195 if( ipopt != 0 )
196 {
197 FreeIpoptProblem(ipopt);
198 ipopt = 0;
199 }
200 }
201
202 protected void finalize() throws Throwable
203 {
204 dispose();
205 }
206
217 public boolean create(int n, int m, int nele_jac, int nele_hess, int index_style)
218 {
219 // delete any previously created native memory
220 dispose();
221
222 x = new double[n];
223 // allocate the callback arguments
224 callback_grad_f = new double[n];
225 callback_jac_g = new double[nele_jac];
226 callback_hess = new double[nele_hess];
227
228 // the multiplier
229 mult_x_U = new double[n];
230 mult_x_L = new double[n];
231 g = new double[m];
232 mult_g = new double[m];
233
234 // Create the optimization problem and return a pointer to it
235 ipopt = CreateIpoptProblem(n, m, nele_jac, nele_hess, index_style);
236
237 //System.out.println("Finish Java Obj");
238 return ipopt == 0 ? false : true;
239 }
240
249 public boolean setIntegerOption(String keyword, int val)
250 {
251 return ipopt == 0 ? false : AddIpoptIntOption(ipopt, keyword, val);
252 }
253
262 public boolean setNumericOption(String keyword, double val)
263 {
264 return ipopt == 0 ? false : AddIpoptNumOption(ipopt, keyword, val);
265 }
266
275 public boolean setStringOption(String keyword, String val)
276 {
277 return ipopt == 0 ? false : AddIpoptStrOption(ipopt, keyword, val.toLowerCase());
278 }
279
290 public int OptimizeNLP()
291 {
292 this.status = this.OptimizeTNLP(ipopt,
293 x, g, obj_val, mult_g, mult_x_L, mult_x_U,
294 callback_grad_f, callback_jac_g, callback_hess);
295
296 return this.status;
297 }
298
302 public double[] getVariableValues()
303 {
304 return x;
305 }
306
310 public double getObjectiveValue()
311 {
312 return obj_val[0];
313 }
314
320 public int getStatus()
321 {
322 return status;
323 }
324
328 public double[] getConstraintValues()
329 {
330 return g;
331 }
332
336 public double[] getConstraintMultipliers()
337 {
338 return mult_g;
339 }
340
344 public double[] getLowerBoundMultipliers()
345 {
346 return mult_x_L;
347 }
348
352 public double[] getUpperBoundMultipliers()
353 {
354 return mult_x_U;
355 }
356
371 public boolean get_scaling_parameters(double[] obj_scaling,
372 int n, double[] x_scaling,
373 int m, double[] g_scaling,
374 boolean[] use_x_g_scaling)
375 {
376 return false;
377 }
378
383 public int get_number_of_nonlinear_variables()
384 {
385 return -1;
386 }
387
395 public boolean get_list_of_nonlinear_variables(int num_nonlin_vars,
396 int[] pos_nonlin_vars)
397 {
398 return false;
399 }
400 }
org.coinor.Ipopt.Ipopt
Ipopt()
Creates a new NLP Solver using { DLLPATH} as path and { DLLNAME} as the DLL name. ...
Definition: Ipopt.java:135
org.coinor.Ipopt.callback_jac_g
double callback_jac_g[]
Definition: Ipopt.java:107
org.coinor.Ipopt.FreeIpoptProblem
native void FreeIpoptProblem(long ipopt)
Native function should not be used directly.
org.coinor.Ipopt.get_bounds_info
abstract boolean get_bounds_info(int n, double[] x_l, double[] x_u, int m, double[] g_l, double[] g_u)
Callback function for the variable bounds and constraint sides.
org.coinor.Ipopt.mult_x_L
double mult_x_L[]
Final multipliers for lower variable bounds.
Definition: Ipopt.java:120
org.coinor.Ipopt.INSUFFICIENT_MEMORY
static final int INSUFFICIENT_MEMORY
Definition: Ipopt.java:99
index_style
Number Number Index Number Number Index Index Index index_style
indexing style for iRow &amp; jCol, 0 for C style, 1 for Fortran style
Definition: IpStdCInterface.h:137
org.coinor.Ipopt.DIVERGING_ITERATES
static final int DIVERGING_ITERATES
Definition: Ipopt.java:87
m
Number Number Index m
Number of constraints.
Definition: IpStdCInterface.h:137
org.coinor.Ipopt.get_number_of_nonlinear_variables
int get_number_of_nonlinear_variables()
When LBFGS hessian approximation is used, this method should be overloaded.
Definition: Ipopt.java:383
org.coinor.Ipopt.NOT_ENOUGH_DEGREES_OF_FRE
static final int NOT_ENOUGH_DEGREES_OF_FRE
Definition: Ipopt.java:93
org.coinor.Ipopt.OptimizeTNLP
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[])
Native function should not be used directly.
org.coinor.Ipopt.getUpperBoundMultipliers
double[] getUpperBoundMultipliers()
Gives dual multipliers for variable upper bounds in final point.
Definition: Ipopt.java:352
org.coinor.Ipopt.USER_REQUESTED_STOP
static final int USER_REQUESTED_STOP
Definition: Ipopt.java:88
org.coinor.Ipopt.getObjectiveValue
double getObjectiveValue()
Gives objective function value at final point.
Definition: Ipopt.java:310
org.coinor.Ipopt.INVALID_OPTION
static final int INVALID_OPTION
Definition: Ipopt.java:95
org.coinor.Ipopt.INTERNAL_ERROR
static final int INTERNAL_ERROR
Definition: Ipopt.java:100
org.coinor.Ipopt.ITERATION_EXCEEDED
static final int ITERATION_EXCEEDED
Definition: Ipopt.java:89
org.coinor.Ipopt.status
int status
Status returned by the solver.
Definition: Ipopt.java:129
org.coinor.Ipopt.INFEASIBLE_PROBLEM
static final int INFEASIBLE_PROBLEM
Definition: Ipopt.java:85
org.coinor.Ipopt.FORTRAN_STYLE
static final int FORTRAN_STYLE
Use FORTRAN index style for iRow and jCol vectors.
Definition: Ipopt.java:80
org.coinor.Ipopt.get_starting_point
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)
Callback function for retrieving a starting point.
org.coinor.Ipopt.DLLNAME
static final String DLLNAME
The default DLL name of the native implementation (without any platform dependent prefixes or suffixe...
Definition: Ipopt.java:73
org.coinor.Ipopt.UNRECOVERABLE_EXCEPTION
static final int UNRECOVERABLE_EXCEPTION
Definition: Ipopt.java:97
org.coinor.Ipopt.mult_x_U
double mult_x_U[]
Final multipliers for upper variable bounds.
Definition: Ipopt.java:123
val
char char * val
Definition: IpStdCInterface.h:189
keyword
char * keyword
Definition: IpStdCInterface.h:189
org.coinor.Ipopt.CreateIpoptProblem
native long CreateIpoptProblem(int n, int m, int nele_jac, int nele_hess, int index_style)
Native function should not be used directly.
org.coinor.Ipopt.getLowerBoundMultipliers
double[] getLowerBoundMultipliers()
Gives dual multipliers for variable lower bounds in final point.
Definition: Ipopt.java:344
org.coinor.Ipopt.getConstraintValues
double[] getConstraintValues()
Gives constraint function values at final point.
Definition: Ipopt.java:328
org.coinor.Ipopt.obj_val
double obj_val[]
Final value of objective function.
Definition: Ipopt.java:114
org.coinor.Ipopt.RESTORATION_FAILED
static final int RESTORATION_FAILED
Definition: Ipopt.java:90
org.coinor.Ipopt.finalize
void finalize()
Definition: Ipopt.java:202
org.coinor.Ipopt.setIntegerOption
boolean setIntegerOption(String keyword, int val)
Function for setting an integer option.
Definition: Ipopt.java:249
org.coinor.Ipopt.setStringOption
boolean setStringOption(String keyword, String val)
Function for setting a string option.
Definition: Ipopt.java:275
org.coinor.Ipopt.CPUTIME_EXCEEDED
static final int CPUTIME_EXCEEDED
Definition: Ipopt.java:92
org.coinor.Ipopt.setNumericOption
boolean setNumericOption(String keyword, double val)
Function for setting a number option.
Definition: Ipopt.java:262
nele_jac
Number Number Index Number Number Index nele_jac
Number of non-zero elements in constraint Jacobian.
Definition: IpStdCInterface.h:137
org.coinor.Ipopt.eval_g
abstract boolean eval_g(int n, double[] x, boolean new_x, int m, double[] g)
Callback function for the constraints.
org.coinor.Ipopt.create
boolean create(int n, int m, int nele_jac, int nele_hess, int index_style)
Create a new problem.
Definition: Ipopt.java:217
org.coinor.Ipopt.NON_IPOPT_EXCEPTION
static final int NON_IPOPT_EXCEPTION
Definition: Ipopt.java:98
org.coinor.Ipopt.ERROR_IN_STEP_COMPUTATION
static final int ERROR_IN_STEP_COMPUTATION
Definition: Ipopt.java:91
org.coinor.Ipopt.AddIpoptStrOption
native boolean AddIpoptStrOption(long ipopt, String keyword, String val)
Native function should not be used directly.
org.coinor.Ipopt.Ipopt
Ipopt(String path, String DLL)
Creates a NLP Solver for the given DLL file.
Definition: Ipopt.java:148
org.coinor.Ipopt.callback_grad_f
double callback_grad_f[]
Callback arguments.
Definition: Ipopt.java:106
org.coinor.Ipopt.AddIpoptIntOption
native boolean AddIpoptIntOption(long ipopt, String keyword, int val)
Native function should not be used directly.
org.coinor.Ipopt.SEARCH_DIRECTION_TOO_SMALL
static final int SEARCH_DIRECTION_TOO_SMALL
Definition: Ipopt.java:86
org.coinor.Ipopt.eval_jac_g
abstract boolean eval_jac_g(int n, double[] x, boolean new_x, int m, int nele_jac, int[] iRow, int[] jCol, double[] values)
Callback function for the constraints Jacobian.
org.coinor.Ipopt.x
double x[]
Final value of variable values.
Definition: Ipopt.java:111
x_scaling
Number Number * x_scaling
Definition: IpStdCInterface.h:210
org.coinor.Ipopt.INVALID_NUMBER_DETECTED
static final int INVALID_NUMBER_DETECTED
Definition: Ipopt.java:96
org.coinor.Ipopt.get_scaling_parameters
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, please overload this method,.
Definition: Ipopt.java:371
org.coinor.Ipopt.eval_h
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)
Callback function for the hessian.
org.coinor.Ipopt.g
double g[]
Values of constraint at final point.
Definition: Ipopt.java:117
nele_hess
Number Number Index Number Number Index Index nele_hess
Number of non-zero elements in Hessian of Lagrangian.
Definition: IpStdCInterface.h:137
org.coinor.Ipopt.OptimizeNLP
int OptimizeNLP()
This function actually solve the problem.
Definition: Ipopt.java:290
org.coinor.Ipopt.getVariableValues
double[] getVariableValues()
Gives primal variable values at final point.
Definition: Ipopt.java:302
org.coinor.Ipopt.DLLPATH
static final String DLLPATH
The relative path where the native DLL is found.
Definition: Ipopt.java:75
org.coinor.Ipopt.ipopt
long ipopt
Pointer to the native optimization object.
Definition: Ipopt.java:103
g_scaling
Number Number Number * g_scaling
Definition: IpStdCInterface.h:210
org.coinor.Ipopt.getConstraintMultipliers
double[] getConstraintMultipliers()
Gives constraint dual multipliers in final point.
Definition: Ipopt.java:336
org.coinor.Ipopt.ACCEPTABLE_LEVEL
static final int ACCEPTABLE_LEVEL
Definition: Ipopt.java:84
org.coinor.Ipopt.eval_grad_f
abstract boolean eval_grad_f(int n, double[] x, boolean new_x, double[] grad_f)
Callback function for the objective function gradient.
org.coinor.Ipopt.mult_g
double mult_g[]
Final multipliers for constraints.
Definition: Ipopt.java:126
org.coinor.Ipopt.getStatus
int getStatus()
Gives Ipopt status of last OptimizeNLP call.
Definition: Ipopt.java:320
org.coinor.Ipopt.get_list_of_nonlinear_variables
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.
Definition: Ipopt.java:395
org.coinor.Ipopt.C_STYLE
static final int C_STYLE
Use C index style for iRow and jCol vectors.
Definition: Ipopt.java:78
org.coinor.Ipopt.AddIpoptNumOption
native boolean AddIpoptNumOption(long ipopt, String keyword, double val)
Native function should not be used directly.
org.coinor.Ipopt.dispose
void dispose()
Dispose of the natively allocated memory.
Definition: Ipopt.java:192
org.coinor.Ipopt
A Java Native Interface for the Ipopt optimization solver.
Definition: Ipopt.java:47
obj_scaling
Number obj_scaling
Definition: IpStdCInterface.h:210
org.coinor.Ipopt.eval_f
abstract boolean eval_f(int n, double[] x, boolean new_x, double[] obj_value)
Callback function for the objective function.
org.coinor.Ipopt.callback_hess
double callback_hess[]
Definition: Ipopt.java:108
org.coinor.Ipopt.SOLVE_SUCCEEDED
static final int SOLVE_SUCCEEDED
The possible Ipopt status return codes: should be kept in sync with Ipopt return codes.
Definition: Ipopt.java:83
org.coinor.Ipopt.INVALID_PROBLEM_DEFINITION
static final int INVALID_PROBLEM_DEFINITION
Definition: Ipopt.java:94