1 using System; 2 using System.Linq; 3 using System.Runtime.InteropServices; 4 5 // mcs -out:highscslib.dll -t:library highs_csharp_api.cs -unsafe 6 7 public enum HighsStatus 8 { 9 OK, 10 Warning, 11 Error 12 } 13 14 public enum HighsBasisStatus 15 { 16 Lower, 17 Basic, 18 Upper, 19 Zero, 20 Nonbasic, 21 Super 22 } 23 24 public enum HighsObjectiveSense 25 { 26 Minimize = 1, 27 Maximize = -1 28 } 29 30 public enum HighsModelStatus 31 { 32 NOTSET, 33 LOAD_ERROR, 34 MODEL_ERROR, 35 PRESOLVE_ERROR, 36 SOLVE_ERROR, 37 POSTSOLVE_ERROR, 38 MODEL_EMPTY, 39 PRIMAL_INFEASIBLE, 40 PRIMAL_UNBOUNDED, 41 OPTIMAL, 42 REACHED_DUAL_OBJECTIVE_VALUE_UPPER_BOUND, 43 REACHED_TIME_LIMIT, 44 REACHED_ITERATION_LIMIT 45 } 46 47 public class HighsModel 48 { 49 public double[] colcost; 50 public double[] collower; 51 public double[] colupper; 52 public double[] rowlower; 53 public double[] rowupper; 54 public int[] astart; 55 public int[] aindex; 56 public double[] avalue; 57 HighsModel()58 public HighsModel() 59 { 60 61 } 62 HighsModel(double[] colcost, double[] collower, double[] colupper, double[] rowlower, double[] rowupper, int[] astart, int[] aindex, double[] avalue)63 public HighsModel(double[] colcost, double[] collower, double[] colupper, double[] rowlower, double[] rowupper, 64 int[] astart, int[] aindex, double[] avalue) 65 { 66 this.colcost = colcost; 67 this.collower = collower; 68 this.colupper = colupper; 69 this.rowlower = rowlower; 70 this.rowupper = rowupper; 71 this.astart = astart; 72 this.aindex = aindex; 73 this.avalue = avalue; 74 } 75 } 76 77 public class HighsSolution 78 { 79 public double[] colvalue; 80 public double[] coldual; 81 public double[] rowvalue; 82 public double[] rowdual; 83 HighsSolution(int numcol, int numrow)84 public HighsSolution(int numcol, int numrow) 85 { 86 this.colvalue = new double[numcol]; 87 this.coldual = new double[numcol]; 88 this.rowvalue = new double[numrow]; 89 this.rowdual = new double[numrow]; 90 } 91 HighsSolution(double[] colvalue, double[] coldual, double[] rowvalue, double[] rowdual)92 public HighsSolution(double[] colvalue, double[] coldual, double[] rowvalue, double[] rowdual) 93 { 94 this.colvalue = colvalue; 95 this.coldual = coldual; 96 this.rowvalue = rowvalue; 97 this.rowdual = rowdual; 98 } 99 } 100 101 public class HighsBasis 102 { 103 public HighsBasisStatus[] colbasisstatus; 104 public HighsBasisStatus[] rowbasisstatus; 105 HighsBasis(int numcol, int numrow)106 public HighsBasis(int numcol, int numrow) 107 { 108 this.colbasisstatus = new HighsBasisStatus[numcol]; 109 this.rowbasisstatus = new HighsBasisStatus[numrow]; 110 } 111 HighsBasis(HighsBasisStatus[] colbasisstatus, HighsBasisStatus[] rowbasisstatus)112 public HighsBasis(HighsBasisStatus[] colbasisstatus, HighsBasisStatus[] rowbasisstatus) 113 { 114 this.colbasisstatus = colbasisstatus; 115 this.rowbasisstatus = rowbasisstatus; 116 } 117 } 118 119 public unsafe class HighsLpSolver 120 { 121 private void* highs; 122 123 private const string highslibname = "highs.dll"; 124 125 [DllImport(highslibname)] Highs_call(Int32 numcol, Int32 numrow, Int32 numnz, double[] colcost, double[] collower, double[] colupper, double[] rowlower, double[] rowupper, int[] astart, int[] aindex, double[] avalue, double[] colvalue, double[] coldual, double[] rowvalue, double[] rowdual, int[] colbasisstatus, int[] rowbasisstatus, ref int modelstatus)126 private static extern int Highs_call(Int32 numcol, Int32 numrow, Int32 numnz, double[] colcost, 127 double[] collower, double[] colupper, double[] rowlower, double[] rowupper, int[] astart, int[] aindex, double[] avalue, 128 double[] colvalue, double[] coldual, double[] rowvalue, double[] rowdual, int[] colbasisstatus, int[] rowbasisstatus, ref int modelstatus); 129 130 [DllImport(highslibname)] Highs_create()131 private static extern void* Highs_create(); 132 133 [DllImport(highslibname)] Highs_destroy(void* highs)134 private static extern void Highs_destroy(void* highs); 135 136 [DllImport(highslibname)] Highs_run(void* highs)137 private static extern int Highs_run(void* highs); 138 139 [DllImport(highslibname)] Highs_readModel(void* highs, string filename)140 private static extern int Highs_readModel(void* highs, string filename); 141 142 [DllImport(highslibname)] Highs_writeModel(void* highs, string filename)143 private static extern int Highs_writeModel(void* highs, string filename); 144 145 [DllImport(highslibname)] Highs_passLp(void* highs, int numcol, int numrow, int numnz, double[] colcost, double[] collower, double[] colupper, double[] rowlower, double[] rowupper, int[] astart, int[] aindex, double[] avalue)146 private static extern int Highs_passLp(void* highs, int numcol, int numrow, int numnz, double[] colcost, 147 double[] collower, double[] colupper, double[] rowlower, double[] rowupper, int[] astart, int[] aindex, double[] avalue); 148 149 [DllImport(highslibname)] Highs_setOptionValue(void* highs, string option, string value)150 private static extern int Highs_setOptionValue(void* highs, string option, string value); 151 152 [DllImport(highslibname)] Highs_getSolution(void* highs, double[] colvalue, double[] coldual, double[] rowvalue, double[] rowdual)153 private static extern void Highs_getSolution(void* highs, double[] colvalue, double[] coldual, double[] rowvalue, double[] rowdual); 154 155 [DllImport(highslibname)] Highs_getNumCols(void* highs)156 private static extern int Highs_getNumCols(void* highs); 157 158 [DllImport(highslibname)] Highs_getNumRows(void* highs)159 private static extern int Highs_getNumRows(void* highs); 160 161 [DllImport(highslibname)] Highs_getNumNz(void* highs)162 private static extern int Highs_getNumNz(void* highs); 163 164 [DllImport(highslibname)] Highs_getBasis(void* highs, int[] colstatus, int[] rowstatus)165 private static extern void Highs_getBasis(void* highs, int[] colstatus, int[] rowstatus); 166 167 [DllImport(highslibname)] Highs_getObjectiveValue(void* highs)168 private static extern double Highs_getObjectiveValue(void* highs); 169 170 [DllImport(highslibname)] Highs_getIterationCount(void* highs)171 private static extern int Highs_getIterationCount(void* highs); 172 173 [DllImport(highslibname)] Highs_getModelStatus(void* highs)174 private static extern int Highs_getModelStatus(void* highs); 175 176 [DllImport(highslibname)] Highs_addRow(void* highs, double lower, double upper, int num_new_nz, int[] indices, double[] values)177 private static extern int Highs_addRow(void* highs, double lower, double upper, int num_new_nz, int[] indices, double[] values); 178 179 [DllImport(highslibname)] Highs_addRows(void* highs, int num_new_row, double[] lower, double[] upper, int num_new_nz, int[] starts, int[] indices, double[] values)180 private static extern int Highs_addRows(void* highs, int num_new_row, double[] lower, double[] upper, 181 int num_new_nz, int[] starts, int[] indices, double[] values); 182 183 [DllImport(highslibname)] Highs_addCol(void* highs, double cost, double lower, double upper, int num_new_nz, int[] indices, double[] values)184 private static extern int Highs_addCol(void* highs, double cost, double lower, double upper, 185 int num_new_nz, int[] indices, double[] values); 186 187 [DllImport(highslibname)] Highs_addCols(void* highs, int num_new_col, double[] costs, double[] lower, double[] upper, int num_new_nz, int[] starts, int[] indices, double[] values)188 private static extern int Highs_addCols(void* highs, int num_new_col, double[] costs, double[] lower, double[] upper, 189 int num_new_nz, int[] starts, int[] indices, double[] values); 190 191 [DllImport(highslibname)] Highs_changeObjectiveSense(void* highs, int sense)192 private static extern int Highs_changeObjectiveSense(void* highs, int sense); 193 194 [DllImport(highslibname)] Highs_changeColCost(void* highs, int col, double cost)195 private static extern int Highs_changeColCost(void* highs, int col, double cost); 196 197 [DllImport(highslibname)] Highs_changeColsCostBySet(void* highs, int num_set_entries, int[] set, double[] cost)198 private static extern int Highs_changeColsCostBySet(void* highs, int num_set_entries, int[] set, double[] cost); 199 200 [DllImport(highslibname)] Highs_changeColsCostByMask(void* highs, int[] mask, double[] cost)201 private static extern int Highs_changeColsCostByMask(void* highs, int[] mask, double[] cost); 202 203 [DllImport(highslibname)] Highs_changeColBounds(void* highs, int col, double lower, double upper)204 private static extern int Highs_changeColBounds(void* highs, int col, double lower, double upper); 205 206 [DllImport(highslibname)] Highs_changeColsBoundsByRange(void* highs, int from_col, int to_col, double[] lower, double[] upper)207 private static extern int Highs_changeColsBoundsByRange(void* highs, int from_col, int to_col, double[] lower, double[] upper); 208 209 [DllImport(highslibname)] Highs_changeColsBoundsBySet(void* highs, int num_set_entries, int[] set, double[] lower, double[] upper)210 private static extern int Highs_changeColsBoundsBySet(void* highs, int num_set_entries, int[] set, double[] lower, double[] upper); 211 212 [DllImport(highslibname)] Highs_changeColsBoundsByMask(void* highs, int[] mask, double[] lower, double[] upper)213 private static extern int Highs_changeColsBoundsByMask(void* highs, int[] mask, double[] lower, double[] upper); 214 215 [DllImport(highslibname)] Highs_changeRowBounds(void* highs, int row, double lower, double upper)216 private static extern int Highs_changeRowBounds(void* highs, int row, double lower, double upper); 217 218 [DllImport(highslibname)] Highs_changeRowsBoundsBySet(void* highs, int num_set_entries, int[] set, double[] lower, double[] upper)219 private static extern int Highs_changeRowsBoundsBySet(void* highs, int num_set_entries, int[] set, double[] lower, double[] upper); 220 221 [DllImport(highslibname)] Highs_changeRowsBoundsByMask(void* highs, int[] mask, double[] lower, double[] upper)222 private static extern int Highs_changeRowsBoundsByMask(void* highs, int[] mask, double[] lower, double[] upper); 223 224 [DllImport(highslibname)] Highs_deleteColsByRange(void* highs, int from_col, int to_col)225 private static extern int Highs_deleteColsByRange(void* highs, int from_col, int to_col); 226 227 [DllImport(highslibname)] Highs_deleteColsBySet(void* highs, int num_set_entries, int[] set)228 private static extern int Highs_deleteColsBySet(void* highs, int num_set_entries, int[] set); 229 230 [DllImport(highslibname)] Highs_deleteColsByMask(void* highs, int[] mask)231 private static extern int Highs_deleteColsByMask(void* highs, int[] mask); 232 233 [DllImport(highslibname)] Highs_deleteRowsByRange(void* highs, int from_row, int to_row)234 private static extern int Highs_deleteRowsByRange(void* highs, int from_row, int to_row); 235 236 [DllImport(highslibname)] Highs_deleteRowsBySet(void* highs, int num_set_entries, int[] set)237 private static extern int Highs_deleteRowsBySet(void* highs, int num_set_entries, int[] set); 238 239 [DllImport(highslibname)] Highs_deleteRowsByMask(void* highs, int[] mask)240 private static extern int Highs_deleteRowsByMask(void* highs, int[] mask); 241 242 [DllImport(highslibname)] Highs_getColsByRange(void* highs, int from_col, int to_col, ref int num_col, double[] costs, double[] lower, double[] upper, ref int num_nz, int[] matrix_start, int[] matrix_index, double[] matrix_value)243 private static extern int Highs_getColsByRange(void* highs, int from_col, int to_col, ref int num_col, double[] costs, 244 double[] lower, double[] upper, ref int num_nz, int[] matrix_start, int[] matrix_index, double[] matrix_value); 245 246 [DllImport(highslibname)] Highs_getColsBySet(void* highs, int num_set_entries, int[] set, ref int num_col, double[] costs, double[] lower, double[] upper, ref int num_nz, int[] matrix_start, int[] matrix_index, double[] matrix_value)247 private static extern int Highs_getColsBySet(void* highs, int num_set_entries, int[] set, ref int num_col, double[] costs, 248 double[] lower, double[] upper, ref int num_nz, int[] matrix_start, int[] matrix_index, double[] matrix_value); 249 250 [DllImport(highslibname)] Highs_getColsByMask(void* highs, int[] mask, ref int num_col, double[] costs, double[] lower, double[] upper, ref int num_nz, int[] matrix_start, int[] matrix_index, double[] matrix_value)251 private static extern int Highs_getColsByMask(void* highs, int[] mask, ref int num_col, double[] costs, 252 double[] lower, double[] upper, ref int num_nz, int[] matrix_start, int[] matrix_index, double[] matrix_value); 253 254 [DllImport(highslibname)] Highs_getRowsByRange(void* highs, int from_row, int to_row, ref int num_row, double[] lower, double[] upper, ref int num_nz, int[] matrix_start, int[] matrix_index, double[] matrix_value)255 private static extern int Highs_getRowsByRange(void* highs, int from_row, int to_row, ref int num_row, 256 double[] lower, double[] upper, ref int num_nz, int[] matrix_start, int[] matrix_index, double[] matrix_value); 257 258 [DllImport(highslibname)] Highs_getRowsBySet(void* highs, int num_set_entries, int[] set, ref int num_row, double[] lower, double[] upper, ref int num_nz, int[] matrix_start, int[] matrix_index, double[] matrix_value)259 private static extern int Highs_getRowsBySet(void* highs, int num_set_entries, int[] set, ref int num_row, 260 double[] lower, double[] upper, ref int num_nz, int[] matrix_start, int[] matrix_index, double[] matrix_value); 261 262 [DllImport(highslibname)] Highs_getRowsByMask(void* highs, int[] mask, ref int num_row, double[] lower, double[] upper, ref int num_nz, int[] matrix_start, int[] matrix_index, double[] matrix_value)263 private static extern int Highs_getRowsByMask(void* highs, int[] mask, ref int num_row, 264 double[] lower, double[] upper, ref int num_nz, int[] matrix_start, int[] matrix_index, double[] matrix_value); 265 266 [DllImport(highslibname)] Highs_getBasicVariables(void* highs, int[] basic_variables)267 private static extern int Highs_getBasicVariables(void* highs, int[] basic_variables); 268 269 [DllImport(highslibname)] Highs_getBasisInverseRow(void* highs, int row, double[] row_vector, ref int row_num_nz, int[] row_indices)270 private static extern int Highs_getBasisInverseRow(void* highs, int row, double[] row_vector, ref int row_num_nz, int[] row_indices); 271 272 [DllImport(highslibname)] Highs_getBasisInverseCol(void* highs, int col, double[] col_vector, ref int col_num_nz, int[] col_indices)273 private static extern int Highs_getBasisInverseCol(void* highs, int col, double[] col_vector, ref int col_num_nz, int[] col_indices); 274 275 [DllImport(highslibname)] Highs_getBasisSolve(void* highs, double[] rhs, double[] solution_vector, ref int solution_num_nz, int[] solution_indices)276 private static extern int Highs_getBasisSolve(void* highs, double[] rhs, double[] solution_vector, ref int solution_num_nz, int[] solution_indices); 277 278 [DllImport(highslibname)] Highs_getBasisTransposeSolve(void* highs, double[] rhs, double[] solution_vector, ref int solution_nz, int[] solution_indices)279 private static extern int Highs_getBasisTransposeSolve(void* highs, double[] rhs, double[] solution_vector, ref int solution_nz, int[] solution_indices); 280 281 [DllImport(highslibname)] Highs_getReducedRow(void* highs, int row, double[] row_vector, ref int row_num_nz, int[] row_indices)282 private static extern int Highs_getReducedRow(void* highs, int row, double[] row_vector, ref int row_num_nz, int[] row_indices); 283 284 [DllImport(highslibname)] Highs_getReducedColumn(void* highs, int col, double[] col_vector, ref int col_num_nz, int[] col_indices)285 private static extern int Highs_getReducedColumn(void* highs, int col, double[] col_vector, ref int col_num_nz, int[] col_indices); 286 call(HighsModel model, ref HighsSolution sol, ref HighsBasis bas, ref HighsModelStatus modelstatus)287 public static HighsStatus call(HighsModel model, ref HighsSolution sol, ref HighsBasis bas, ref HighsModelStatus modelstatus) 288 { 289 int nc = model.colcost.Length; 290 int nr = model.rowlower.Length; 291 int nnz = model.avalue.Length; 292 293 int[] colbasstat = new int[nc]; 294 int[] rowbasstat = new int[nr]; 295 296 int modelstate = 0; 297 298 HighsStatus status = (HighsStatus)HighsLpSolver.Highs_call(nc, nr, nnz, model.colcost, model.collower, model.colupper, 299 model.rowlower, model.rowupper, model.astart, model.aindex, model.avalue, 300 sol.colvalue, sol.coldual, sol.rowvalue, sol.rowdual, colbasstat, rowbasstat, ref modelstate); 301 302 modelstatus = (HighsModelStatus)modelstate; 303 304 bas.colbasisstatus = colbasstat.Select(x => (HighsBasisStatus)x).ToArray(); 305 bas.rowbasisstatus = rowbasstat.Select(x => (HighsBasisStatus)x).ToArray(); 306 307 return status; 308 } 309 HighsLpSolver()310 public HighsLpSolver() 311 { 312 this.highs = HighsLpSolver.Highs_create(); 313 } 314 ~HighsLpSolver()315 ~HighsLpSolver() 316 { 317 HighsLpSolver.Highs_destroy(this.highs); 318 } 319 run()320 public HighsStatus run() 321 { 322 return (HighsStatus)HighsLpSolver.Highs_run(this.highs); 323 } 324 readModel(string filename)325 public HighsStatus readModel(string filename) 326 { 327 return (HighsStatus)HighsLpSolver.Highs_readModel(this.highs, filename); 328 } 329 writeModel(string filename)330 public HighsStatus writeModel(string filename) 331 { 332 return (HighsStatus)HighsLpSolver.Highs_writeModel(this.highs, filename); 333 } 334 passLp(HighsModel model)335 public HighsStatus passLp(HighsModel model) 336 { 337 return (HighsStatus)HighsLpSolver.Highs_passLp(this.highs, model.colcost.Length, model.rowlower.Length, model.avalue.Length, 338 model.colcost, model.collower, model.colupper, model.rowlower, model.rowupper, model.astart, model.aindex, model.avalue); 339 } 340 setOptionValue(string option, string value)341 public HighsStatus setOptionValue(string option, string value) 342 { 343 return (HighsStatus)HighsLpSolver.Highs_setOptionValue(this.highs, option, value); 344 } 345 getNumCols()346 public int getNumCols() 347 { 348 return HighsLpSolver.Highs_getNumCols(this.highs); 349 } 350 getNumRows()351 public int getNumRows() 352 { 353 return HighsLpSolver.Highs_getNumRows(this.highs); 354 } 355 getNumNz()356 public int getNumNz() 357 { 358 return HighsLpSolver.Highs_getNumNz(this.highs); 359 } 360 getSolution()361 public HighsSolution getSolution() 362 { 363 int nc = this.getNumCols(); 364 int nr = this.getNumRows(); 365 366 HighsSolution sol = new HighsSolution(nc, nr); 367 HighsLpSolver.Highs_getSolution(this.highs, sol.colvalue, sol.coldual, sol.rowvalue, sol.rowdual); 368 return sol; 369 } 370 getBasis()371 public HighsBasis getBasis() 372 { 373 int nc = this.getNumCols(); 374 int nr = this.getNumRows(); 375 376 int[] colbasstat = new int[nc]; 377 int[] rowbasstat = new int[nr]; 378 379 HighsLpSolver.Highs_getBasis(this.highs, colbasstat, rowbasstat); 380 HighsBasis bas = new HighsBasis(colbasstat.Select(x => (HighsBasisStatus)x).ToArray(), rowbasstat.Select(x => (HighsBasisStatus)x).ToArray()); 381 382 return bas; 383 } 384 getObjectiveValue()385 public double getObjectiveValue() 386 { 387 return HighsLpSolver.Highs_getObjectiveValue(this.highs); 388 } 389 GetModelStatus()390 public HighsModelStatus GetModelStatus() 391 { 392 return (HighsModelStatus)HighsLpSolver.Highs_getModelStatus(this.highs); 393 } 394 getIterationCount()395 public int getIterationCount() 396 { 397 return HighsLpSolver.Highs_getIterationCount(this.highs); 398 } 399 addRow(double lower, double upper, int[] indices, double[] values)400 public HighsStatus addRow(double lower, double upper, int[] indices, double[] values) 401 { 402 return (HighsStatus)HighsLpSolver.Highs_addRow(this.highs, lower, upper, indices.Length, indices, values); 403 } 404 addRows(double[] lower, double[] upper, int[] starts, int[] indices, double[] values)405 public HighsStatus addRows(double[] lower, double[] upper, int[] starts, int[] indices, double[] values) 406 { 407 return (HighsStatus)HighsLpSolver.Highs_addRows(this.highs, lower.Length, lower, upper, indices.Length, starts, indices, values); 408 } 409 addCol(double cost, double lower, double upper, int[] indices, double[] values)410 public HighsStatus addCol(double cost, double lower, double upper, int[] indices, double[] values) 411 { 412 return (HighsStatus)HighsLpSolver.Highs_addCol(this.highs, cost, lower, upper, indices.Length, indices, values); 413 } 414 addCols(double[] costs, double[] lower, double[] upper, int[] starts, int[] indices, double[] values)415 public HighsStatus addCols(double[] costs, double[] lower, double[] upper, int[] starts, int[] indices, double[] values) 416 { 417 return (HighsStatus)HighsLpSolver.Highs_addCols(this.highs, costs.Length, costs, lower, upper, indices.Length, starts, indices, values); 418 } 419 changeObjectiveSense(HighsObjectiveSense sense)420 public HighsStatus changeObjectiveSense(HighsObjectiveSense sense) 421 { 422 return (HighsStatus)HighsLpSolver.Highs_changeObjectiveSense(this.highs, (int)sense); 423 } 424 changeColCost(int col, double cost)425 public HighsStatus changeColCost(int col, double cost) 426 { 427 return (HighsStatus)HighsLpSolver.Highs_changeColCost(this.highs, col, cost); 428 } 429 changeColsCostBySet(int[] cols, double[] costs)430 public HighsStatus changeColsCostBySet(int[] cols, double[] costs) 431 { 432 return (HighsStatus)HighsLpSolver.Highs_changeColsCostBySet(this.highs, cols.Length, cols, costs); 433 } 434 changeColsCostByMask(bool[] mask, double[] cost)435 public HighsStatus changeColsCostByMask(bool[] mask, double[] cost) 436 { 437 return (HighsStatus)HighsLpSolver.Highs_changeColsCostByMask(this.highs, mask.Select(x => x ? 1 : 0).ToArray(), cost); 438 } 439 changeColBounds(int col, double lower, double upper)440 public HighsStatus changeColBounds(int col, double lower, double upper) 441 { 442 return (HighsStatus)HighsLpSolver.Highs_changeColBounds(this.highs, col, lower, upper); 443 } 444 changeColsBoundsByRange(int from, int to, double[] lower, double[] upper)445 public HighsStatus changeColsBoundsByRange(int from, int to, double[] lower, double[] upper) 446 { 447 return (HighsStatus)HighsLpSolver.Highs_changeColsBoundsByRange(this.highs, from, to, lower, upper); 448 } 449 changeColsBoundsBySet(int[] cols, double[] lower, double[] upper)450 public HighsStatus changeColsBoundsBySet(int[] cols, double[] lower, double[] upper) 451 { 452 return (HighsStatus)HighsLpSolver.Highs_changeColsBoundsBySet(this.highs, cols.Length, cols, lower, upper); 453 } 454 changeColsBoundsByMask(bool[] mask, double[] lower, double[] upper)455 public HighsStatus changeColsBoundsByMask(bool[] mask, double[] lower, double[] upper) 456 { 457 return (HighsStatus)HighsLpSolver.Highs_changeColsBoundsByMask(this.highs, mask.Select(x => x ? 1 : 0).ToArray(), lower, upper); 458 } 459 changeRowBounds(int row, double lower, double upper)460 public HighsStatus changeRowBounds(int row, double lower, double upper) 461 { 462 return (HighsStatus)HighsLpSolver.Highs_changeRowBounds(this.highs, row, lower, upper); 463 } 464 changeRowsBoundsBySet(int[] rows, double[] lower, double[] upper)465 public HighsStatus changeRowsBoundsBySet(int[] rows, double[] lower, double[] upper) 466 { 467 return (HighsStatus)HighsLpSolver.Highs_changeRowsBoundsBySet(this.highs, rows.Length, rows, lower, upper); 468 } 469 changeRowsBoundsByMask(bool[] mask, double[] lower, double[] upper)470 public HighsStatus changeRowsBoundsByMask(bool[] mask, double[] lower, double[] upper) 471 { 472 return (HighsStatus)HighsLpSolver.Highs_changeRowsBoundsByMask(this.highs, mask.Select(x => x ? 1 : 0).ToArray(), lower, upper); 473 } 474 deleteColsByRange(int from, int to)475 public HighsStatus deleteColsByRange(int from, int to) 476 { 477 return (HighsStatus)HighsLpSolver.Highs_deleteColsByRange(this.highs, from, to); 478 } 479 deleteColsBySet(int[] cols)480 public HighsStatus deleteColsBySet(int[] cols) 481 { 482 return (HighsStatus)HighsLpSolver.Highs_deleteColsBySet(this.highs, cols.Length, cols); 483 } 484 deleteColsByMask(bool[] mask)485 public HighsStatus deleteColsByMask(bool[] mask) 486 { 487 return (HighsStatus)HighsLpSolver.Highs_deleteColsByMask(this.highs, mask.Select(x => x ? 1 : 0).ToArray()); 488 } 489 deleteRowsByRange(int from, int to)490 public HighsStatus deleteRowsByRange(int from, int to) 491 { 492 return (HighsStatus)HighsLpSolver.Highs_deleteRowsByRange(this.highs, from, to); 493 } 494 deleteRowsBySet(int[] rows)495 public HighsStatus deleteRowsBySet(int[] rows) 496 { 497 return (HighsStatus)HighsLpSolver.Highs_deleteRowsBySet(this.highs, rows.Length, rows); 498 } 499 deleteRowsByMask(bool[] mask)500 public HighsStatus deleteRowsByMask(bool[] mask) 501 { 502 return (HighsStatus)HighsLpSolver.Highs_deleteRowsByMask(this.highs, mask.Select(x => x ? 1 : 0).ToArray()); 503 } 504 505 // int Highs_getColsByRange(void *highs, int from_col, int to_col, ref int num_col, double[] costs, 506 // double[] lower, double[] upper, ref int num_nz, int[] matrix_start, int[] matrix_index, double[] matrix_value); 507 508 // [DllImport(highslibname)] 509 // int Highs_getColsBySet(void *highs, int num_set_entries, int[] set, ref int num_col, double[] costs, 510 // double[] lower, double[] upper, ref int num_nz, int[] matrix_start, int[] matrix_index, double[] matrix_value); 511 512 // [DllImport(highslibname)] 513 // int Highs_getColsByMask(void *highs, int[] mask, ref int num_col, double[] costs, 514 // double[] lower, double[] upper, ref int num_nz, int[] matrix_start, int[] matrix_index, double[] matrix_value); 515 516 // [DllImport(highslibname)] 517 // int Highs_getRowsByRange(void *highs, int from_row, int to_row, ref int num_row, 518 // double[] lower, double[] upper, ref int num_nz, int[] matrix_start, int[] matrix_index, double[] matrix_value); 519 520 // [DllImport(highslibname)] 521 // int Highs_getRowsBySet(void *highs, int num_set_entries, int[] set, ref int num_row, 522 // double[] lower, double[] upper, ref int num_nz, int[] matrix_start, int[] matrix_index, double[] matrix_value); 523 524 // [DllImport(highslibname)] 525 // int Highs_getRowsByMask(void *highs, int[] mask, ref int num_row, 526 // double[] lower, double[] upper, ref int num_nz, int[] matrix_start, int[] matrix_index, double[] matrix_value); 527 getBasicVariables(ref int[] basic_variables)528 public HighsStatus getBasicVariables(ref int[] basic_variables) 529 { 530 return (HighsStatus)Highs_getBasicVariables(this.highs, basic_variables); 531 } 532 getBasisInverseRow(int row, double[] row_vector, ref int row_num_nz, int[] row_indices)533 public HighsStatus getBasisInverseRow(int row, double[] row_vector, ref int row_num_nz, int[] row_indices) 534 { 535 return (HighsStatus)Highs_getBasisInverseRow(this.highs, row, row_vector, ref row_num_nz, row_indices); 536 } 537 getBasisInverseCol(int col, double[] col_vector, ref int col_num_nz, int[] col_indices)538 public HighsStatus getBasisInverseCol(int col, double[] col_vector, ref int col_num_nz, int[] col_indices) 539 { 540 return (HighsStatus)Highs_getBasisInverseCol(this.highs, col, col_vector, ref col_num_nz, col_indices); 541 } 542 getBasisSolve(double[] rhs, double[] solution_vector, ref int solution_num_nz, int[] solution_indices)543 public HighsStatus getBasisSolve(double[] rhs, double[] solution_vector, ref int solution_num_nz, int[] solution_indices) 544 { 545 return (HighsStatus)Highs_getBasisSolve(this.highs, rhs, solution_vector, ref solution_num_nz, solution_indices); 546 } 547 getBasisTransposeSolve(double[] rhs, double[] solution_vector, ref int solution_num_nz, int[] solution_indices)548 public HighsStatus getBasisTransposeSolve(double[] rhs, double[] solution_vector, ref int solution_num_nz, int[] solution_indices) 549 { 550 return (HighsStatus)Highs_getBasisTransposeSolve(this.highs, rhs, solution_vector, ref solution_num_nz, solution_indices); 551 } 552 getReducedRow(int row, double[] row_vector, ref int row_num_nz, int[] row_indices)553 public HighsStatus getReducedRow(int row, double[] row_vector, ref int row_num_nz, int[] row_indices) 554 { 555 return (HighsStatus)Highs_getReducedRow(this.highs, row, row_vector, ref row_num_nz, row_indices); 556 } 557 getReducedColumn(int col, double[] col_vector, ref int col_num_nz, int[] col_indices)558 public HighsStatus getReducedColumn(int col, double[] col_vector, ref int col_num_nz, int[] col_indices) 559 { 560 return (HighsStatus)Highs_getReducedColumn(this.highs, col, col_vector, ref col_num_nz, col_indices); 561 } 562 } 563