Skip to content

Commit 29e1f5c

Browse files
committed
read egout
1 parent 6d84941 commit 29e1f5c

File tree

1 file changed

+14
-68
lines changed

1 file changed

+14
-68
lines changed

examples/call_highs_from_csharp.cs

Lines changed: 14 additions & 68 deletions
Original file line numberDiff line numberDiff line change
@@ -4,80 +4,26 @@
44

55
using Highs;
66

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";
2712

2813
HighsLpSolver solver = new HighsLpSolver();
2914

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+
3120
status = solver.run();
32-
HighsSolution sol = solver.getSolution();
33-
HighsBasis bas = solver.getBasis();
3421
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+
6624
Console.WriteLine("Status: " + status);
6725
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+
8228
}
8329
}

0 commit comments

Comments
 (0)