Ipopt  3.12.11
 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 
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,
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 
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 }
Ipopt()
Creates a new NLP Solver using { DLLPATH} as path and { DLLNAME} as the DLL name. ...
Definition: Ipopt.java:135
double callback_jac_g[]
Definition: Ipopt.java:107
native void FreeIpoptProblem(long ipopt)
Native function should not be used directly.
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.
double mult_x_L[]
Final multipliers for lower variable bounds.
Definition: Ipopt.java:120
static final int INSUFFICIENT_MEMORY
Definition: Ipopt.java:99
Number Number Index Number Number Index Index Index index_style
indexing style for iRow & jCol, 0 for C style, 1 for Fortran style
static final int DIVERGING_ITERATES
Definition: Ipopt.java:87
Number Number Index m
Number of constraints.
int get_number_of_nonlinear_variables()
When LBFGS hessian approximation is used, this method should be overloaded.
Definition: Ipopt.java:383
static final int NOT_ENOUGH_DEGREES_OF_FRE
Definition: Ipopt.java:93
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.
double[] getUpperBoundMultipliers()
Gives dual multipliers for variable upper bounds in final point.
Definition: Ipopt.java:352
static final int USER_REQUESTED_STOP
Definition: Ipopt.java:88
double getObjectiveValue()
Gives objective function value at final point.
Definition: Ipopt.java:310
static final int INVALID_OPTION
Definition: Ipopt.java:95
static final int INTERNAL_ERROR
Definition: Ipopt.java:100
static final int ITERATION_EXCEEDED
Definition: Ipopt.java:89
int status
Status returned by the solver.
Definition: Ipopt.java:129
static final int INFEASIBLE_PROBLEM
Definition: Ipopt.java:85
static final int FORTRAN_STYLE
Use FORTRAN index style for iRow and jCol vectors.
Definition: Ipopt.java:80
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.
static final String DLLNAME
The default DLL name of the native implementation (without any platform dependent prefixes or suffixe...
Definition: Ipopt.java:73
static final int UNRECOVERABLE_EXCEPTION
Definition: Ipopt.java:97
double mult_x_U[]
Final multipliers for upper variable bounds.
Definition: Ipopt.java:123
char char * val
char * keyword
native long CreateIpoptProblem(int n, int m, int nele_jac, int nele_hess, int index_style)
Native function should not be used directly.
double[] getLowerBoundMultipliers()
Gives dual multipliers for variable lower bounds in final point.
Definition: Ipopt.java:344
double[] getConstraintValues()
Gives constraint function values at final point.
Definition: Ipopt.java:328
double obj_val[]
Final value of objective function.
Definition: Ipopt.java:114
static final int RESTORATION_FAILED
Definition: Ipopt.java:90
void finalize()
Definition: Ipopt.java:202
boolean setIntegerOption(String keyword, int val)
Function for setting an integer option.
Definition: Ipopt.java:249
boolean setStringOption(String keyword, String val)
Function for setting a string option.
Definition: Ipopt.java:275
static final int CPUTIME_EXCEEDED
Definition: Ipopt.java:92
boolean setNumericOption(String keyword, double val)
Function for setting a number option.
Definition: Ipopt.java:262
Number Number Index Number Number Index nele_jac
Number of non-zero elements in constraint Jacobian.
abstract boolean eval_g(int n, double[] x, boolean new_x, int m, double[] g)
Callback function for the constraints.
boolean create(int n, int m, int nele_jac, int nele_hess, int index_style)
Create a new problem.
Definition: Ipopt.java:217
static final int NON_IPOPT_EXCEPTION
Definition: Ipopt.java:98
static final int ERROR_IN_STEP_COMPUTATION
Definition: Ipopt.java:91
native boolean AddIpoptStrOption(long ipopt, String keyword, String val)
Native function should not be used directly.
Ipopt(String path, String DLL)
Creates a NLP Solver for the given DLL file.
Definition: Ipopt.java:148
double callback_grad_f[]
Callback arguments.
Definition: Ipopt.java:106
native boolean AddIpoptIntOption(long ipopt, String keyword, int val)
Native function should not be used directly.
static final int SEARCH_DIRECTION_TOO_SMALL
Definition: Ipopt.java:86
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.
double x[]
Final value of variable values.
Definition: Ipopt.java:111
Number Number * x_scaling
static final int INVALID_NUMBER_DETECTED
Definition: Ipopt.java:96
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
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.
double g[]
Values of constraint at final point.
Definition: Ipopt.java:117
Number Number Index Number Number Index Index nele_hess
Number of non-zero elements in Hessian of Lagrangian.
int OptimizeNLP()
This function actually solve the problem.
Definition: Ipopt.java:290
double[] getVariableValues()
Gives primal variable values at final point.
Definition: Ipopt.java:302
static final String DLLPATH
The relative path where the native DLL is found.
Definition: Ipopt.java:75
long ipopt
Pointer to the native optimization object.
Definition: Ipopt.java:103
Number Number Number * g_scaling
double[] getConstraintMultipliers()
Gives constraint dual multipliers in final point.
Definition: Ipopt.java:336
static final int ACCEPTABLE_LEVEL
Definition: Ipopt.java:84
abstract boolean eval_grad_f(int n, double[] x, boolean new_x, double[] grad_f)
Callback function for the objective function gradient.
double mult_g[]
Final multipliers for constraints.
Definition: Ipopt.java:126
int getStatus()
Gives Ipopt status of last OptimizeNLP call.
Definition: Ipopt.java:320
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
static final int C_STYLE
Use C index style for iRow and jCol vectors.
Definition: Ipopt.java:78
native boolean AddIpoptNumOption(long ipopt, String keyword, double val)
Native function should not be used directly.
void dispose()
Dispose of the natively allocated memory.
Definition: Ipopt.java:192
A Java Native Interface for the Ipopt optimization solver.
Definition: Ipopt.java:47
Number obj_scaling
abstract boolean eval_f(int n, double[] x, boolean new_x, double[] obj_value)
Callback function for the objective function.
double callback_hess[]
Definition: Ipopt.java:108
static final int SOLVE_SUCCEEDED
The possible Ipopt status return codes: should be kept in sync with Ipopt return codes.
Definition: Ipopt.java:83
static final int INVALID_PROBLEM_DEFINITION
Definition: Ipopt.java:94