public override object Solve(object solver) /* La construction de la matrice des données du problème n'est pas prise en charge par le solveur Coin */ { /* Celle-ci se fait au fur et à mesure qu'on ajoute des données par le biais du code de la fonction Solve() */ int ind = 0; double objectConst = 0.0; int NZCount = 0; int result; UpperBounds = new double[NUM_COLS]; LowerBounds = new double [NUM_COLS]; MatrixBegin = new int [NUM_COLS + 1]; MatrixCount = new int [NUM_COLS]; for (int i = 0; i < NUM_COLS; i++) { UpperBounds[i] = Double.PositiveInfinity; LowerBounds[i] = Double.NegativeInfinity; MatrixBegin[i] = i * 2; } MatrixBegin[NUM_COLS] = NUM_COLS * 2; for (int i = 0; i < NUM_COLS; i++) { int count = 0; for (int j = 0; j < NUM_ROWS; j++) { if (Matrix[j, i] != 0) { NZCount++; count++; } } MatrixCount[i] = count; } MatrixValues = new double[NZCount]; MatrixIndex = new int[NZCount]; for (int i = 0; i < NUM_COLS; i++) { for (int j = 0; j < NUM_ROWS; j++) { if (Matrix[j, i] != 0) { MatrixValues[ind] = Matrix[j, i]; MatrixIndex[ind] = j; ind++; } } } CoinMP.CoinLoadProblem((IntPtr)solver, NUM_COLS, NUM_ROWS, NZCount, 0, CoinMP.SOLV_OBJSENS_MAX, objectConst, ObjectCoeffs, LowerBounds, UpperBounds, RowTypes, RhsValues, RangeValues, MatrixBegin, MatrixCount, MatrixIndex, MatrixValues, ColNames, RowNames, ObjName); result = CoinMP.CoinOptimizeProblem((IntPtr)solver); result = CoinMP.CoinWriteFile((IntPtr)solver, CoinMP.SOLV_FILE_MPS, "Result_CoinMP"); return(CoinMP.CoinGetSolutionTextIntPtr((IntPtr)solver)); }
public override bool SetOutputFile(object solver, string filename) { if (CoinMP.CoinWriteFile((IntPtr)solver, CoinMP.SOLV_FILE_MPS, filename) == 0) { return(false); } return(true); }
public void RunProblem(string problemName, double optimalValue, int colCount, int rowCount, int nonZeroCount, int rangeCount, int objectSense, double objectConst, double[] objectCoeffs, double[] lowerBounds, double[] upperBounds, char[] rowType, double[] rhsValues, double[] rangeValues, int[] matrixBegin, int[] matrixCount, int[] matrixIndex, double[] matrixValues, string[] colNames, string[] rowNames, string objectName, double[] initValues, char[] colType) { IntPtr hProb; int result; logTxt.NewLine(); logTxt.WriteLine("Solve Problem: " + problemName + " (obj=" + optimalValue + ")"); logTxt.WriteLine("---------------------------------------------------------------"); hProb = CoinMP.CoinCreateProblem(problemName); result = CoinMP.CoinLoadMatrix(hProb, colCount, rowCount, nonZeroCount, rangeCount, objectSense, objectConst, objectCoeffs, lowerBounds, upperBounds, rowType, rhsValues, rangeValues, matrixBegin, matrixCount, matrixIndex, matrixValues); result = CoinMP.CoinLoadNames(hProb, colNames, rowNames, objectName); if (result != 0) { logTxt.WriteLine("CoinLoadProblem failed"); } if (colType != null) { result = CoinMP.CoinLoadInteger(hProb, colType); if (result != 0) { logTxt.WriteLine("CoinLoadInteger failed"); } } result = CoinMP.CoinCheckProblem(hProb); if (result != 0) { logTxt.WriteLine("Check Problem failed (result = " + result + ")"); } CoinMP.MsgLogDelegate MsgLogDelegate = new CoinMP.MsgLogDelegate(MsgLogCallback); result = CoinMP.CoinSetMsgLogCallback(hProb, MsgLogDelegate); result = CoinMP.CoinOptimizeProblem(hProb); result = CoinMP.CoinWriteFile(hProb, CoinMP.SOLV_FILE_MPS, problemName); GetAndCheckSolution(optimalValue, hProb); result = CoinMP.CoinUnloadProblem(hProb); }