15 public static void main(String argv[]) {
16 System.loadLibrary(
"conoptjni4");
18 String
name =
"tutorial2";
21 Tut2ModelData
model =
new Tut2ModelData();
31 int license_int_1 = Integer.parseInt(System.getenv(
"CONOPT_LICENSE_INT_1"));
32 int license_int_2 = Integer.parseInt(System.getenv(
"CONOPT_LICENSE_INT_2"));
33 int license_int_3 = Integer.parseInt(System.getenv(
"CONOPT_LICENSE_INT_3"));
34 String
license_text = System.getenv(
"CONOPT_LICENSE_TEXT");
38 }
catch (Exception e) {
39 System.out.println(
"Unable to set license: " + e.getMessage());
48 conopt.objectiveValue(), 0.572943, 0.000001);
71 public Tut2ModelData() {
77 private void setConstants() {
99 int[] index = {varl, varinp, varout, varp};
100 double[] value = {-1, -1, 0, 0};
101 int[] nlflag = {0, 0, 1, 1};
108 int[] index = {varl, varinp, varout};
109 double[] value = {0, 0, -1};
110 int[] nlflag = {1, 1, 0};
116 int[] index = {varout, varp};
117 double[] value = {1, 2};
118 int[] nlflag = {0, 0};
129 int[] rownum = {0, 1, 1, 3};
130 int[] colnum = {0, 0, 1, 2};
140 double Inp = x[varinp];
141 double Out = x[varout];
145 if (rowno == consobj) {
148 else if (rowno == consprod) {
149 double hold1 = (Al*Math.pow(
L,(-Rho)) + Ak*Math.pow(K,(-Rho)) + Ainp*Math.pow(
Inp,(-Rho)));
164 assert x.length == jac.length;
167 double Inp = x[varinp];
168 double Out = x[varout];
171 if (rowno == consobj) {
175 else if (rowno == consprod) {
176 double hold1 = (Al*Math.pow(
L,(-Rho)) + Ak*Math.pow(K,(-Rho)) + Ainp*Math.pow(
Inp,(-Rho)));
180 jac[varl] =
hold3 * Al * Math.pow(
L ,(-Rho-1.));
181 jac[varinp] =
hold3 * Ainp * Math.pow(
Inp,(-Rho-1.));
189 public void evaluateSDLagrangian(
double x[],
double u[],
int[] hessianrow,
int[] hessiancol,
double[] hessianval) {
198 hessianval[3] = u[consobj];
199 if ( u[consprod] != 0.0 ) {
204 hold1 = (Al * Math.pow(
L, -Rho) + Ak * Math.pow(K, -Rho) + Ainp * Math.pow(
Inp, -Rho));
222 hessianval[0] = hold4 * (-Rho) * Math.pow(Al * Math.pow(
L, -Rho - 1.0), 2) +
223 hold3 * Al * (-Rho - 1.0) * Math.pow(
L, -Rho - 2.0);
224 hessianval[1] = hold4 * (-Rho) * (Al * Math.pow(
L, -Rho - 1.0)) *
225 (Ainp * Math.pow(
Inp, -Rho - 1.0));
226 hessianval[2] = hold4 * (-Rho) * Math.pow(Ainp * Math.pow(
Inp, -Rho - 1.0), 2) +
227 hold3 * Ainp * (-Rho - 1.0) * Math.pow(
Inp, -Rho - 2.0);
231 for (
int i = 0; i < 3; i++)
232 hessianval[i] = hessianval[i] * u[consprod];
static final ConstraintType Eq
static final ConstraintType Free
A class that can be extended to build and solve a model using Conopt.
static final ObjectiveElement Constraint
static final Sense Maximize
static int checkSolve(String name, int model_status, int solution_status, double objective, double expected_objective, double tol)
static void main(String argv[])
addConstraint(self, *args)
Overload 1: adds a constraint to the problem.
setObjectiveElement(self, elem, elemindex)
sets the index for the objective variable or constraint
addVariable(self, *args)
Overload 1: adds a variable to the model.
setOptimizationSense(self, sense)
sets the optimisation direction.
setSDLagrangianStructure(self, rownum, colnum)
sets the structure of the second derivatives of the Lagrangian
void buildModel()
adds variables and constraints to the model
double evaluateNonlinearTerm(double[] x, int rowno, boolean ignerr, int thread)
callback method for evaluating the nonlinear terms in a given row
void evaluateSDLagrangian(double x[], double u[], int[] hessianrow, int[] hessiancol, double[] hessianval)
Computes and returns the numerical values of the Lagrangian of the Hessian.
void evaluateNonlinearJacobian(double[] x, double[] jac, int rowno, int[] jacnum, boolean ignerr, int thread)
callback method for evaluating the jacobian for the nonlinear terms in a given row