15 public static void main(String argv[]){
16 System.loadLibrary(
"conoptjni4");
21 qp4_TutModelData
model =
new qp4_TutModelData();
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(), 59978.0, 0.001);
59 private double[] target;
60 private double[] Qdiag;
61 private double[] Qlowerdiag;
63 public qp4_TutModelData() {
69 private void setConstants() {
72 target =
new double[NN];
73 Qdiag =
new double[NN];
74 Qlowerdiag =
new double[NN];
75 for (
int i = 0; i < NN; i++)
81 for (
int i = 0; i < NN - 1; i++)
91 for (
int i = 0; i < NN; i++)
96 int[] varindex =
new int[NN];
97 int[] zeros =
new int[NN];
98 int[] ones =
new int[NN];
99 for (
int i = 0; i < NN; i++)
108 Arrays.stream(zeros).asDoubleStream().toArray(), ones);
112 Arrays.stream(ones).asDoubleStream().toArray(), zeros);
124 setLagrangianStructure();
127 private void setLagrangianStructure() {
128 int[] hessianrow =
new int[
NQ];
129 int[] hessiancol =
new int[
NQ];
132 for (
int i = 0; i <
NN - 1; i++)
135 hessianrow[2*i + 1] = i + 1;
138 hessiancol[2*i + 1] = i;
140 hessianrow[NQ - 1] = NN - 1;
141 hessiancol[NQ - 1] = NN - 1;
156 for (
int i = 0; i < NN; i++)
157 g += (x[i] - target[i])*Qdiag[i]*(x[i] - target[i]);
158 for (
int i = 0; i < NN - 1; i++)
159 g += 2*(x[i + 1] - target[i + 1])*Qlowerdiag[i]*(x[i] - target[i]);
170 assert x.length == jac.length;
174 for (
int i = 0; i < NN; i++)
175 jac[i] += Qdiag[i]*(x[i] - target[i]);
177 for (
int i = 0; i < NN - 1; i++)
179 jac[i + 1] += Qlowerdiag[i]*(x[i] - target[i]);
180 jac[i] += Qlowerdiag[i]*(x[i + 1] - target[i + 1]);
191 assert x.length == d2g.length;
192 assert dx.length == d2g.length;
194 for (
int i = 0; i < NN; i++)
195 d2g[i] = Qdiag[i]*dx[i];
197 for (
int i = 0; i < NN - 1; i++)
199 d2g[i + 1] += Qlowerdiag[i]*dx[i];
200 d2g[i] += Qlowerdiag[i]*dx[i + 1];
209 public void evaluateSDLagrangian(
double[] x,
double[] u,
int[] hessianrow,
int[] hessiancol,
double[] hessianval) {
210 assert hessianrow.length == hessianval.length;
211 assert hessiancol.length == hessianval.length;
213 for (
int i = 0; i < NN - 1; i++)
215 hessianval[2*i] = Qdiag[i]*u[0];
216 hessianval[2*i + 1] = Qlowerdiag[i]*u[0];
218 hessianval[NQ - 1] = Qdiag[NN - 1]*u[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 SDEvaluationType Constraint
static final Sense Minimize
static void main(String argv[])
static int checkSolve(String name, int model_status, int solution_status, double objective, double expected_objective, double tol)
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.
setSDEvaluationType(self, sdevaltype)
informs CONOPT of the method for evaluating the second derivative
setSDLagrangianStructure(self, rownum, colnum)
sets the structure of the second derivatives of the Lagrangian
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
void evaluateDirectionalSD(double[] x, double[] dx, double[] d2g, int rowno, int[] jacnum, int thread)
computes the directional second derivative for a single constraint
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