Skip to content

Commit 87b08e8

Browse files
Fix the QP example in call_highs_from_csharp.cs.
The code was creating a Hessian matrix that did not match the expression given in the comments. The comment says the QP is minimize x_2 + (1/2)(2x_1^2 - 2x_1x_3 + 0.2x_2^2 + 2x_3^2) so the Hessian matrix is [ 2 0 -1] [ 0 0.2 0] [-1 0 2] To create this Hessian, the code that creates the Hessian matrix is changed from int dim = 2; int[] qstart = {0, 2, 3}; int[] qindex = {0, 1, 1}; double[] qvalue = {2, -1, 2}; (which would correspond to the 2x2 matrix Q = [[2, -1], [0, 2]]) to int dim = 3; int[] qstart = {0, 2, 3, 4}; int[] qindex = {0, 1, 1, 2}; double[] qvalue = {2, -1, 0.2, 2};
1 parent 26b632a commit 87b08e8

File tree

1 file changed

+5
-5
lines changed

1 file changed

+5
-5
lines changed

examples/call_highs_from_csharp.cs

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@ static void Main(string[] args) {
1111
// minimize x_2 + (1/2)(2x_1^2 - 2x_1x_3 + 0.2x_2^2 + 2x_3^2)
1212
//
1313
// subject to x_1 + x_2 + x_3 >= 1; x>=0
14-
double[] cc = {0, 1, 0};
14+
double[] cc = {0, 1, 0};
1515
double[] cl = {0, 0, 0};
1616
double[] cu = {1.0e30, 1.0e30, 1.0e30};
1717
double[] rl = {1};
@@ -52,10 +52,10 @@ static void Main(string[] args) {
5252
Console.WriteLine("x" + i + " = " + sol.colvalue[i] + " is " + bas.colbasisstatus[i]);
5353
}
5454
// 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};
55+
int dim = 3;
56+
int[] qstart = {0, 2, 3, 4};
57+
int[] qindex = {0, 1, 1, 2};
58+
double[] qvalue = {2, -1, 0.2, 2};
5959
HessianFormat q_format = HessianFormat.kTriangular;
6060
HighsHessian hessian = new HighsHessian(dim, qstart, qindex, qvalue, q_format);
6161
status = solver.passHessian(hessian);

0 commit comments

Comments
 (0)