Skip to content

Commit

Permalink
Added dim to HessianFormat and started adding Hessian to call_highs_f…
Browse files Browse the repository at this point in the history
…rom_csharp.cs
  • Loading branch information
jajhall committed Aug 28, 2024
1 parent 74682bc commit af09d2d
Show file tree
Hide file tree
Showing 2 changed files with 25 additions and 2 deletions.
11 changes: 10 additions & 1 deletion examples/call_highs_from_csharp.cs
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@

class Program {
static void Main(string[] args) {
// Test with an LP
double[] cc = {1, -2};
double[] cl = {0, 0};
double[] cu = {10, 10};
Expand Down Expand Up @@ -43,5 +44,13 @@ static void Main(string[] args) {
for (int i=0; i<sol.colvalue.Length; i++) {
Console.WriteLine("x" + i + " = " + sol.colvalue[i] + " is " + bas.colbasisstatus[i]);
}
// Add a Hessian
int dim = 2;
int[] qstart = {0, 2};
int[] qindex = {0, 1, 1};
double[] qvalue = {2, -1, 2};
HessianFormat q_format = HessianFormat.kTriangular;


}
}
}
16 changes: 15 additions & 1 deletion src/interfaces/highs_csharp_api.cs
Original file line number Diff line number Diff line change
Expand Up @@ -113,6 +113,7 @@ public HighsModel(double[] colcost, double[] collower, double[] colupper, double
public class HighsHessian
{
public HessianFormat q_format;
public int dim;
public int[] qstart;
public int[] qindex;
public double[] qvalue;
Expand All @@ -122,8 +123,9 @@ public HighsHessian()

}

public HighsHessian(int[] qstart, int[] qindex, double[] qvalue, HessianFormat q_format = HessianFormat.kTriangular)
public HighsHessian(int dim, int[] qstart, int[] qindex, double[] qvalue, HessianFormat q_format = HessianFormat.kTriangular)
{
this.dim = dim;
this.qstart = qstart;
this.qindex = qindex;
this.qvalue = qvalue;
Expand Down Expand Up @@ -721,6 +723,18 @@ public HighsStatus passMip(HighsModel model)
model.highs_integrality);
}

public HighsStatus passHessian(HighsHessian hessian)
{
return (HighsStatus)HighsLpSolver.Highs_passHessian(
this.highs,
hessian.dim,
hessian.qvalue.Length,
(int)hessian.q_format,
hessian.qstart,
hessian.qindex,
hessian.qvalue);
}

public HighsStatus setOptionValue(string option, string value)
{
return (HighsStatus)HighsLpSolver.Highs_setOptionValue(this.highs, option, value);
Expand Down

0 comments on commit af09d2d

Please sign in to comment.