9 package org.coinor.examples;
55 create(n, m, nele_jac, nele_hess, index_style);
60 int m,
double[]
g_L,
double[]
g_U)
66 for(
int i = 0; i < n; ++i )
73 g_L[0] = 25.0; g_U[0] = 2e19;
74 g_L[1] = 40.0; g_U[1] = 40.0;
81 boolean init_z,
double[] z_L,
double[] z_U,
82 int m,
boolean init_lambda,
double[] lambda)
84 assert init_z ==
false;
85 assert init_lambda =
false;
118 protected boolean eval_f(
int n,
double[]
x,
boolean new_x,
double[] obj_value)
122 obj_value[0] = x[0] * x[3] * (x[0] + x[1] + x[2]) + x[2];
127 protected boolean eval_grad_f(
int n,
double[]
x,
boolean new_x,
double[] grad_f)
131 grad_f[0] = x[0] * x[3] + x[3] * (x[0] + x[1] + x[2]);
132 grad_f[1] = x[0] * x[3];
133 grad_f[2] = x[0] * x[3] + 1;
134 grad_f[3] = x[0] * (x[0] + x[1] + x[2]);
139 protected boolean eval_g(
int n,
double[]
x,
boolean new_x,
int m,
double[]
g)
144 g[0] = x[0] * x[1] * x[2] * x[3];
145 g[1] = x[0]*x[0] + x[1]*x[1] + x[2]*x[2] + x[3]*x[3];
151 int m,
int nele_jac,
int[] iRow,
int[] jCol,
double[] values)
161 iRow[0] = 0; jCol[0] = 0;
162 iRow[1] = 0; jCol[1] = 1;
163 iRow[2] = 0; jCol[2] = 2;
164 iRow[3] = 0; jCol[3] = 3;
165 iRow[4] = 1; jCol[4] = 0;
166 iRow[5] = 1; jCol[5] = 1;
167 iRow[6] = 1; jCol[6] = 2;
168 iRow[7] = 1; jCol[7] = 3;
174 values[0] = x[1]*x[2]*x[3];
175 values[1] = x[0]*x[2]*x[3];
176 values[2] = x[0]*x[1]*x[3];
177 values[3] = x[0]*x[1]*x[2];
188 protected 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)
202 for( row = 0; row < n; ++row )
204 for( col = 0; col <= row; ++col)
212 assert idx == nele_hess;
220 values[0] = obj_factor * (2*x[3]);
221 values[1] = obj_factor * (x[3]);
223 values[3] = obj_factor * (x[3]);
226 values[6] = obj_factor * (2*x[0] + x[1] + x[2]);
227 values[7] = obj_factor * (x[0]);
228 values[8] = obj_factor * (x[0]);
232 values[1] += lambda[0] * (x[2] * x[3]);
233 values[3] += lambda[0] * (x[1] * x[3]);
234 values[4] += lambda[0] * (x[0] * x[3]);
235 values[6] += lambda[0] * (x[1] * x[2]);
236 values[7] += lambda[0] * (x[0] * x[2]);
237 values[8] += lambda[0] * (x[0] * x[1]);
240 values[0] += lambda[1] * 2.0;
241 values[2] += lambda[1] * 2.0;
242 values[5] += lambda[1] * 2.0;
243 values[9] += lambda[1] * 2.0;
252 boolean[] use_x_g_scaling)
258 public void print(
double[]
x, String str)
260 System.out.println(str);
261 for(
int i = 0; i < x.length; ++i )
262 System.out.println(x[i]);
263 System.out.println();
269 public static void main(String []args)
286 int status = hs071.OptimizeNLP();
290 System.out.println(
"\n\n*** The problem solved!");
292 System.out.println(
"\n\n*** The problem was not solved successfully!");
294 double obj = hs071.getObjectiveValue();
295 System.out.println(
"\nObjective Value = " + obj +
"\n");
297 double x[] = hs071.getVariableValues();
298 hs071.print(
x,
"Primal Variable Values:");
300 double constraints[] = hs071.getConstraintValues();
301 hs071.print(constraints,
"Constraint Values:");
303 double MLB[] = hs071.getLowerBoundMultipliers();
304 hs071.print(MLB,
"Dual Multipliers for Variable Lower Bounds:");
306 double MUB[] = hs071.getUpperBoundMultipliers();
307 hs071.print(MUB,
"Dual Multipliers for Variable Upper Bounds:");
309 double lam[] = hs071.getConstraintMultipliers();
310 hs071.print(lam,
"Dual Multipliers for Constraints:");
Java example for interfacing with IPOPT.
Number Number Index Number Number Index Index Index index_style
indexing style for iRow & jCol, 0 for C style, 1 for Fortran style
Number Number Index m
Number of constraints.
boolean eval_g(int n, double[] x, boolean new_x, int m, double[] g)
Callback function for the constraints.
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.
boolean eval_grad_f(int n, double[] x, boolean new_x, double[] grad_f)
Callback function for the objective function gradient.
int status
Status returned by the solver.
void print(double[] x, String str)
boolean eval_f(int n, double[] x, boolean new_x, double[] obj_value)
Callback function for the objective function.
Number Number Index Number Number * g_U
Upper bounds on constraints.
HS071()
Creates a new instance of HS071cpp.
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 the starting point.
boolean create(int n, int m, int nele_jac, int nele_hess, int index_style)
Create a new problem.
Number * x_L
Lower bounds on variables.
double x[]
Final value of variable values.
Number Number Index Number * g_L
Lower bounds on constraints.
Number Number * x_U
Upper bounds on variables.
Number Number * x_scaling
double g[]
Values of constraint at final point.
Number Number Index Number Number Index Index nele_hess
Number of non-zero elements in Hessian of Lagrangian.
Number Number Number * g_scaling
boolean get_scaling_parameters(double[] obj_scaling, int n, double[] x_scaling, int m, double[] g_scaling, boolean[] use_x_g_scaling)
static final int C_STYLE
Use C index style for iRow and jCol vectors.
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.
A Java Native Interface for the Ipopt optimization solver.
static void main(String[]args)
Main function for running this example.
static final int SOLVE_SUCCEEDED
The possible Ipopt status return codes: should be kept in sync with Ipopt return codes.
boolean get_bounds_info(int n, double[] x_L, double[] x_U, int m, double[] g_L, double[] g_U)
Callback function for variable bounds and constraint sides.