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