15 public static void main(String argv[]) {
16 System.loadLibrary(
"conoptjni4");
18 String
name =
"tutorial2r";
21 Tut2rModelData
model =
new Tut2rModelData();
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);
73 public Tut2rModelData() {
79 private void setConstants() {
105 Al * Math.pow(initL, -Rho) + Ak * Math.pow(K, -Rho) + Ainp * Math.pow(initInp, -Rho));
110 int[] index = {varl, varinp, varout, varp};
111 double[] value = {-1, -1, 0, 0};
112 int[] nlflag = {0, 0, 1, 1};
119 int[] index = {varl, varinp, varint};
120 double[] value = {0, 0, -1};
121 int[] nlflag = {1, 1, 0};
127 int[] index = {varout, varp};
128 double[] value = {1, 2};
129 int[] nlflag = {0, 0};
135 int[] index = {varout, varint};
136 double[] value = {-1, 0};
137 int[] nlflag = {0, 1};
148 int[] rownum = {0, 1, 3, 4};
149 int[] colnum = {0, 1, 2, 4};
159 double Inp = x[varinp];
160 double Out = x[varout];
162 double Int = x[varint];
165 if (rowno == consobj) {
168 else if (rowno == consprod) {
169 g = (Al * Math.pow(
L, (-Rho)) + Ak * Math.pow(K, (-Rho)) + Ainp * Math.pow(
Inp, (-Rho)));
171 else if (rowno == consnew) {
172 g = Math.pow(Int, (-1.0 / Rho));
184 assert x.length == jac.length;
187 double Inp = x[varinp];
188 double Out = x[varout];
190 double Int = x[varint];
192 if (rowno == consobj) {
196 else if (rowno == consprod) {
197 jac[varl] = Al * (-Rho) * Math.pow(
L, (-Rho - 1.));
198 jac[varinp] = Ainp * (-Rho) * Math.pow(
Inp, (-Rho - 1.));
200 else if (rowno == consnew) {
201 jac[varint] = (-1.0 / Rho) * Math.pow(Int, (-1.0 / Rho - 1.0));
209 public void evaluateSDLagrangian(
double x[],
double u[],
int[] hessianrow,
int[] hessiancol,
double[] hessianval) {
214 hessianval[2] = u[consobj];
215 if ( u[consprod] != 0.0 ) {
219 hessianval[0] = (-Rho) * (-Rho - 1.0) * Al * Math.pow(
L, -Rho - 2.0) * u[consprod];
220 hessianval[1] = (-Rho) * (-Rho - 1.0) * Ainp * Math.pow(
Inp, -Rho - 2.0) * u[consprod];
222 if (u[consnew] != 0.0)
223 hessianval[3] = (-1.0 / Rho) * (-1.0 / Rho - 1.0) * Math.pow(x[varint], -1.0 / Rho - 2.0);
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