CONOPT
Loading...
Searching...
No Matches
largeres2.java
Go to the documentation of this file.
1
7
8import java.util.*;
9import java.lang.Math;
10import conopt.*;
11
14public class largeres2 {
15 public static void main(String argv[]) {
16 System.loadLibrary("conoptjni4");
17
18 String name = "largeres2";
19
20 Conopt conopt = new Conopt(name);
21 LrgRes2ModelData model = new LrgRes2ModelData();
23
24
25 // adding the message handler to the conopt interface
26 conopt.setMessageHandler(msghdlr);
27
28 // building the model
29 model.buildModel();
30
31 // loading the model in the conopt object
32 conopt.loadModel(model);
33
34 // Disable debug output for function values
35 conopt.debugFV(0);
36
37 // try to set the license using the environment variables
38 try {
39 int license_int_1 = Integer.parseInt(System.getenv("CONOPT_LICENSE_INT_1"));
40 int license_int_2 = Integer.parseInt(System.getenv("CONOPT_LICENSE_INT_2"));
41 int license_int_3 = Integer.parseInt(System.getenv("CONOPT_LICENSE_INT_3"));
42 String license_text = System.getenv("CONOPT_LICENSE_TEXT");
43
46 } catch (Exception e) {
47 System.out.println("Unable to set license: " + e.getMessage());
48 }
49
50 int coi_error = conopt.solve();
51 std s = new std();
52 int retcode = 0;
53
54 if (coi_error != 400) {
55 s.java_log(name, "Expected return code 400, Saw " + coi_error);
56 retcode = -1;
57 }
58 else {
59 s.java_log(name, "Successful Solve");
60 conopt.printStatus();
61 }
62
63 msghdlr.close();
64 System.exit(retcode);
65 }
66}
67
68class LrgRes2ModelData extends ModelData {
69 private int varidx;
70 private int considx;
71
72 public LrgRes2ModelData() {
73 super();
74 }
75
76
81 public void buildModel() {
82 // adding the variables to the model
83 varidx = addVariable(-Conopt.Infinity, Conopt.Infinity, 100.0);
84
85 // adding the constraints to the model
86 // Constraint 1
87 {
88 int[] index = {varidx};
89 double[] value = {0};
90 int[] nlflag = {1};
91
92 considx = addConstraint(ConstraintType.Eq, 10, index, value, nlflag);
93 }
94
95 // setting the objective constraint
97
98 // setting the optimisation direction
100 }
101
106 public double evaluateNonlinearTerm(double[] x, int rowno, boolean ignerr, int thread) {
107 double g = 0;
108
109 if (rowno == considx) {
110 g = Math.exp(x[varidx]);
111 }
112
113 return g;
114 }
115
120 public void evaluateNonlinearJacobian(double[] x, double[] jac, int rowno, int[] jacnum, boolean ignerr, int thread) {
121 assert x.length == jac.length;
122
123 if (rowno == considx) {
124 jac[varidx] = Math.exp(x[varidx]);
125 }
126 }
127}
The Conopt class.
Definition conopt.py:1380
static final ConstraintType Eq
A class that can be extended to build and solve a model using Conopt.
Definition conopt.py:2407
static final ObjectiveElement Variable
static final Sense Maximize
Definition Sense.java:29
static void main(String argv[])
static void java_log(final String name, final String message)
Definition std.java:10
addConstraint(self, *args)
Overload 1: adds a constraint to the problem.
Definition conopt.py:2621
setObjectiveElement(self, elem, elemindex)
sets the index for the objective variable or constraint
Definition conopt.py:2766
addVariable(self, *args)
Overload 1: adds a variable to the model.
Definition conopt.py:2677
setOptimizationSense(self, sense)
sets the optimisation direction.
Definition conopt.py:2775
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 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
Definition std.py:1