 Timestamp:
 Feb 2, 2006 11:45:39 AM (14 years ago)
 Location:
 trunk/Test
 Files:

 2 edited
Legend:
 Unmodified
 Added
 Removed

trunk/Test/Cbc_ampl.cpp
r242 r244 28 28 #include "unistd.h" 29 29 #include <string> 30 /* so decodePhrase and clpCheck can access */ 31 static ampl_info * saveInfo=NULL; 32 // Set to 1 if algorithm found 33 static char algFound[20]=""; 30 34 static char* 31 clpCheck(Option_Info *oi, keyword *kw, char *v) 32 { 33 char *rv=NULL; 34 printf("string %s\n",v); 35 return rv; 36 } 37 /* so decodePhrase can access */ 38 static ampl_info * saveInfo=NULL; 35 checkPhrase(Option_Info *oi, keyword *kw, char *v) 36 { 37 if (strlen(v)) 38 printf("string %s\n",v); 39 // Say algorithm found 40 strcpy(algFound,kw>desc);; 41 return v; 42 } 43 static char* 44 checkPhrase2(Option_Info *oi, keyword *kw, char *v) 45 { 46 if (strlen(v)) 47 printf("string %s\n",v); 48 // put out keyword 49 saveInfo>arguments=(char **) realloc(saveInfo>arguments,(saveInfo>numberArguments+1)*sizeof(char *)); 50 saveInfo>arguments[saveInfo>numberArguments++]=strdup(kw>desc); 51 return v; 52 } 39 53 static fint 40 54 decodePhrase(char * phrase,ftnlen length) … … 58 72 #define VP (char*) 59 73 static keyword keywds[] = { /* must be sorted */ 60 { "aaaa", clpCheck, (char *) xxxxxx }, 74 { "barrier", checkPhrase, (char *) xxxxxx ,"barrier" }, 75 { "dual", checkPhrase, (char *) xxxxxx , "dualsimplex"}, 76 { "initial", checkPhrase, (char *) xxxxxx , "initialsolve"}, 77 { "max", checkPhrase2, (char *) xxxxxx , "maximize"}, 78 { "maximize", checkPhrase2, (char *) xxxxxx , "maximize"}, 79 { "primal", checkPhrase, (char *) xxxxxx , "primalsimplex"}, 61 80 { "wantsol", WS_val, NULL, "write .sol file (without AMPL)" } 62 81 }; … … 275 294 } 276 295 if (!found) { 277 info>arguments=(char **) realloc(info>arguments,(info>numberArguments+1)*sizeof(char *)); 278 info>arguments[info>numberArguments++]=strdup("solve"); 296 if (!strlen(algFound)) { 297 info>arguments=(char **) realloc(info>arguments,(info>numberArguments+1)*sizeof(char *)); 298 info>arguments[info>numberArguments++]=strdup("solve"); 299 } else { 300 // use algorithm from keyword 301 info>arguments=(char **) realloc(info>arguments,(info>numberArguments+1)*sizeof(char *)); 302 info>arguments[info>numberArguments++]=strdup(algFound); 303 } 279 304 } 280 305 if (foundSleep) { 
trunk/Test/CoinSolve.cpp
r243 r244 15 15 #include "CoinHelperFunctions.hpp" 16 16 // Same version as CBC 17 #define CBCVERSION "1.0 0.02"17 #define CBCVERSION "1.01.00" 18 18 19 19 #include "CoinMpsIO.hpp" … … 22 22 #include "CoinTime.hpp" 23 23 #include "ClpSimplex.hpp" 24 #include "ClpSimplexOther.hpp" 24 25 #include "ClpSolve.hpp" 25 26 #include "ClpPackedMatrix.hpp" … … 81 82 #endif 82 83 static double totalTime=0.0; 84 static void statistics(ClpSimplex * originalModel, ClpSimplex * model); 83 85 84 86 //############################################################################# … … 487 489 int printMode=0; 488 490 int presolveOptions=0; 491 int substitution=3; 492 int dualize=0; 489 493 int doCrash=0; 490 494 int doSprint=1; … … 547 551 parameters[whichParam(SAVESOL,numberParameters,parameters)].setStringValue(solutionSaveFile); 548 552 parameters[whichParam(SPRINT,numberParameters,parameters)].setIntValue(doSprint); 553 parameters[whichParam(SUBSTITUTION,numberParameters,parameters)].setIntValue(substitution); 554 parameters[whichParam(DUALIZE,numberParameters,parameters)].setIntValue(dualize); 549 555 model.setNumberBeforeTrust(5); 550 556 parameters[whichParam(NUMBERBEFORE,numberParameters,parameters)].setIntValue(5); … … 851 857 else if (parameters[iParam].type()==PRINTOPTIONS) 852 858 printOptions = value; 859 else if (parameters[iParam].type()==SUBSTITUTION) 860 substitution = value; 861 else if (parameters[iParam].type()==DUALIZE) 862 dualize = value; 853 863 else if (parameters[iParam].type()==CUTPASS) 854 864 cutPass = value; … … 1123 1133 ClpSolve::PresolveType presolveType; 1124 1134 ClpSimplex * model2 = lpSolver; 1135 if (dualize) { 1136 model2 = ((ClpSimplexOther *) model2)>dualOfModel(); 1137 printf("Dual of model has %d rows and %d columns\n", 1138 model2>numberRows(),model2>numberColumns()); 1139 model2>setOptimizationDirection(1.0); 1140 } 1125 1141 if (noPrinting) 1126 1142 lpSolver>setLogLevel(0); 1127 1143 ClpSolve solveOptions; 1128 if (preSolve!=5&&preSolve) 1144 solveOptions.setPresolveActions(presolveOptions); 1145 solveOptions.setSubstitution(substitution); 1146 if (preSolve!=5&&preSolve) { 1129 1147 presolveType=ClpSolve::presolveNumber; 1130 else if (preSolve) 1148 if (preSolve<0) { 1149 preSolve =  preSolve; 1150 if (preSolve<=100) { 1151 presolveType=ClpSolve::presolveNumber; 1152 printf("Doing %d presolve passes  picking up noncosted slacks\n", 1153 preSolve); 1154 solveOptions.setDoSingletonColumn(true); 1155 } else { 1156 preSolve =100; 1157 presolveType=ClpSolve::presolveNumberCost; 1158 printf("Doing %d presolve passes  picking up costed slacks\n", 1159 preSolve); 1160 } 1161 } 1162 } else if (preSolve) { 1131 1163 presolveType=ClpSolve::presolveOn; 1132 else1164 } else { 1133 1165 presolveType=ClpSolve::presolveOff; 1166 } 1134 1167 solveOptions.setPresolveType(presolveType,preSolve); 1135 if (type==DUALSIMPLEX SOLVECONTINUOUS) {1168 if (type==DUALSIMPLEXtype==SOLVECONTINUOUS) { 1136 1169 method=ClpSolve::useDual; 1137 1170 } else if (type==PRIMALSIMPLEX) { … … 1205 1238 model2>initialSolve(solveOptions); 1206 1239 basisHasValues=1; 1240 if (dualize) { 1241 ((ClpSimplexOther *) lpSolver)>restoreFromDual(model2); 1242 delete model2; 1243 model2=lpSolver; 1244 } 1207 1245 #ifdef CBC_AMPL 1208 1246 if (usingAmpl) { … … 1266 1304 } 1267 1305 #endif 1306 } else { 1307 std::cout<<"** Current model not valid"<<std::endl; 1308 } 1309 break; 1310 case STATISTICS: 1311 if (goodModel) { 1312 // If presolve on look at presolved 1313 bool deleteModel2=false; 1314 ClpSimplex * model2 = lpSolver; 1315 if (preSolve) { 1316 ClpPresolve pinfo; 1317 int presolveOptions2 = presolveOptions&~0x40000000; 1318 if ((presolveOptions2&0xffff)!=0) 1319 pinfo.setPresolveActions(presolveOptions2); 1320 pinfo.setSubstitution(substitution); 1321 if ((printOptions&1)!=0) 1322 pinfo.statistics(); 1323 double presolveTolerance = 1324 parameters[whichParam(PRESOLVETOLERANCE,numberParameters,parameters)].doubleValue(); 1325 model2 = 1326 pinfo.presolvedModel(*lpSolver,presolveTolerance, 1327 true,preSolve); 1328 if (model2) { 1329 printf("Statistics for presolved model\n"); 1330 deleteModel2=true; 1331 } else { 1332 printf("Presolved model looks infeasible  will use unpresolved\n"); 1333 model2 = lpSolver; 1334 } 1335 } else { 1336 printf("Statistics for unpresolved model\n"); 1337 model2 = lpSolver; 1338 } 1339 statistics(lpSolver,model2); 1340 if (deleteModel2) 1341 delete model2; 1268 1342 } else { 1269 1343 std::cout<<"** Current model not valid"<<std::endl; … … 2826 2900 return 0; 2827 2901 } 2902 static void breakdown(const char * name, int numberLook, const double * region) 2903 { 2904 double range[] = { 2905 COIN_DBL_MAX, 2906 1.0e15,1.0e11,1.0e8,1.0e5,1.0e4,1.0e3,1.0e2,1.0e1, 2907 1.0, 2908 1.0e1,1.0e2,1.0e3,1.0e4,1.0e5,1.0e8,1.0e11,1.0e15, 2909 0.0, 2910 1.0e15,1.0e11,1.0e8,1.0e5,1.0e4,1.0e3,1.0e2,1.0e1, 2911 1.0, 2912 1.0e1,1.0e2,1.0e3,1.0e4,1.0e5,1.0e8,1.0e11,1.0e15, 2913 COIN_DBL_MAX}; 2914 int nRanges = (int) (sizeof(range)/sizeof(double)); 2915 int * number = new int[nRanges]; 2916 memset(number,0,nRanges*sizeof(int)); 2917 int * numberExact = new int[nRanges]; 2918 memset(numberExact,0,nRanges*sizeof(int)); 2919 int i; 2920 for ( i=0;i<numberLook;i++) { 2921 double value = region[i]; 2922 for (int j=0;j<nRanges;j++) { 2923 if (value==range[j]) { 2924 numberExact[j]++; 2925 break; 2926 } else if (value<range[j]) { 2927 number[j]++; 2928 break; 2929 } 2930 } 2931 } 2932 printf("\n%s has %d entries\n",name,numberLook); 2933 for (i=0;i<nRanges;i++) { 2934 if (number[i]) 2935 printf("%d between %g and %g",number[i],range[i1],range[i]); 2936 if (numberExact[i]) { 2937 if (number[i]) 2938 printf(", "); 2939 printf("%d exactly at %g",numberExact[i],range[i]); 2940 } 2941 if (number[i]+numberExact[i]) 2942 printf("\n"); 2943 } 2944 delete [] number; 2945 delete [] numberExact; 2946 } 2947 static void statistics(ClpSimplex * originalModel, ClpSimplex * model) 2948 { 2949 int numberColumns = originalModel>numberColumns(); 2950 const char * integerInformation = originalModel>integerInformation(); 2951 const double * columnLower = originalModel>columnLower(); 2952 const double * columnUpper = originalModel>columnUpper(); 2953 int numberIntegers=0; 2954 int numberBinary=0; 2955 int iRow,iColumn; 2956 if (integerInformation) { 2957 for (iColumn=0;iColumn<numberColumns;iColumn++) { 2958 if (integerInformation[iColumn]) { 2959 if (columnUpper[iColumn]>columnLower[iColumn]) { 2960 numberIntegers++; 2961 if (columnUpper[iColumn]==0.0&&columnLower[iColumn]==1) 2962 numberBinary++; 2963 } 2964 } 2965 } 2966 } 2967 numberColumns = model>numberColumns(); 2968 int numberRows = model>numberRows(); 2969 columnLower = model>columnLower(); 2970 columnUpper = model>columnUpper(); 2971 const double * rowLower = model>rowLower(); 2972 const double * rowUpper = model>rowUpper(); 2973 const double * objective = model>objective(); 2974 CoinPackedMatrix * matrix = model>matrix(); 2975 CoinBigIndex numberElements = matrix>getNumElements(); 2976 const int * columnLength = matrix>getVectorLengths(); 2977 //const CoinBigIndex * columnStart = matrix>getVectorStarts(); 2978 const double * elementByColumn = matrix>getElements(); 2979 int * number = new int[numberRows+1]; 2980 memset(number,0,(numberRows+1)*sizeof(int)); 2981 int numberObjSingletons=0; 2982 /* cType 2983 0 0/inf, 1 0/up, 2 lo/inf, 3 lo/up, 4 free, 5 fix, 6 inf/0, 7 inf/up, 2984 8 0/1 2985 */ 2986 int cType[9]; 2987 std::string cName[]={"0.0>inf,","0.0>up,","lo>inf,","lo>up,","free,","fixed,","inf>0.0,", 2988 "inf>up,","0.0>1.0"}; 2989 int nObjective=0; 2990 memset(cType,0,sizeof(cType)); 2991 for (iColumn=0;iColumn<numberColumns;iColumn++) { 2992 int length=columnLength[iColumn]; 2993 if (length==1&&objective[iColumn]) 2994 numberObjSingletons++; 2995 number[length]++; 2996 if (objective[iColumn]) 2997 nObjective++; 2998 if (columnLower[iColumn]>1.0e20) { 2999 if (columnLower[iColumn]==0.0) { 3000 if (columnUpper[iColumn]>1.0e20) 3001 cType[0]++; 3002 else if (columnUpper[iColumn]==1.0) 3003 cType[8]++; 3004 else if (columnUpper[iColumn]==0.0) 3005 cType[5]++; 3006 else 3007 cType[1]++; 3008 } else { 3009 if (columnUpper[iColumn]>1.0e20) 3010 cType[2]++; 3011 else if (columnUpper[iColumn]==columnLower[iColumn]) 3012 cType[5]++; 3013 else 3014 cType[3]++; 3015 } 3016 } else { 3017 if (columnUpper[iColumn]>1.0e20) 3018 cType[4]++; 3019 else if (columnUpper[iColumn]==0.0) 3020 cType[6]++; 3021 else 3022 cType[7]++; 3023 } 3024 } 3025 /* rType 3026 0 E 0, 1 E 1, 2 E 1, 3 E other, 4 G 0, 5 G 1, 6 G other, 3027 7 L 0, 8 L 1, 9 L other, 10 Range 0/1, 11 Range other, 12 free 3028 */ 3029 int rType[13]; 3030 std::string rName[]={"E 0.0,","E 1.0,","E 1.0,","E other,","G 0.0,","G 1.0,","G other,", 3031 "L 0.0,","L 1.0,","L other,","Range 0.0>1.0,","Range other,","Free"}; 3032 memset(rType,0,sizeof(rType)); 3033 for (iRow=0;iRow<numberRows;iRow++) { 3034 if (rowLower[iRow]>1.0e20) { 3035 if (rowLower[iRow]==0.0) { 3036 if (rowUpper[iRow]>1.0e20) 3037 rType[4]++; 3038 else if (rowUpper[iRow]==1.0) 3039 rType[10]++; 3040 else if (rowUpper[iRow]==0.0) 3041 rType[0]++; 3042 else 3043 rType[11]++; 3044 } else if (rowLower[iRow]==1.0) { 3045 if (rowUpper[iRow]>1.0e20) 3046 rType[5]++; 3047 else if (rowUpper[iRow]==rowLower[iRow]) 3048 rType[1]++; 3049 else 3050 rType[11]++; 3051 } else if (rowLower[iRow]==1.0) { 3052 if (rowUpper[iRow]>1.0e20) 3053 rType[6]++; 3054 else if (rowUpper[iRow]==rowLower[iRow]) 3055 rType[2]++; 3056 else 3057 rType[11]++; 3058 } else { 3059 if (rowUpper[iRow]>1.0e20) 3060 rType[6]++; 3061 else if (rowUpper[iRow]==rowLower[iRow]) 3062 rType[3]++; 3063 else 3064 rType[11]++; 3065 } 3066 } else { 3067 if (rowUpper[iRow]>1.0e20) 3068 rType[12]++; 3069 else if (rowUpper[iRow]==0.0) 3070 rType[7]++; 3071 else if (rowUpper[iRow]==1.0) 3072 rType[8]++; 3073 else 3074 rType[9]++; 3075 } 3076 } 3077 // Basic statistics 3078 printf("\n\nProblem has %d rows, %d columns (%d with objective) and %d elements\n", 3079 numberRows,numberColumns,nObjective,numberElements); 3080 if (number[0]+number[1]) { 3081 printf("There are "); 3082 if (numberObjSingletons) 3083 printf("%d singletons with objective ",numberObjSingletons); 3084 int numberNoObj = number[1]numberObjSingletons; 3085 if (numberNoObj) 3086 printf("%d singletons with no objective ",numberNoObj); 3087 if (number[0]) 3088 printf("** %d columns have no entries",number[0]); 3089 printf("\n"); 3090 } 3091 printf("Column breakdown:\n"); 3092 int k; 3093 for (k=0;k<(int) (sizeof(cType)/sizeof(int));k++) { 3094 printf("%d of type %s ",cType[k],cName[k].c_str()); 3095 if (((k+1)%3)==0) 3096 printf("\n"); 3097 } 3098 if ((k%3)!=0) 3099 printf("\n"); 3100 printf("Row breakdown:\n"); 3101 for (k=0;k<(int) (sizeof(rType)/sizeof(int));k++) { 3102 printf("%d of type %s ",rType[k],rName[k].c_str()); 3103 if (((k+1)%3)==0) 3104 printf("\n"); 3105 } 3106 if ((k%3)!=0) 3107 printf("\n"); 3108 if (model>logLevel()<2) 3109 return ; 3110 int kMax = model>logLevel()>3 ? 1000000 : 10; 3111 k=0; 3112 for (iRow=1;iRow<=numberRows;iRow++) { 3113 if (number[iRow]) { 3114 k++; 3115 printf("%d columns have %d entries\n",number[iRow],iRow); 3116 if (k==kMax) 3117 break; 3118 } 3119 } 3120 if (k<numberRows) { 3121 int kk=k; 3122 k=0; 3123 for (iRow=numberRows;iRow>=1;iRow) { 3124 if (number[iRow]) { 3125 k++; 3126 if (k==kMax) 3127 break; 3128 } 3129 } 3130 if (k>kk) { 3131 printf("\n .........\n\n"); 3132 iRow=k; 3133 k=0; 3134 for (;iRow<numberRows;iRow++) { 3135 if (number[iRow]) { 3136 k++; 3137 printf("%d columns have %d entries\n",number[iRow],iRow); 3138 if (k==kMax) 3139 break; 3140 } 3141 } 3142 } 3143 } 3144 delete [] number; 3145 printf("\n\n"); 3146 // get row copy 3147 CoinPackedMatrix rowCopy = *matrix; 3148 rowCopy.reverseOrdering(); 3149 //const int * column = rowCopy.getIndices(); 3150 const int * rowLength = rowCopy.getVectorLengths(); 3151 //const CoinBigIndex * rowStart = rowCopy.getVectorStarts(); 3152 //const double * element = rowCopy.getElements(); 3153 number = new int[numberColumns+1]; 3154 memset(number,0,(numberColumns+1)*sizeof(int)); 3155 for (iRow=0;iRow<numberRows;iRow++) { 3156 int length=rowLength[iRow]; 3157 number[length]++; 3158 } 3159 if (number[0]) 3160 printf("** %d rows have no entries\n",number[0]); 3161 k=0; 3162 for (iColumn=1;iColumn<=numberColumns;iColumn++) { 3163 if (number[iColumn]) { 3164 k++; 3165 printf("%d rows have %d entries\n",number[iColumn],iColumn); 3166 if (k==kMax) 3167 break; 3168 } 3169 } 3170 if (k<numberColumns) { 3171 int kk=k; 3172 k=0; 3173 for (iColumn=numberColumns;iColumn>=1;iColumn) { 3174 if (number[iColumn]) { 3175 k++; 3176 if (k==kMax) 3177 break; 3178 } 3179 } 3180 if (k>kk) { 3181 printf("\n .........\n\n"); 3182 iColumn=k; 3183 k=0; 3184 for (;iColumn<numberColumns;iColumn++) { 3185 if (number[iColumn]) { 3186 k++; 3187 printf("%d rows have %d entries\n",number[iColumn],iColumn); 3188 if (k==kMax) 3189 break; 3190 } 3191 } 3192 } 3193 } 3194 delete [] number; 3195 // Now do breakdown of ranges 3196 breakdown("Elements",numberElements,elementByColumn); 3197 breakdown("RowLower",numberRows,rowLower); 3198 breakdown("RowUpper",numberRows,rowUpper); 3199 breakdown("ColumnLower",numberColumns,columnLower); 3200 breakdown("ColumnUpper",numberColumns,columnUpper); 3201 breakdown("Objective",numberColumns,objective); 3202 } 2828 3203 /* 2829 3204 Version 1.00.00 November 16 2005. … … 2844 3219 Added use of CbcStrategy to do clean preprocessing 2845 3220 Added use of referenceSolver for cleaner repetition of Cbc 3221 Version 1.01.00 February 2 2006 3222 Added first try at Ampl interface 2846 3223 */
Note: See TracChangeset
for help on using the changeset viewer.