9 package org.coinor.examples;
10 import org.coinor.Ipopt;
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)
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)
290 System.out.println(
"\n\n*** The problem solved!");
292 System.out.println(
"\n\n*** The problem was not solved successfully!");
295 System.out.println(
"\nObjective Value = " + obj +
"\n");
298 hs071.
print(
x,
"Primal Variable Values:");
301 hs071.
print(constraints,
"Constraint Values:");
304 hs071.
print(MLB,
"Dual Multipliers for Variable Lower Bounds:");
307 hs071.
print(MUB,
"Dual Multipliers for Variable Upper Bounds:");
310 hs071.
print(lam,
"Dual Multipliers for Constraints:");
Number Number Index Number Number Index Index nele_hess
Number of non-zero elements in Hessian of Lagrangian.
Number Number Index Number * g_L
Lower bounds on constraints.
Number Number Index Number Number Index nele_jac
Number of non-zero elements in constraint Jacobian.
Number Number * x_scaling
Number Number Index Number Number * g_U
Upper bounds on constraints.
Number Number Number * g_scaling
Number Number Index m
Number of constraints.
Number * x_L
Lower bounds on variables.
Number Number * x_U
Upper bounds on variables.
Number Number Index Number Number Index Index Index index_style
indexing style for iRow & jCol, 0 for C style, 1 for Fortran style
double[] getVariableValues()
Gives primal variable values at final point.
static final int SOLVE_SUCCEEDED
The possible Ipopt status return codes: should be kept in sync with Ipopt return codes.
double[] getConstraintMultipliers()
Gives constraint dual multipliers in final point.
double g[]
Values of constraint at final point.
double x[]
Final value of variable values.
int status
Status returned by the solver.
double[] getConstraintValues()
Gives constraint function values at final point.
double getObjectiveValue()
Gives objective function value at final point.
double[] getUpperBoundMultipliers()
Gives dual multipliers for variable upper bounds in final point.
boolean create(int n, int m, int nele_jac, int nele_hess, int index_style)
Create a new problem.
double[] getLowerBoundMultipliers()
Gives dual multipliers for variable lower bounds in final point.
int OptimizeNLP()
This function actually solve the problem.
Java example for interfacing with IPOPT.
boolean eval_grad_f(int n, double[] x, boolean new_x, double[] grad_f)
Callback function for the objective function gradient.
boolean eval_f(int n, double[] x, boolean new_x, double[] obj_value)
Callback function for the objective function.
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.
HS071()
Creates a new instance of HS071cpp.
void print(double[] x, String str)
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_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.
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,.
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.
static void main(String[]args)
Main function for running this example.