Changeset 292 for stable/1.4


Ignore:
Timestamp:
Oct 27, 2009 5:30:35 PM (10 years ago)
Author:
bjarni
Message:

Added new functions to CoinMP.cs (csharp) and recompiled CoinMPTestCS8.exe and CoinMPTestCS9.exe

Location:
stable/1.4/CoinMP/examples/csharp
Files:
3 edited

Legend:

Unmodified
Added
Removed
  • stable/1.4/CoinMP/examples/csharp/Coinmp.cs

    r280 r292  
    5353        public const int SOLV_FILE_IIS = 8;
    5454
    55         private static string GenerateNamesBuf(string[] NamesList)
     55        public const int SOLV_CHECK_COLCOUNT = 1;
     56        public const int SOLV_CHECK_ROWCOUNT = 2;
     57        public const int SOLV_CHECK_RANGECOUNT = 3;
     58        public const int SOLV_CHECK_OBJSENSE = 4;
     59        public const int SOLV_CHECK_ROWTYPE = 5;
     60        public const int SOLV_CHECK_MATBEGIN = 6;
     61        public const int SOLV_CHECK_MATCOUNT = 7;
     62        public const int SOLV_CHECK_MATBEGCNT = 8;
     63        public const int SOLV_CHECK_MATBEGNZ = 9;
     64        public const int SOLV_CHECK_MATINDEX = 10;
     65        public const int SOLV_CHECK_MATINDEXROW = 11;
     66        public const int SOLV_CHECK_BOUNDS = 12;
     67        public const int SOLV_CHECK_COLTYPE = 13;
     68        public const int SOLV_CHECK_COLNAMES = 14;
     69        public const int SOLV_CHECK_COLNAMESLEN = 15;
     70        public const int SOLV_CHECK_ROWNAMES = 16;
     71        public const int SOLV_CHECK_ROWNAMSLEN = 17;
     72
     73        private static string GenerateNamesBuf(string[] namesList)
    5674        {
    5775            int i;
    5876            StringBuilder namesBuf = new StringBuilder();
    5977
    60             if (NamesList.GetLength(0) > 0)
     78            if (namesList.GetLength(0) > 0)
    6179            {
    62                 namesBuf.Append(NamesList[0] + "\0");
    63                 for (i = 1; i < NamesList.GetLength(0); i++)
     80                namesBuf.Append(namesList[0] + "\0");
     81                for (i = 1; i < namesList.GetLength(0); i++)
    6482                {
    65                     namesBuf.Append(NamesList[i] + "\0");
     83                    namesBuf.Append(namesList[i] + "\0");
    6684                }
    6785            }
     
    6987        }
    7088
    71         public delegate int MsgLogDelegate(string MessageStr);
    72 
    73         [DllImport("coinmp.dll")] public static extern int CoinInitSolver(string LicenseStr);
     89        public delegate int MsgLogDelegate(string messageStr);
     90
     91        public delegate int IterDelegate(int iterCount,
     92                                         double objectValue,
     93                                         int isFeasible,
     94                                         double infeasValue);
     95
     96        public delegate int MipNodeDelegate(int iterCount,
     97                                            int mipNodeCount,
     98                                            double bestBound,
     99                                            double bestInteger,
     100                                            int isMipImproved);
     101
     102        [DllImport("coinmp.dll")] public static extern int CoinInitSolver(string licenseStr);
    74103        [DllImport("coinmp.dll")] public static extern int CoinFreeSolver();
    75104
    76         [DllImport("coinmp.dll")] public static extern String CoinGetSolverName();
    77         [DllImport("coinmp.dll")] public static extern int CoinGetSolverNameBuf(StringBuilder SolverName, int buflen);
    78         [DllImport("coinmp.dll")] public static extern String CoinGetVersionStr();
    79         [DllImport("coinmp.dll")] public static extern int CoinGetVersionStrBuf(StringBuilder VersionStr, int buflen);
     105        [DllImport("coinmp.dll")] public static extern string CoinGetSolverName();
     106        [DllImport("coinmp.dll")] public static extern int CoinGetSolverNameBuf(StringBuilder solverName, int buflen);
     107        [DllImport("coinmp.dll")] public static extern string CoinGetVersionStr();
     108        [DllImport("coinmp.dll")] public static extern int CoinGetVersionStrBuf(StringBuilder versionStr, int buflen);
    80109        [DllImport("coinmp.dll")] public static extern double CoinGetVersion();
    81110
     
    86115        [DllImport("coinmp.dll")] public static extern IntPtr CoinCreateProblem(string problemName);
    87116
    88         [DllImport("coinmp.dll")] public static extern int CoinSetLoadNamesType(IntPtr hProb, int loadNamesType);
    89 
    90117        [DllImport("coinmp.dll")] public static extern int CoinLoadProblemBuf(IntPtr hProb, int colCount, int rowCount,
    91                         int NZcount, int RangeCount, int objectSense, double objectConst, double[] objectCoeffs,
    92                         double[] lowerBounds, double[] upperBounds, char[] rowType, double[] RHSValues,
    93                         double[] RangeValues, int[] matrixBegin, int[] matrixCount, int[] matrixIndex,
     118                        int nzCount, int rangeCount, int objectSense, double objectConst, double[] objectCoeffs,
     119                        double[] lowerBounds, double[] upperBounds, char[] rowType, double[] rhsValues,
     120                        double[] rangeValues, int[] matrixBegin, int[] matrixCount, int[] matrixIndex,
    94121                        double[] matrixValues, string colNamesBuf, string rowNamesBuf, string objName);
    95122
    96         public static int CoinLoadProblem(IntPtr hProb, int colCount, int rowCount, int NZcount,
    97                         int RangeCount, int objectSense, double objectConst, double[] objectCoeffs,
    98                         double[] lowerBounds, double[] upperBounds, char[] rowType, double[] RHSValues,
    99                         double[] RangeValues, int[] matrixBegin, int[] matrixCount, int[] matrixIndex,
     123        public static int CoinLoadProblem(IntPtr hProb, int colCount, int rowCount, int nzCount,
     124                        int rangeCount, int objectSense, double objectConst, double[] objectCoeffs,
     125                        double[] lowerBounds, double[] upperBounds, char[] rowType, double[] rhsValues,
     126                        double[] rangeValues, int[] matrixBegin, int[] matrixCount, int[] matrixIndex,
    100127                        double[] matrixValues, string[] colNames, string[] rowNames, string objName)
    101128        {
    102             return CoinLoadProblemBuf(hProb, colCount, rowCount, NZcount, RangeCount, objectSense,
    103                         objectConst, objectCoeffs, lowerBounds, upperBounds, rowType, RHSValues,
    104                         RangeValues, matrixBegin, matrixCount, matrixIndex, matrixValues,
     129            return CoinLoadProblemBuf(hProb, colCount, rowCount, nzCount, rangeCount, objectSense,
     130                        objectConst, objectCoeffs, lowerBounds, upperBounds, rowType, rhsValues,
     131                        rangeValues, matrixBegin, matrixCount, matrixIndex, matrixValues,
    105132                        GenerateNamesBuf(colNames), GenerateNamesBuf(rowNames), objName);
    106133
    107134        }
    108135
    109         // No rowType, switch to rowLower and rowUpper arguments
    110         public static int CoinLoadProblem(IntPtr hProb, int colCount, int rowCount, int NZcount,
    111                         int RangeCount, int objectSense, double objectConst, double[] objectCoeffs,
     136        // when there is no rowType argument, CoinLoadProblem switches to rowLower and rowUpper arguments
     137        public static int CoinLoadProblem(IntPtr hProb, int colCount, int rowCount, int nzCount,
     138                        int rangeCount, int objectSense, double objectConst, double[] objectCoeffs,
    112139                        double[] lowerBounds, double[] upperBounds, double[] rowLower, double[] rowUpper,
    113140                        int[] matrixBegin, int[] matrixCount, int[] matrixIndex, double[] matrixValues,
    114141                        string[] colNames, string[] rowNames, string objName)
    115142        {
    116             return CoinLoadProblemBuf(hProb, colCount, rowCount, NZcount, RangeCount, objectSense,
     143            return CoinLoadProblemBuf(hProb, colCount, rowCount, nzCount, rangeCount, objectSense,
    117144                        objectConst, objectCoeffs, lowerBounds, upperBounds, null, rowLower,
    118145                        rowUpper, matrixBegin, matrixCount, matrixIndex, matrixValues,
     
    121148        }
    122149
     150        [DllImport("coinmp.dll")] public static extern int CoinLoadInitValues(IntPtr hProb, double[] initValues);
     151
     152        [DllImport("coinmp.dll")] public static extern int CoinLoadInteger(IntPtr hProb, char[] columnType);
     153
     154
     155        [DllImport("coinmp.dll")] public static extern int CoinLoadPriority(IntPtr hProb, int priorCount,
     156                        int[] priorIndex, int[] priorValues, int[] branchDir);
     157
     158        [DllImport("coinmp.dll")] public static extern int CoinLoadSemiCont(IntPtr hProb, int semiCount,
     159                        int[] semiIndex);
     160
     161        [DllImport("coinmp.dll")] public static extern int CoinLoadSos(IntPtr hProb, int sosCount,
     162                        int sosNZCount, int[] sosType, int[] sosPrior,
     163                        int[] sosBegin, int[] sosIndex, double[] sosRef);
     164
     165        [DllImport("coinmp.dll")] public static extern int CoinLoadQuadratic(IntPtr hProb, int[] quadBegin,
     166                        int[] quadCount, int[] quadIndex, double[] quadValues);
     167
     168        [DllImport("coinmp.dll")] public static extern int CoinLoadNonlinear(IntPtr hProb, int nlpTreeCount,
     169                        int nlpLineCount, int[] nlpBegin, int[] nlpOper,
     170                        int[] nlpArg1, int[] nlpArg2, int[] nlpIndex1,
     171                        int[] nlpIndex2, double[] nlpValue1, double[] nlpValue2);
     172
    123173        [DllImport("coinmp.dll")] public static extern int CoinUnloadProblem(IntPtr hProb);
    124174
    125175        [DllImport("coinmp.dll")] public static extern int CoinCheckProblem(IntPtr hProb);
     176
     177        [DllImport("coinmp.dll")] public static extern int CoinSetLoadNamesType(IntPtr hProb, int loadNamesType);
     178
     179        [DllImport("coinmp.dll")] public static extern string CoinGetProblemName(IntPtr hProb);
     180        [DllImport("coinmp.dll")] public static extern int CoinGetProblemNameBuf(IntPtr hProb,
     181                        StringBuilder problemName, int buflen);
     182
     183        [DllImport("coinmp.dll")] public static extern int CoinGetColCount(IntPtr hProb);
     184        [DllImport("coinmp.dll")] public static extern int CoinGetRowCount(IntPtr hProb);
     185
     186        [DllImport("coinmp.dll")] public static extern string CoinGetColName(IntPtr hProb, int col);
     187        [DllImport("coinmp.dll")] public static extern int CoinGetColNameBuf(IntPtr hProb, int col,
     188                        StringBuilder colName, int buflen);
     189
     190        [DllImport("coinmp.dll")] public static extern string CoinGetRowName(IntPtr hProb, int row);
     191        [DllImport("coinmp.dll")] public static extern int CoinGetRowNameBuf(IntPtr hProb, int row,
     192                        StringBuilder rowName, int buflen);
     193
     194        [DllImport("coinmp.dll")] public static extern int CoinSetMsgLogCallback(IntPtr hProb, MsgLogDelegate msgLogDelegate);
     195        [DllImport("coinmp.dll")] public static extern int CoinSetIterCallback(IntPtr hProb, IterDelegate iterDelegate);
     196        [DllImport("coinmp.dll")] public static extern int CoinSetMipNodeCallback(IntPtr hProb, MipNodeDelegate mipNodeDelegate);
     197
    126198        [DllImport("coinmp.dll")] public static extern int CoinOptimizeProblem(IntPtr hProb, int method);
    127199
     
    132204
    133205        [DllImport("coinmp.dll")] public static extern int CoinGetSolutionStatus(IntPtr hProb);
    134         [DllImport("coinmp.dll")] public static extern double CoinGetObjectValue(IntPtr hProb);
    135 
    136         [DllImport("coinmp.dll")] public static extern int CoinSetMsgLogCallback(IntPtr hProb, MsgLogDelegate MsgLogDelegate);
    137 
    138 
    139         [DllImport("coinmp.dll")] public static extern int CoinLoadInteger(IntPtr hProb, char[] columnType);
    140 
    141         [DllImport("coinmp.dll")] public static extern int CoinWriteFile(IntPtr hProb, int fileType, string writeFilename);
    142 
    143         [DllImport("coinmp.dll")] public static extern String CoinGetSolutionText(IntPtr hProbs, int solutionStatus);
     206
     207        [DllImport("coinmp.dll")] public static extern string CoinGetSolutionText(IntPtr hProbs, int solutionStatus);
    144208        [DllImport("coinmp.dll")] public static extern int CoinGetSolutionTextBuf(IntPtr hProbs, int solutionStatus,
    145209                        StringBuilder solutionText, int buflen);
    146210
    147         [DllImport("coinmp.dll")] public static extern int CoinGetColCount(IntPtr hProb);
    148         [DllImport("coinmp.dll")] public static extern int CoinGetRowCount(IntPtr hProb);
     211        [DllImport("coinmp.dll")] public static extern double CoinGetObjectValue(IntPtr hProb);
     212        [DllImport("coinmp.dll")] public static extern double CoinGetMipBestBound(IntPtr hProb);
     213
     214        [DllImport("coinmp.dll")] public static extern int CoinGetIterCount(IntPtr hProb);
     215        [DllImport("coinmp.dll")] public static extern int CoinGetMipNodeCount(IntPtr hProb);
    149216
    150217        [DllImport("coinmp.dll")] public static extern int CoinGetSolutionValues(IntPtr hProb, [In, Out] double[] activity,
    151                 [In, Out] double[] reducedCost, [In, Out] double[] slackValues, [In, Out] double[] shadowPrice);
    152 
    153         [DllImport("coinmp.dll")] public static extern String CoinGetColName(IntPtr hProb, int col);
    154         [DllImport("coinmp.dll")] public static extern int CoinGetColNameBuf(IntPtr hProb, int col, StringBuilder colName, int buflen);
    155    
     218                        [In, Out] double[] reducedCost, [In, Out] double[] slackValues, [In, Out] double[] shadowPrice);
     219
     220        [DllImport("coinmp.dll")] public static extern int CoinGetSolutionRanges(IntPtr hProb, [In, Out] double[] objLoRange,
     221                        [In, Out] double[] objUpRange, [In, Out] double[] rhsLoRange, [In, Out] double[] rhsUpRange);
     222
     223        [DllImport("coinmp.dll")] public static extern int CoinGetSolutionBasis(IntPtr hProb, [In, Out] int[] colStatus,
     224                        [In, Out] double[] rowStatus);
     225
     226        [DllImport("coinmp.dll")] public static extern int CoinReadFile(IntPtr hProb, int fileType, string readFilename);
     227        [DllImport("coinmp.dll")] public static extern int CoinWriteFile(IntPtr hProb, int fileType, string writeFilename);
     228
     229
     230        [DllImport("coinmp.dll")] public static extern int CoinOpenLogFile(IntPtr hProb, string logFilename);
     231        [DllImport("coinmp.dll")] public static extern int CoinCloseLogFile(IntPtr hProb);
     232
     233        [DllImport("coinmp.dll")] public static extern int CoinGetOptionCount(IntPtr hProb);
     234        [DllImport("coinmp.dll")] public static extern int CoinGetOptionInfo(IntPtr hProb, int optionNr,
     235                        [In, Out] int[] optionID, [In, Out] int[] groupType, [In, Out] int[] optionType);
     236
     237        [DllImport("coinmp.dll")] public static extern int CoinGetOptionName(IntPtr hProb, int optionNr);
     238        [DllImport("coinmp.dll")] public static extern int CoinGetOptionNameBuf(IntPtr hProb, int optionNr,
     239                        StringBuilder optionName, int buflen);
     240
     241        [DllImport("coinmp.dll")] public static extern int CoinGetOptionShortName(IntPtr hProb, int optionNr);
     242        [DllImport("coinmp.dll")] public static extern int CoinGetOptionShortNameBuf(IntPtr hProb, int optionNr,
     243                        StringBuilder shortName, int buflen);
     244
     245        [DllImport("coinmp.dll")] public static extern int CoinGetIntOptionMinMax(IntPtr hProb, int optionNr,
     246                        [In, Out] int[] minValue, [In, Out] int[] maxValue);
     247        [DllImport("coinmp.dll")] public static extern int CoinGetRealOptionMinMax(IntPtr hProb, int optionNr,
     248                        [In, Out] double[] minValue, [In, Out] double[] maxValue);
     249
     250        [DllImport("coinmp.dll")] public static extern int CoinGetOptionChanged(IntPtr hProb, int optionID);
     251
     252        [DllImport("coinmp.dll")] public static extern int CoinGetIntOption(IntPtr hProb, int optionID);
     253        [DllImport("coinmp.dll")] public static extern int CoinSetIntOption(IntPtr hProb, int optionID, int intValue);
     254
     255        [DllImport("coinmp.dll")] public static extern int CoinGetRealOption(IntPtr hProb, int optionID);
     256        [DllImport("coinmp.dll")] public static extern int CoinSetRealOption(IntPtr hProb, int optionID, double realValue);
     257
     258        [DllImport("coinmp.dll")] public static extern int CoinGetStringOption(IntPtr hProb, int optionID);
     259        [DllImport("coinmp.dll")] public static extern int CoinGetStringOptionBuf(IntPtr hProb, int optionID,
     260                        StringBuilder stringValue, int buflen);
     261        [DllImport("coinmp.dll")] public static extern int CoinSetStringOption(IntPtr hProb, int optionID,
     262                        string stringValue);
    156263    }
    157264}
Note: See TracChangeset for help on using the changeset viewer.