예제 #1
0
        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);
        }