17 public static void main(String argv[]){
18 System.loadLibrary(
"conoptjni4");
23 qp1_TutModelData
model =
new qp1_TutModelData();
33 int license_int_1 = Integer.parseInt(System.getenv(
"CONOPT_LICENSE_INT_1"));
34 int license_int_2 = Integer.parseInt(System.getenv(
"CONOPT_LICENSE_INT_2"));
35 int license_int_3 = Integer.parseInt(System.getenv(
"CONOPT_LICENSE_INT_3"));
36 String
license_text = System.getenv(
"CONOPT_LICENSE_TEXT");
40 }
catch (Exception e) {
41 System.out.println(
"Unable to set license: " + e.getMessage());
50 conopt.objectiveValue(), 59978.0, 0.001);
61 private double[] target;
62 private double[] Qdiag;
63 private double[] Qlowerdiag;
65 public qp1_TutModelData() {
71 private void setConstants() {
74 target =
new double[NN];
75 Qdiag =
new double[NN];
76 Qlowerdiag =
new double[NN];
77 for (
int i = 0; i < NN; i++)
83 for (
int i = 0; i < NN - 1; i++)
94 for (
int i = 0; i < NN; i++)
99 int[] varindex =
new int[NN];
100 int[] zeros =
new int[NN];
101 int[] ones =
new int[NN];
102 for (
int i = 0; i < NN; i++)
111 Arrays.stream(zeros).asDoubleStream().toArray(), ones);
115 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]);
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 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.
void buildModel()
adds variables and constraints to the model
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
double evaluateNonlinearTerm(double[] x, int rowno, boolean ignerr, int thread)
callback method for evaluating the nonlinear terms in a given row