|
4 | 4 |
|
5 | 5 | using Highs; |
6 | 6 |
|
7 | | -class Program { |
8 | | - static void Main(string[] args) { |
9 | | - // Illustrate the solution of a QP, after first solving just the LP |
10 | | - // |
11 | | - // minimize x_2 + (1/2)(2x_1^2 - 2x_1x_3 + 0.2x_2^2 + 2x_3^2) |
12 | | - // |
13 | | - // subject to x_1 + x_2 + x_3 >= 1; x>=0 |
14 | | - double[] cc = {0, 1, 0}; |
15 | | - double[] cl = {0, 0, 0}; |
16 | | - double[] cu = {1.0e30, 1.0e30, 1.0e30}; |
17 | | - double[] rl = {1}; |
18 | | - double[] ru = {1.0e30}; |
19 | | - int[] astart = {0, 3}; |
20 | | - int[] aindex = {0, 1, 2}; |
21 | | - double[] avalue = {1, 1, 1}; |
22 | | - HighsObjectiveSense sense = HighsObjectiveSense.kMinimize; |
23 | | - double offset = 0; |
24 | | - HighsMatrixFormat a_format = HighsMatrixFormat.kRowwise; |
25 | | - |
26 | | - HighsModel model = new HighsModel(cc, cl, cu, rl, ru, astart, aindex, avalue, null, offset, a_format, sense); |
| 7 | +class Program |
| 8 | +{ |
| 9 | + static void Main(string[] args) |
| 10 | + { |
| 11 | + string model_name = "egout"; |
27 | 12 |
|
28 | 13 | HighsLpSolver solver = new HighsLpSolver(); |
29 | 14 |
|
30 | | - HighsStatus status = solver.passLp(model); |
| 15 | + HighsStatus status = solver.readModel( |
| 16 | + "C:\\Users\\galab\\code\\HiGHS\\check\\instances\\" + |
| 17 | + model_name + ".mps"); |
| 18 | + Console.WriteLine("Read status: " + status); |
| 19 | + |
31 | 20 | status = solver.run(); |
32 | | - HighsSolution sol = solver.getSolution(); |
33 | | - HighsBasis bas = solver.getBasis(); |
34 | 21 | HighsModelStatus modelStatus = solver.GetModelStatus(); |
35 | | - |
36 | | - Console.WriteLine("Status: " + status); |
37 | | - Console.WriteLine("Modelstatus: " + modelStatus); |
38 | | - |
39 | | - for (int i=0; i<sol.colvalue.Length; i++) { |
40 | | - Console.WriteLine("Activity for col " + i + " = " + sol.colvalue[i]); |
41 | | - } |
42 | | - for (int i=0; i<sol.rowvalue.Length; i++) { |
43 | | - Console.WriteLine("Activity for row " + i + " = " + sol.rowvalue[i]); |
44 | | - } |
45 | | - for (int i=0; i<sol.coldual.Length; i++) { |
46 | | - Console.WriteLine("Reduced cost x[" + i + "] = " + sol.coldual[i]); |
47 | | - } |
48 | | - for (int i=0; i<sol.rowdual.Length; i++) { |
49 | | - Console.WriteLine("Dual value for row " + i + " = " + sol.rowdual[i]); |
50 | | - } |
51 | | - for (int i=0; i<sol.colvalue.Length; i++) { |
52 | | - Console.WriteLine("x" + i + " = " + sol.colvalue[i] + " is " + bas.colbasisstatus[i]); |
53 | | - } |
54 | | - // Add the Hessian |
55 | | - int dim = 2; |
56 | | - int[] qstart = {0, 2, 3}; |
57 | | - int[] qindex = {0, 1, 1}; |
58 | | - double[] qvalue = {2, -1, 2}; |
59 | | - HessianFormat q_format = HessianFormat.kTriangular; |
60 | | - HighsHessian hessian = new HighsHessian(dim, qstart, qindex, qvalue, q_format); |
61 | | - status = solver.passHessian(hessian); |
62 | | - status = solver.run(); |
63 | | - sol = solver.getSolution(); |
64 | | - modelStatus = solver.GetModelStatus(); |
65 | | - |
| 22 | + double objective = solver.getObjectiveValue(); |
| 23 | + |
66 | 24 | Console.WriteLine("Status: " + status); |
67 | 25 | Console.WriteLine("Modelstatus: " + modelStatus); |
68 | | - |
69 | | - for (int i=0; i<sol.colvalue.Length; i++) { |
70 | | - Console.WriteLine("Activity for col " + i + " = " + sol.colvalue[i]); |
71 | | - } |
72 | | - for (int i=0; i<sol.rowvalue.Length; i++) { |
73 | | - Console.WriteLine("Activity for row " + i + " = " + sol.rowvalue[i]); |
74 | | - } |
75 | | - for (int i=0; i<sol.coldual.Length; i++) { |
76 | | - Console.WriteLine("Reduced cost x[" + i + "] = " + sol.coldual[i]); |
77 | | - } |
78 | | - for (int i=0; i<sol.rowdual.Length; i++) { |
79 | | - Console.WriteLine("Dual value for row " + i + " = " + sol.rowdual[i]); |
80 | | - } |
81 | | - |
| 26 | + Console.WriteLine("Objective: " + modelStatus); |
| 27 | + |
82 | 28 | } |
83 | 29 | } |
0 commit comments