15 public static void main(String argv[]){
16 System.loadLibrary(
"conoptjni4");
21 qp2_TutModelData
model =
new qp2_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 qp2_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);
133 for (
int i = 0; i < NN; i++)
134 g += (x[i] - target[i])*Qdiag[i]*(x[i] - target[i]);
135 for (
int i = 0; i < NN - 1; i++)
136 g += 2*(x[i + 1] - target[i + 1])*Qlowerdiag[i]*(x[i] - target[i]);
147 assert x.length == jac.length;
151 for (
int i = 0; i < NN; i++)
152 jac[i] += Qdiag[i]*(x[i] - target[i]);
154 for (
int i = 0; i < NN - 1; i++)
156 jac[i + 1] += Qlowerdiag[i]*(x[i] - target[i]);
157 jac[i] += Qlowerdiag[i]*(x[i + 1] - target[i + 1]);
168 assert x.length == d2g.length;
169 assert dx.length == d2g.length;
171 for (
int i = 0; i < NN; i++)
172 d2g[i] = Qdiag[i]*dx[i];
174 for (
int i = 0; i < NN - 1; i++)
176 d2g[i + 1] += Qlowerdiag[i]*dx[i];
177 d2g[i] += Qlowerdiag[i]*dx[i + 1];
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
double evaluateNonlinearTerm(double[] x, int rowno, boolean ignerr, int thread)
callback method for evaluating the nonlinear terms in a given row
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 buildModel()
adds variables and constraints to the model
void evaluateDirectionalSD(double[] x, double[] dx, double[] d2g, int rowno, int[] jacnum, int thread)
computes the directional second derivative for a single constraint