Changes from stable/2.8/Cbc/src/CbcSolver.cpp at r2102 to trunk/Cbc/src/CbcSolver.cpp at r2108
 File:

 1 edited
Legend:
 Unmodified
 Added
 Removed

trunk/Cbc/src/CbcSolver.cpp
r2102 r2108 50 50 #include "OsiAuxInfo.hpp" 51 51 #include "CbcMipStartIO.hpp" 52 // for printing 53 #ifndef CLP_OUTPUT_FORMAT 54 #define CLP_OUTPUT_FORMAT %15.8g 55 #endif 56 #define CLP_QUOTE(s) CLP_STRING(s) 57 #define CLP_STRING(s) #s 52 58 53 59 #include "CbcSolverHeuristics.hpp" … … 446 452 for (i = 0; i < numberCutGenerators_; i++) 447 453 delete cutGenerator_[i]; 448 delete [] cutGenerator_;449 454 delete [] statusUserFunction_; 450 455 delete originalSolver_; … … 452 457 statusUserFunction_ = NULL; 453 458 delete babModel_; 454 delete [] parameters_;455 459 delete callBack_; 456 460 numberUserFunctions_ = rhs.numberUserFunctions_; … … 657 661 parameters_[whichParam(CBC_PARAM_STR_FPUMP, numberParameters_, parameters_)].setCurrentOption("on"); 658 662 parameters_[whichParam(CBC_PARAM_STR_GREEDY, numberParameters_, parameters_)].setCurrentOption("on"); 659 parameters_[whichParam(CBC_PARAM_STR_COMBINE, numberParameters_, parameters_)].setCurrentOption("o ff");663 parameters_[whichParam(CBC_PARAM_STR_COMBINE, numberParameters_, parameters_)].setCurrentOption("on"); 660 664 parameters_[whichParam(CBC_PARAM_STR_CROSSOVER2, numberParameters_, parameters_)].setCurrentOption("off"); 661 665 parameters_[whichParam(CBC_PARAM_STR_PIVOTANDCOMPLEMENT, numberParameters_, parameters_)].setCurrentOption("off"); … … 1159 1163 return CbcMain1(argc, argv, model, dummyCallBack); 1160 1164 } 1165 1161 1166 #ifdef CBC_THREAD_SAFE 1162 1167 // Copies of some input decoding … … 1270 1275 { 1271 1276 } 1277 1272 1278 /* 1273 1279 Meaning of whereFrom: … … 1289 1295 return CbcMain1(argc,argv,model,callBack,staticParameterData); 1290 1296 } 1291 #ifdef GENERAL_HANDLER_PRINTING1292 1297 static void printGeneralMessage(CbcModel &model,const char * message); 1293 #endif1294 1298 /* 1295 1299 Meaning of whereFrom: … … 1311 1315 bool noPrinting = parameterData.noPrinting_; 1312 1316 bool useSignalHandler = parameterData.useSignalHandler_; 1313 #ifdef GENERAL_HANDLER_PRINTING1314 //char printByHandler[1000];1315 #endif1316 1317 CbcModel & model_ = model; 1317 1318 #ifdef CBC_THREAD_SAFE … … 1835 1836 int iParam; 1836 1837 iParam = whichParam(CBC_PARAM_INT_DIVEOPT, numberParameters_, parameters_); 1837 parameters_[iParam].setIntValue( 3);1838 parameters_[iParam].setIntValue(2); 1838 1839 iParam = whichParam(CBC_PARAM_INT_FPUMPITS, numberParameters_, parameters_); 1839 1840 parameters_[iParam].setIntValue(30); … … 2260 2261 else if (parameters_[iParam].type() == CBC_PARAM_INT_EXPERIMENT) { 2261 2262 int addFlags=0; 2263 // switch on some later features if >999 2264 if (value>999) { 2265 int switchValue=value/1000; 2266 const char * message = NULL; 2267 value = 1000*switchValue; 2268 parameters_[whichParam(CBC_PARAM_INT_EXPERIMENT, numberParameters_, parameters_)].setIntValue(0/*value*/); 2269 switch (switchValue) { 2270 default: 2271 case 4: 2272 // hotstart 500, 200 cut passes 2273 message=parameters_[whichParam(CBC_PARAM_INT_MAXHOTITS, numberParameters_, parameters_)].setIntValueWithMessage(500); 2274 if (!noPrinting_&&message) 2275 generalMessageHandler>message(CLP_GENERAL, generalMessages) 2276 << message << CoinMessageEol; 2277 message=parameters_[whichParam(CBC_PARAM_INT_CUTPASS, numberParameters_, parameters_)].setIntValueWithMessage(200); 2278 if (!noPrinting_&&message) 2279 generalMessageHandler>message(CLP_GENERAL, generalMessages) 2280 << message << CoinMessageEol; 2281 case 3: 2282 // multiple 4 2283 message=parameters_[whichParam(CBC_PARAM_INT_MULTIPLEROOTS, numberParameters_, parameters_)].setIntValueWithMessage(4); 2284 if (!noPrinting_&&message) 2285 generalMessageHandler>message(CLP_GENERAL, generalMessages) 2286 << message << CoinMessageEol; 2287 case 2: 2288 // rens plus all diving at root 2289 message=parameters_[whichParam(CBC_PARAM_INT_DIVEOPT, numberParameters_, parameters_)].setIntValueWithMessage(16); 2290 if (!noPrinting_&&message) 2291 generalMessageHandler>message(CLP_GENERAL, generalMessages) 2292 << message << CoinMessageEol; 2293 model_.setNumberAnalyzeIterations(value); 2294 // tune 7 zero,lagomory,gmi at root  probing on 2295 case 1: 2296 tunePreProcess=7; 2297 message=parameters_[whichParam(CLP_PARAM_INT_PROCESSTUNE, numberParameters_, parameters_)].setIntValueWithMessage(7); 2298 if (!noPrinting_&&message) 2299 generalMessageHandler>message(CLP_GENERAL, generalMessages) 2300 << message << CoinMessageEol; 2301 //message = parameters_[whichParam(CBC_PARAM_INT_MIPOPTIONS, numberParameters_, parameters_)].setIntValueWithMessage(1025); 2302 //if (!noPrinting_&&message) 2303 // generalMessageHandler>message(CLP_GENERAL, generalMessages) 2304 // << message << CoinMessageEol; 2305 message=parameters_[whichParam(CBC_PARAM_STR_PROBINGCUTS, numberParameters_, parameters_)].setCurrentOptionWithMessage("on"); 2306 probingAction = 1; 2307 if (!noPrinting_&&message) 2308 generalMessageHandler>message(CLP_GENERAL, generalMessages) 2309 << message << CoinMessageEol; 2310 message=parameters_[whichParam(CBC_PARAM_STR_ZEROHALFCUTS, numberParameters_, parameters_)].setCurrentOptionWithMessage("root"); 2311 if (!noPrinting_&&message) 2312 generalMessageHandler>message(CLP_GENERAL, generalMessages) 2313 << message << CoinMessageEol; 2314 message=parameters_[whichParam(CBC_PARAM_STR_LAGOMORYCUTS, numberParameters_, parameters_)].setCurrentOptionWithMessage("root"); 2315 if (!noPrinting_&&message) 2316 generalMessageHandler>message(CLP_GENERAL, generalMessages) 2317 << message << CoinMessageEol; 2318 GMIAction = 2; 2319 message=parameters_[whichParam(CBC_PARAM_STR_GMICUTS, numberParameters_, parameters_)].setCurrentOptionWithMessage("root"); 2320 if (!noPrinting_&&message) 2321 generalMessageHandler>message(CLP_GENERAL, generalMessages) 2322 << message << CoinMessageEol; 2323 } 2324 value = 0; 2325 } 2262 2326 if (value>=10) { 2263 2327 addFlags = 1048576*(value/10); … … 2569 2633 probingAction = action; 2570 2634 knapsackAction = action; 2571 zerohalfAction = action;2572 2635 cliqueAction = action; 2573 2636 flowAction = action; … … 2582 2645 parameters_[whichParam(CBC_PARAM_STR_MIXEDCUTS, numberParameters_, parameters_)].setCurrentOption(action); 2583 2646 parameters_[whichParam(CBC_PARAM_STR_TWOMIRCUTS, numberParameters_, parameters_)].setCurrentOption(action); 2584 parameters_[whichParam(CBC_PARAM_STR_ZEROHALFCUTS, numberParameters_, parameters_)].setCurrentOption(action);2585 2647 if (!action) { 2648 zerohalfAction = action; 2649 parameters_[whichParam(CBC_PARAM_STR_ZEROHALFCUTS, numberParameters_, parameters_)].setCurrentOption(action); 2586 2650 redsplitAction = action; 2587 2651 parameters_[whichParam(CBC_PARAM_STR_REDSPLITCUTS, numberParameters_, parameters_)].setCurrentOption(action); … … 2988 3052 #ifdef COIN_HAS_ASL 2989 3053 if (statusUserFunction_[0]) { 2990 3054 double value = model2>getObjValue(); 2991 3055 char buf[300]; 2992 3056 int pos = 0; … … 3052 3116 #endif 3053 3117 } else { 3054 #ifndef DISALLOW_PRINTING3055 #ifdef GENERAL_HANDLER_PRINTING3056 3118 sprintf(generalPrint, "** Current model not valid"); 3057 3119 printGeneralMessage(model_,generalPrint); 3058 #else3059 std::cout << "** Current model not valid" << std::endl;3060 #endif3061 #endif3062 3120 } 3063 3121 break; … … 3095 3153 delete model2; 3096 3154 } else { 3097 #ifndef DISALLOW_PRINTING3098 #ifdef GENERAL_HANDLER_PRINTING3099 3155 sprintf(generalPrint, "** Current model not valid"); 3100 3156 printGeneralMessage(model_,generalPrint); 3101 #else3102 std::cout << "** Current model not valid" << std::endl;3103 #endif3104 #endif3105 3157 } 3106 3158 break; … … 3109 3161 int numberInfeasibilities = lpSolver>tightenPrimalBounds(); 3110 3162 if (numberInfeasibilities) { 3111 #ifdef GENERAL_HANDLER_PRINTING3112 3163 sprintf(generalPrint,"** Analysis indicates model infeasible"); 3113 3164 printGeneralMessage(model_,generalPrint); 3114 #else3115 std::cout << "** Analysis indicates model infeasible" << std::endl;3116 #endif3117 3165 } 3118 3166 } else { 3119 #ifndef DISALLOW_PRINTING3120 #ifdef GENERAL_HANDLER_PRINTING3121 3167 sprintf(generalPrint, "** Current model not valid"); 3122 3168 printGeneralMessage(model_,generalPrint); 3123 #else3124 std::cout << "** Current model not valid" << std::endl;3125 #endif3126 #endif3127 3169 } 3128 3170 break; … … 3137 3179 lpSolver>replaceMatrix(newMatrix); 3138 3180 delete saveMatrix; 3139 #ifdef GENERAL_HANDLER_PRINTING3140 3181 sprintf(generalPrint, "Matrix converted to + one matrix"); 3141 3182 printGeneralMessage(model_,generalPrint); 3142 #else3143 std::cout << "Matrix converted to + one matrix" << std::endl;3144 #endif3145 3183 } else { 3146 #ifdef GENERAL_HANDLER_PRINTING3147 3184 sprintf(generalPrint, "Matrix can not be converted to + 1 matrix"); 3148 3185 printGeneralMessage(model_,generalPrint); 3149 #else3150 std::cout << "Matrix can not be converted to + 1 matrix" << std::endl;3151 #endif3152 3186 } 3153 3187 } else { 3154 #ifdef GENERAL_HANDLER_PRINTING3155 3188 sprintf(generalPrint, "Matrix not a ClpPackedMatrix"); 3156 3189 printGeneralMessage(model_,generalPrint); 3157 #else3158 std::cout << "Matrix not a ClpPackedMatrix" << std::endl;3159 #endif3160 3190 } 3161 3191 } else { 3162 #ifndef DISALLOW_PRINTING3163 #ifdef GENERAL_HANDLER_PRINTING3164 3192 sprintf(generalPrint, "** Current model not valid"); 3165 3193 printGeneralMessage(model_,generalPrint); 3166 #else3167 std::cout << "** Current model not valid" << std::endl;3168 #endif3169 #endif3170 3194 } 3171 3195 break; … … 3185 3209 << CoinMessageEol; 3186 3210 } else { 3187 #ifndef DISALLOW_PRINTING3188 #ifdef GENERAL_HANDLER_PRINTING3189 3211 sprintf(generalPrint, "** Current model not valid"); 3190 3212 printGeneralMessage(model_,generalPrint); 3191 #else3192 std::cout << "** Current model not valid" << std::endl;3193 #endif3194 #endif3195 3213 } 3196 3214 #endif … … 3206 3224 lpSolver>replaceMatrix(newMatrix); 3207 3225 delete saveMatrix; 3208 #ifdef GENERAL_HANDLER_PRINTING3209 3226 sprintf(generalPrint, "Matrix converted to network matrix"); 3210 3227 printGeneralMessage(model_,generalPrint); 3211 #else3212 std::cout << "Matrix converted to network matrix" << std::endl;3213 #endif3214 3228 } else { 3215 #ifdef GENERAL_HANDLER_PRINTING3216 3229 sprintf(generalPrint, "Matrix can not be converted to network matrix"); 3217 3230 printGeneralMessage(model_,generalPrint); 3218 #else3219 std::cout << "Matrix can not be converted to network matrix" << std::endl;3220 #endif3221 3231 } 3222 3232 } else { 3223 #ifdef GENERAL_HANDLER_PRINTING3224 3233 sprintf(generalPrint, "Matrix not a ClpPackedMatrix"); 3225 3234 printGeneralMessage(model_,generalPrint); 3226 #else3227 std::cout << "Matrix not a ClpPackedMatrix" << std::endl;3228 #endif3229 3235 } 3230 3236 } else { 3231 #ifndef DISALLOW_PRINTING3232 #ifdef GENERAL_HANDLER_PRINTING3233 3237 sprintf(generalPrint, "** Current model not valid"); 3234 3238 printGeneralMessage(model_,generalPrint); 3235 #else3236 std::cout << "** Current model not valid" << std::endl;3237 #endif3238 #endif3239 3239 } 3240 3240 break; 3241 3241 case CBC_PARAM_ACTION_DOHEURISTIC: 3242 3242 if (goodModel) { 3243 #ifndef CBC_USE_INITIAL_TIME 3244 if (model_.useElapsedTime()) 3245 model_.setDblParam(CbcModel::CbcStartSeconds, CoinGetTimeOfDay()); 3246 else 3247 model_.setDblParam(CbcModel::CbcStartSeconds, CoinCpuTime()); 3248 #endif 3243 3249 int vubAction = parameters_[whichParam(CBC_PARAM_INT_VUBTRY, numberParameters_, parameters_)].intValue(); 3244 3250 if (vubAction != 1) { … … 3271 3277 } 3272 3278 // Actually do heuristics 3279 // may need to flip objective 3280 bool needFlip = model_.solver()>getObjSense()<0.0; 3281 if (needFlip) 3282 model_.flipModel(); 3283 //if we do then  fix priorities in clonebutmodel_.convertToDynamic(); 3284 bool objectsExist = model_.objects() != NULL; 3285 if (!objectsExist) { 3286 model_.findIntegers(false); 3287 model_.convertToDynamic(); 3288 } 3289 // set priorities etc 3290 if (priorities) { 3291 OsiObject ** objects = model_.objects(); 3292 int numberObjects = model_.numberObjects(); 3293 for (int iObj = 0; iObj < numberObjects; iObj++) { 3294 CbcSimpleInteger * obj = 3295 dynamic_cast <CbcSimpleInteger *>(objects[iObj]) ; 3296 if (!obj) 3297 continue; 3298 int iColumn = obj>columnNumber(); 3299 if (branchDirection) { 3300 obj>setPreferredWay(branchDirection[iColumn]); 3301 } 3302 if (priorities) { 3303 int iPriority = priorities[iColumn]; 3304 if (iPriority > 0) 3305 obj>setPriority(iPriority); 3306 } 3307 if (pseudoUp && pseudoUp[iColumn]) { 3308 CbcSimpleIntegerPseudoCost * obj1a = 3309 dynamic_cast <CbcSimpleIntegerPseudoCost *>(objects[iObj]) ; 3310 assert (obj1a); 3311 if (pseudoDown[iColumn] > 0.0) 3312 obj1a>setDownPseudoCost(pseudoDown[iColumn]); 3313 if (pseudoUp[iColumn] > 0.0) 3314 obj1a>setUpPseudoCost(pseudoUp[iColumn]); 3315 } 3316 } 3317 } 3273 3318 doHeuristics(&model_, 2, parameters_, 3274 3319 numberParameters_, noPrinting_, initialPumpTune); 3320 if (!objectsExist) { 3321 model_.deleteObjects(false); 3322 } 3323 if (needFlip) 3324 model_.flipModel(); 3275 3325 if (model_.bestSolution()) { 3276 3326 model_.setProblemStatus(1); … … 3329 3379 // User can set options  main difference is lack of model and CglPreProcess 3330 3380 goodModel = true; 3381 parameters_[whichParam(CBC_PARAM_INT_MULTIPLEROOTS, numberParameters_, parameters_)].setIntValue(0); 3331 3382 /* 3332 3383 Run branchandcut. First set a few options  node comparison, scaling. … … 3339 3390 int logLevel = parameters_[slog].intValue(); 3340 3391 int truncateColumns=COIN_INT_MAX; 3392 int truncateRows=1; 3393 double * truncatedRhsLower=NULL; 3394 double * truncatedRhsUpper=NULL; 3341 3395 int * newPriorities=NULL; 3342 3396 // Reduce printout … … 3523 3577 cbcModel>initialSolve(); 3524 3578 if (clpModel>tightenPrimalBounds() != 0) { 3525 #ifndef DISALLOW_PRINTING3526 #ifdef GENERAL_HANDLER_PRINTING3527 3579 sprintf(generalPrint, "Problem is infeasible  tightenPrimalBounds!"); 3528 3580 printGeneralMessage(model_,generalPrint); 3529 #else3530 std::cout << "Problem is infeasible  tightenPrimalBounds!" << std::endl;3531 #endif3532 #endif3533 3581 break; 3534 3582 } … … 3700 3748 #ifndef CBC_OTHER_SOLVER 3701 3749 if (!complicatedInteger && preProcess == 0 && clpSolver>tightenPrimalBounds(0.0, 0, true) != 0) { 3702 #ifndef DISALLOW_PRINTING3703 #ifdef GENERAL_HANDLER_PRINTING3704 3750 sprintf(generalPrint, "Problem is infeasible  tightenPrimalBounds!"); 3705 3751 printGeneralMessage(model_,generalPrint); 3706 #else3707 std::cout << "Problem is infeasible  tightenPrimalBounds!" << std::endl;3708 #endif3709 #endif3710 3752 model_.setProblemStatus(0); 3711 3753 model_.setSecondaryStatus(1); 3754 // say infeasible for solution 3755 integerStatus = 6; 3712 3756 // and in babModel if exists 3713 3757 if (babModel_) { … … 3810 3854 if (tightenFactor && !complicatedInteger) { 3811 3855 if (modelC>tightenPrimalBounds(tightenFactor) != 0) { 3812 #ifndef DISALLOW_PRINTING3813 #ifdef GENERAL_HANDLER_PRINTING3814 3856 sprintf(generalPrint, "Problem is infeasible!"); 3815 3857 printGeneralMessage(model_,generalPrint); 3816 #else3817 std::cout << "Problem is infeasible!" << std::endl;3818 #endif3819 #endif3820 3858 model_.setProblemStatus(0); 3821 3859 model_.setSecondaryStatus(1); … … 3916 3954 { 3917 3955 CbcModel tempModel=*babModel_; 3956 assert (babModel_>getNumCols()==model_.getNumCols()); 3918 3957 std::vector< std::string > colNames; 3919 for ( int i=0 ; (i< babModel_>solver()>getNumCols()) ; ++i )3958 for ( int i=0 ; (i<model_.solver()>getNumCols()) ; ++i ) 3920 3959 colNames.push_back( model_.solver()>getColName(i) ); 3921 std::vector< double > x( babModel_>getNumCols(), 0.0 );3960 std::vector< double > x( model_.getNumCols(), 0.0 ); 3922 3961 double obj; 3923 3962 int status = computeCompleteSolution( &tempModel, colNames, mipStartBefore, &x[0], obj ); 3924 3963 // set cutoff 3925 if (!status) 3964 if (!status) { 3926 3965 babModel_>setCutoff(CoinMin(babModel_>getCutoff(),obj+1.0e4)); 3966 babModel_>setBestSolution( &x[0], static_cast<int>(x.size()), obj, false ); 3967 babModel_>setSolutionCount(1); 3968 model_.setCutoff(CoinMin(model_.getCutoff(),obj+1.0e4)); 3969 model_.setBestSolution( &x[0], static_cast<int>(x.size()), obj, false ); 3970 model_.setSolutionCount(1); 3971 } 3927 3972 } 3928 3973 if (preProcess && type == CBC_PARAM_ACTION_BAB) { … … 3982 4027 // heavy probing 3983 4028 generator1.setMaxPassRoot(2); 3984 generator1.setMaxElements( 300);4029 generator1.setMaxElements(1000); 3985 4030 generator1.setMaxProbeRoot(saveSolver>getNumCols()); 4031 generator1.setMaxLookRoot(saveSolver>getNumCols()); 3986 4032 } 3987 4033 if ((babModel_>specialOptions()&65536) != 0) … … 4045 4091 OsiObject ** oldObjects = babModel_>objects(); 4046 4092 int numberOldObjects = babModel_>numberObjects(); 4093 if (!numberOldObjects) { 4094 oldObjects = model_.objects(); 4095 numberOldObjects = model_.numberObjects(); 4096 } 4047 4097 // SOS 4048 4098 int numberColumns = saveSolver>getNumCols(); … … 4075 4125 } 4076 4126 int numberPasses = 10; 4077 if (tunePreProcess >= 1000000) {4078 numberPasses = (tunePreProcess / 1000000)  1;4079 tunePreProcess = tunePreProcess % 1000000;4080 } else if (tunePreProcess >= 10000) {4081 numberPasses = (tunePreProcess / 10000)  1;4082 tunePreProcess = tunePreProcess % 10000;4083 }4084 4127 #ifndef CBC_OTHER_SOLVER 4085 4128 if (doSprint > 0) { … … 4117 4160 process.setOptions(2+4+8); // no cuts 4118 4161 cbcPreProcessPointer = & process; 4162 int saveOptions = osiclp>getModelPtr()>moreSpecialOptions(); 4163 if ((model_.specialOptions()&16777216)!=0&& 4164 model_.getCutoff()>1.0e30) { 4165 osiclp>getModelPtr()>setMoreSpecialOptions(saveOptions262144); 4166 } 4119 4167 solver2 = process.preProcessNonDefault(*saveSolver, translate[preProcess], numberPasses, 4120 4168 tunePreProcess); … … 4122 4170 saveSolver>writeMps("before");*/ 4123 4171 osiclp>getModelPtr()>setPerturbation(savePerturbation); 4172 osiclp>getModelPtr()>setMoreSpecialOptions(saveOptions); 4124 4173 } 4125 4174 #elif CBC_OTHER_SOLVER==1 … … 4159 4208 // say infeasible for solution 4160 4209 integerStatus = 6; 4210 delete saveSolver; 4211 saveSolver=NULL; 4161 4212 model_.setProblemStatus(0); 4162 4213 model_.setSecondaryStatus(1); … … 4193 4244 if (preProcess == 2) { 4194 4245 OsiClpSolverInterface * clpSolver2 = dynamic_cast< OsiClpSolverInterface*> (solver2); 4195 #if 1 4196 ClpSimplex * lpSolver = 4197 clpSolver2>getModelPtr(); 4246 ClpSimplex * lpSolver = clpSolver2>getModelPtr(); 4198 4247 lpSolver>writeMps("presolved.mps", 0, 1, lpSolver>optimizationDirection()); 4199 #else4200 // put back names4201 ClpSimplex lpSolver(*clpSolver2>getModelPtr());4202 //OsiClpSolverInterface * originalSolver = dynamic_cast< OsiClpSolverInterface*> (olver);4203 ClpSimplex * originalLp = clpSolver>getModelPtr();4204 const int * originalColumns = process.originalColumns();4205 int numberColumns = lpSolver.getNumCols();4206 for (int i = 0; i < numberColumns; i++) {4207 int jColumn = originalColumns[i];4208 std::string name = originalLp>getColumnName(jColumn);4209 lpSolver.setColumnName(i,name);4210 }4211 lpSolver.writeMps("presolved.mps", 0, 1, lpSolver.optimizationDirection());4212 #endif4213 4248 printf("Preprocessed model (minimization) on presolved.mps\n"); 4214 4249 } … … 4234 4269 int threshold = 4235 4270 parameters_[whichParam(CBC_PARAM_INT_EXTRA_VARIABLES, numberParameters_, parameters_)].intValue(); 4236 if (threshold) { 4271 int more2 = parameters_[whichParam(CBC_PARAM_INT_MOREMOREMIPOPTIONS, numberParameters_, parameters_)].intValue(); 4272 if (threshold  (more2&(5121024)) != 0) { 4237 4273 int numberColumns = solver2>getNumCols(); 4274 truncateRows = solver2>getNumRows(); 4275 bool modifiedModel=false; 4238 4276 int highPriority=0; 4239 4277 /* … … 4439 4477 lowerNew, upperNew); 4440 4478 sprintf(generalPrint,"Replacing model  %d new variables",numberDifferentObj); 4441 generalMessageHandler>message(CLP_GENERAL, generalMessages) 4442 << generalPrint 4443 << CoinMessageEol; 4444 truncateColumns=numberColumns; 4479 modifiedModel=true; 4445 4480 } 4446 4481 delete [] columnAdd; … … 4451 4486 delete [] which; 4452 4487 delete [] obj; 4488 if ((more2&(5121024)) != 0) { 4489 // try for row slacks etc 4490 // later do row branching 4491 int iRow, iColumn; 4492 int numberColumns = solver2>getNumCols(); 4493 int numberRows = solver2>getNumRows(); 4494 int fudgeObjective = more2&512; 4495 int addSlacks = more2&1024; 4496 if (fudgeObjective) { 4497 bool moveObj = false; 4498 fudgeObjective = 0; 4499 const double * objective = solver2>getObjCoefficients(); 4500 const double * columnLower = solver2>getColLower(); 4501 const double * columnUpper = solver2>getColUpper(); 4502 double * newValues = new double [numberColumns+1]; 4503 int * newColumn = new int [numberColumns+1]; 4504 bool allInteger=true; 4505 int n=0; 4506 double newLower = 0.0; 4507 double newUpper = 0.0; 4508 for (iColumn=0;iColumn<numberColumns;iColumn++) { 4509 if (objective[iColumn]) { 4510 if (!solver2>isInteger(iColumn)) { 4511 allInteger=false; 4512 break; 4513 } else { 4514 double value = objective[iColumn]; 4515 double nearest = floor(value+0.5); 4516 if (fabs(valuenearest)>1.0e8) { 4517 allInteger=false; 4518 break; 4519 } else { 4520 newValues[n]=nearest; 4521 newColumn[n++]=iColumn; 4522 if (nearest>0.0) { 4523 newLower += CoinMax(columnLower[iColumn],1.0e20)*nearest; 4524 newUpper += CoinMin(columnUpper[iColumn],1.0e20)*nearest; 4525 } else { 4526 newUpper += CoinMax(columnLower[iColumn],1.0e20)*nearest; 4527 newLower += CoinMin(columnUpper[iColumn],1.0e20)*nearest; 4528 } 4529 } 4530 } 4531 } 4532 } 4533 if (allInteger && n) { 4534 fudgeObjective = n; 4535 solver2>addCol(0,NULL,NULL,newLower,newUpper,0.0,"obj_col"); 4536 solver2>setInteger(numberColumns); 4537 newValues[n]=1.0; 4538 newColumn[n++]=numberColumns; 4539 solver2>addRow(n,newColumn,newValues,0.0,0.0); 4540 if (moveObj) { 4541 memset(newValues,0,numberColumns*sizeof(double)); 4542 newValues[numberColumns]=1.0; 4543 solver2>setObjective(newValues); 4544 } 4545 numberRows++; 4546 numberColumns++; 4547 } 4548 delete [] newValues; 4549 delete [] newColumn; 4550 } 4551 if (addSlacks) { 4552 bool moveObj = false; 4553 addSlacks=0; 4554 // get row copy 4555 const CoinPackedMatrix * matrix = solver2>getMatrixByRow(); 4556 const double * element = matrix>getElements(); 4557 const int * column = matrix>getIndices(); 4558 const CoinBigIndex * rowStart = matrix>getVectorStarts(); 4559 const int * rowLength = matrix>getVectorLengths(); 4560 const double * rowLower = solver2>getRowLower(); 4561 const double * rowUpper = solver2>getRowUpper(); 4562 const double * columnLower = solver2>getColLower(); 4563 const double * columnUpper = solver2>getColUpper(); 4564 4565 // maximum space for additional columns 4566 CoinBigIndex * newColumnStart = new CoinBigIndex[numberRows+1]; 4567 newColumnStart[0]=0; 4568 int * newRow = new int [numberRows]; 4569 double * newElement = new double [numberRows]; 4570 double * newObjective = new double [numberRows]; 4571 double * newColumnLower = new double [numberRows]; 4572 double * newColumnUpper = new double [numberRows]; 4573 double * oldObjective = CoinCopyOfArray(solver2>getObjCoefficients(), 4574 numberColumns); 4575 for (iRow=0;iRow<numberRows;iRow++) { 4576 if (rowLower[iRow]!=rowUpper[iRow]) { 4577 bool allInteger=true; 4578 double newLower = 0.0; 4579 double newUpper = 0.0; 4580 double constantObjective=0.0; 4581 for (int j=rowStart[iRow];j<rowStart[iRow]+rowLength[iRow];j++) { 4582 int iColumn = column[j]; 4583 if (!solver2>isInteger(iColumn)) { 4584 allInteger=false; 4585 break; 4586 } else { 4587 double value = element[j]; 4588 double nearest = floor(value+0.5); 4589 if (fabs(valuenearest)>1.0e8) { 4590 allInteger=false; 4591 break; 4592 } else { 4593 if (!oldObjective[iColumn]) 4594 constantObjective=COIN_DBL_MAX; 4595 if (!constantObjective) { 4596 constantObjective=oldObjective[iColumn]/nearest; 4597 } else if (constantObjective!=COIN_DBL_MAX) { 4598 double newConstant=oldObjective[iColumn]/nearest; 4599 if (constantObjective>0.0) { 4600 if (newConstant<=0.0) 4601 constantObjective=COIN_DBL_MAX; 4602 else 4603 constantObjective=CoinMin(constantObjective,newConstant); 4604 } else { 4605 if (newConstant>=0.0) 4606 constantObjective=COIN_DBL_MAX; 4607 else 4608 constantObjective=CoinMax(constantObjective,newConstant); 4609 } 4610 } 4611 if (nearest>0.0) { 4612 newLower += CoinMax(columnLower[iColumn],1.0e20)*nearest; 4613 newUpper += CoinMin(columnUpper[iColumn],1.0e20)*nearest; 4614 } else { 4615 newUpper += CoinMax(columnLower[iColumn],1.0e20)*nearest; 4616 newLower += CoinMin(columnUpper[iColumn],1.0e20)*nearest; 4617 } 4618 } 4619 } 4620 } 4621 if (allInteger) { 4622 newColumnStart[addSlacks+1]=addSlacks+1; 4623 newRow[addSlacks]=iRow; 4624 newElement[addSlacks]=1.0; 4625 newObjective[addSlacks] = 0.0; 4626 if (moveObj && constantObjective != COIN_DBL_MAX) { 4627 // move some of objective here if looks constant 4628 newObjective[addSlacks]=constantObjective; 4629 for (int j=rowStart[iRow];j<rowStart[iRow]+rowLength[iRow];j++) { 4630 int iColumn = column[j]; 4631 double value = element[j]; 4632 double nearest = floor(value+0.5); 4633 oldObjective[iColumn] = nearest*constantObjective; 4634 } 4635 } 4636 newColumnLower[addSlacks] = CoinMax(newLower,ceil(rowLower[iRow]));; 4637 newColumnUpper[addSlacks] = CoinMin(newUpper,floor(rowUpper[iRow])); 4638 addSlacks++; 4639 } 4640 } 4641 } 4642 if (addSlacks) { 4643 solver2>setObjective(oldObjective); 4644 solver2>addCols(addSlacks,newColumnStart,newRow,newElement, 4645 newColumnLower,newColumnUpper,newObjective); 4646 truncatedRhsLower = CoinCopyOfArray(solver2>getRowLower(),numberRows); 4647 truncatedRhsUpper = CoinCopyOfArray(solver2>getRowUpper(),numberRows); 4648 for (int j=0;j<addSlacks;j++) { 4649 int iRow = newRow[j]; 4650 solver2>setRowLower(iRow,0.0); 4651 solver2>setRowUpper(iRow,0.0); 4652 int iColumn = j+numberColumns; 4653 solver2>setInteger(iColumn); 4654 std::string name = solver2>getRowName(iRow); 4655 name += "_int"; 4656 solver2>setColName(iColumn,name); 4657 } 4658 } 4659 } 4660 if (fudgeObjectiveaddSlacks) { 4661 modifiedModel=true; 4662 if (fudgeObjective && addSlacks) { 4663 sprintf(generalPrint,"Objective integer added with %d elements and %d Integer slacks added", 4664 fudgeObjective,addSlacks); 4665 } else if (fudgeObjective) { 4666 // just objective 4667 sprintf(generalPrint,"Objective integer added with %d elements", 4668 fudgeObjective); 4669 more2 &= ~1024; 4670 } else { 4671 // just slacks 4672 sprintf(generalPrint,"%d Integer slacks added",addSlacks); 4673 more2 &= ~512; 4674 } 4675 } else { 4676 more2 &= ~(5121024); 4677 } 4678 parameters_[whichParam(CBC_PARAM_INT_MOREMOREMIPOPTIONS, numberParameters_, parameters_)].setIntValue(more2); 4679 } 4680 if (modifiedModel) { 4681 generalMessageHandler>message(CLP_GENERAL, generalMessages) 4682 << generalPrint 4683 << CoinMessageEol; 4684 truncateColumns=numberColumns; 4685 } 4453 4686 } 4454 4687 babModel_>assignSolver(solver2); … … 4469 4702 //modelC>setLogLevel(0); 4470 4703 if (!complicatedInteger && modelC>tightenPrimalBounds() != 0) { 4471 #ifndef DISALLOW_PRINTING4472 #ifdef GENERAL_HANDLER_PRINTING4473 4704 sprintf(generalPrint, "Problem is infeasible!"); 4474 4705 printGeneralMessage(model_,generalPrint); 4475 #else4476 std::cout << "Problem is infeasible!" << std::endl;4477 #endif4478 #endif4479 4706 model_.setProblemStatus(0); 4480 4707 model_.setSecondaryStatus(1); 4481 4708 // say infeasible for solution 4482 4709 integerStatus = 6; 4710 delete saveSolver; 4711 saveSolver=NULL; 4483 4712 // and in babModel_ if exists 4484 4713 if (babModel_) { … … 4665 4894 probingGen.setMaxPassRoot(2); 4666 4895 probingGen.setMaxProbeRoot(numberColumns); 4667 probingGen.setMaxLookRoot( 100);4896 probingGen.setMaxLookRoot(numberColumns); 4668 4897 } 4669 4898 // If 5 then force on … … 4838 5067 babModel_>addCutGenerator(&flowGen, translate[flowAction], "FlowCover"); 4839 5068 accuracyFlag[numberGenerators] = 2; 4840 switches[numberGenerators++] = 1;5069 switches[numberGenerators++] = 0; 4841 5070 } 4842 5071 if (twomirAction && (complicatedInteger != 1  … … 4919 5148 babModel_>addCutGenerator(&zerohalfGen, translate[zerohalfAction], "ZeroHalf"); 4920 5149 accuracyFlag[numberGenerators] = 5; 5150 babModel_>cutGenerator(numberGenerators)> 5151 setNeedsRefresh(true); 4921 5152 switches[numberGenerators++] = 2; 4922 5153 } … … 5069 5300 // Used to be automatically set 5070 5301 int mipOptions = parameters_[whichParam(CBC_PARAM_INT_MIPOPTIONS, numberParameters_, parameters_)].intValue() % 10000; 5071 if (mipOptions != (1057) ) {5302 if (mipOptions != (1057) && mipOptions != 1025 ) { 5072 5303 sprintf(generalPrint, "mip options %d", mipOptions); 5073 5304 generalMessageHandler>message(CLP_GENERAL, generalMessages) … … 5190 5421 #endif 5191 5422 const int * originalColumns = preProcess ? process.originalColumns() : NULL; 5423 //if (model.getMIPStart().size()) 5424 // mipStart = model.getMIPStart(); 5192 5425 if (mipStart.size() && !mipStartBefore.size()) 5193 5426 { … … 5219 5452 double obj; 5220 5453 int status = computeCompleteSolution( babModel_, colNames, mipStart, &x[0], obj ); 5221 if (!status) 5454 if (!status) { 5222 5455 babModel_>setBestSolution( &x[0], static_cast<int>(x.size()), obj, false ); 5456 babModel_>setSolutionCount(1); 5457 } 5223 5458 } 5224 5459 … … 5412 5647 int iStart = starts[iSOS]; 5413 5648 int n = starts[iSOS+1]  iStart; 5649 //#define MAKE_SOS_CLIQUES 5650 #ifndef MAKE_SOS_CLIQUES 5414 5651 objects[iSOS] = new CbcSOS(babModel_, n, which + iStart, weight + iStart, 5415 5652 iSOS, type[iSOS]); 5653 #else 5654 objects[iSOS] = 5655 new CbcClique(babModel_, 1, n, which + iStart, 5656 NULL,iSOS1); 5657 #endif 5416 5658 // branch on long sets first 5417 5659 objects[iSOS]>setPriority(numberColumns  n); … … 5506 5748 if (objSOS) 5507 5749 continue; 5750 #ifdef MAKE_SOS_CLIQUES 5751 // skip cliques 5752 CbcClique * objClique = 5753 dynamic_cast <CbcClique *>(objects[iObj]) ; 5754 if (objClique) 5755 continue; 5756 #endif 5508 5757 int iColumn = objects[iObj]>columnNumber(); 5509 5758 assert (iColumn >= 0); … … 6151 6400 osiclp = dynamic_cast< OsiClpSolverInterface*> (babModel_>solver()); 6152 6401 lpSolver = osiclp>getModelPtr(); 6402 int hotits = parameters_[whichParam(CBC_PARAM_INT_MAXHOTITS, numberParameters_, parameters_)].intValue(); 6403 if (hotits>100) { 6404 osiclp>setSpecialOptions(osiclp>specialOptions()&~32); 6405 osiclp>setIntParam(OsiMaxNumIterationHotStart, hotits); 6406 } else { 6407 osiclp>setIntParam(OsiMaxNumIterationHotStart, hotits); 6408 } 6153 6409 #elif CBC_OTHER_SOLVER==1 6154 6410 #endif … … 6318 6574 } 6319 6575 // We may have priorities from extra variables 6576 int more2 = parameters_[whichParam(CBC_PARAM_INT_MOREMOREMIPOPTIONS, numberParameters_, parameters_)].intValue(); 6320 6577 if(newPriorities ) { 6321 6578 if (truncateColumns<babModel_>getNumCols()) { … … 6323 6580 babModel_>passInPriorities(newPriorities,false); 6324 6581 } 6582 delete [] newPriorities; 6583 } else if ((more2&(5121024)) != 0) { 6584 babModel_>findIntegers(true); 6585 int numberIntegers = babModel_>numberIntegers(); 6586 int * newPriorities = new int [numberIntegers]; 6587 int n = numberIntegers  (babModel_>getNumCols()truncateColumns); 6588 for (int i=0;i<n;i++) 6589 newPriorities[i]=babModel_>priority(i); 6590 #if 1 6591 int ixxxxxx = 6592 parameters_[whichParam(CBC_PARAM_INT_MAXNODES, numberParameters_, parameters_)].intValue(); 6593 int obj_priority=1000; 6594 int slack_priority=1000; 6595 if (ixxxxxx>=1000000&&ixxxxxx<1010000) { 6596 ixxxxxx = 1000000; 6597 if (ixxxxxx == 0) { 6598 obj_priority=1000; 6599 slack_priority=1000; 6600 } else if(ixxxxxx == 1) { 6601 obj_priority=10000; 6602 slack_priority=10000; 6603 } else if(ixxxxxx == 2) { 6604 obj_priority=100; 6605 slack_priority=100; 6606 } else if(ixxxxxx == 3) { 6607 obj_priority=100; 6608 slack_priority=10000; 6609 } else if(ixxxxxx == 4) { 6610 obj_priority=10000; 6611 slack_priority=100; 6612 } else if(ixxxxxx == 5) { 6613 obj_priority=100; 6614 slack_priority=200; 6615 } else if(ixxxxxx == 6) { 6616 obj_priority=200; 6617 slack_priority=100; 6618 } else { 6619 abort(); 6620 } 6621 } 6622 if ((more2&512)!=0) { 6623 newPriorities[n++]=obj_priority; 6624 } 6625 if ((more2&1024)!=0) { 6626 for (int i=n;i<numberIntegers;i++) 6627 newPriorities[i]=slack_priority; 6628 } 6629 #else 6630 #define PRIORITY_TRY 0 6631 #if PRIORITY_TRY == 0 6632 #define OBJ_PRIORITY 1000 6633 #define SLACK_PRIORITY 1000 6634 #elif PRIORITY_TRY == 1 6635 #define OBJ_PRIORITY 10000 6636 #define SLACK_PRIORITY 10000 6637 #elif PRIORITY_TRY == 2 6638 #define OBJ_PRIORITY 100 6639 #define SLACK_PRIORITY 100 6640 #elif PRIORITY_TRY == 3 6641 #define OBJ_PRIORITY 100 6642 #define SLACK_PRIORITY 10000 6643 #elif PRIORITY_TRY == 4 6644 #define OBJ_PRIORITY 10000 6645 #define SLACK_PRIORITY 100 6646 #elif PRIORITY_TRY == 5 6647 #define OBJ_PRIORITY 100 6648 #define SLACK_PRIORITY 200 6649 #elif PRIORITY_TRY == 6 6650 #define OBJ_PRIORITY 200 6651 #define SLACK_PRIORITY 100 6652 #endif 6653 if ((more2&512)!=0) { 6654 newPriorities[n++]=OBJ_PRIORITY; 6655 } 6656 if ((more2&1024)!=0) { 6657 for (int i=n;i<numberIntegers;i++) 6658 newPriorities[i]=SLACK_PRIORITY; 6659 } 6660 #endif 6661 babModel_>passInPriorities(newPriorities,false); 6325 6662 delete [] newPriorities; 6326 6663 } … … 6347 6684 int jParam = whichParam(CBC_PARAM_STR_CUTOFF_CONSTRAINT, 6348 6685 numberParameters_, parameters_); 6349 if(parameters_[jParam].currentOptionAsInteger()) 6686 if(parameters_[jParam].currentOptionAsInteger()) { 6350 6687 babModel_>setCutoffAsConstraint(true); 6688 int moreOptions=babModel_>moreSpecialOptions(); 6689 if(parameters_[jParam].currentOptionAsInteger()==4) 6690 babModel_>setMoreSpecialOptions(moreOptions4194304); 6691 } 6351 6692 int multipleRoot = parameters_[whichParam(CBC_PARAM_INT_MULTIPLEROOTS, numberParameters_, parameters_)].intValue(); 6352 6693 if (multipleRoot<10000) { … … 6437 6778 if (biLinearProblem) 6438 6779 babModel_>setSpecialOptions(babModel_>specialOptions() &(~(51232768))); 6780 babModel_>setMoreSpecialOptions2(parameters_[whichParam(CBC_PARAM_INT_MOREMOREMIPOPTIONS, numberParameters_, parameters_)].intValue()); 6781 #ifdef COIN_HAS_NTY 6782 { 6783 int jParam = whichParam(CBC_PARAM_STR_ORBITAL, 6784 numberParameters_, parameters_); 6785 if(parameters_[jParam].currentOptionAsInteger()) { 6786 int k = parameters_[jParam].currentOptionAsInteger(); 6787 babModel_>setMoreSpecialOptions2(babModel_>moreSpecialOptions2()  (k*128)); 6788 } 6789 } 6790 #endif 6439 6791 babModel_>branchAndBound(statistics); 6440 6792 if (truncateColumns<babModel_>solver()>getNumCols()) { … … 6447 6799 delStuff[i]=i+truncateColumns; 6448 6800 solverX>deleteCols(numberDelete,delStuff); 6801 numberDelete = numberRowstruncateRows; 6449 6802 for (int i=0;i<numberDelete;i++) 6450 delStuff[i]=i+ numberRowsnumberDelete;6803 delStuff[i]=i+truncateRows; 6451 6804 solverX>deleteRows(numberDelete,delStuff); 6452 6805 delete [] delStuff; 6806 if (truncatedRhsLower) { 6807 numberRows=solverX>getNumRows(); 6808 for (int i=0;i<numberRows;i++) { 6809 solverX>setRowLower(i,truncatedRhsLower[i]); 6810 solverX>setRowUpper(i,truncatedRhsUpper[i]); 6811 } 6812 delete [] truncatedRhsLower; 6813 delete [] truncatedRhsUpper; 6814 } 6453 6815 } 6454 6816 //#define CLP_FACTORIZATION_INSTRUMENT … … 6659 7021 #ifndef CLP_INVESTIGATE 6660 7022 CglImplication * implication = dynamic_cast<CglImplication*>(generator>generator()); 6661 if (implication )7023 if (implication && !generator>numberCutsInTotal()) 6662 7024 continue; 6663 7025 #endif … … 6701 7063 // infeasible 6702 7064 integerStatus = 6; 7065 delete saveSolver; 7066 saveSolver=NULL; 6703 7067 } 6704 7068 } … … 7058 7422 sprintf(generalPrint + strlen(generalPrint), 7059 7423 "Gap: %.2f\n", 7060 (babModel_>getObjValue()babModel_>getBestPossibleObjValue())/babModel_>getBestPossibleObjValue()); 7424 (babModel_>getObjValue()babModel_>getBestPossibleObjValue())/ 7425 fabs(babModel_>getBestPossibleObjValue())); 7061 7426 } 7062 7427 } … … 7160 7525 #endif 7161 7526 } else { 7162 #ifdef GENERAL_HANDLER_PRINTING7163 7527 sprintf(generalPrint, "Model strengthened  now has %d rows", 7164 7528 clpSolver>getNumRows()); 7165 7529 printGeneralMessage(model_,generalPrint); 7166 #else7167 std::cout << "Model strengthened  now has " << clpSolver>getNumRows()7168 << " rows" << std::endl;7169 #endif7170 7530 } 7171 7531 time1 = time2; … … 7183 7543 //babModel_=NULL; 7184 7544 } else { 7185 #ifndef DISALLOW_PRINTING7186 #ifdef GENERAL_HANDLER_PRINTING7187 7545 sprintf(generalPrint, "** Current model not valid"); 7188 7546 printGeneralMessage(model_,generalPrint); 7189 #else7190 std::cout << "** Current model not valid" << std::endl ;7191 #endif7192 #endif7193 7547 } 7194 7548 break ; … … 7317 7671 } else { 7318 7672 canOpen = false; 7319 #ifdef GENERAL_HANDLER_PRINTING7320 7673 sprintf(generalPrint, "Unable to open file %s",gmplData.c_str()); 7321 7674 printGeneralMessage(model_,generalPrint); 7322 #else7323 std::cout << "Unable to open file " << gmplData << std::endl;7324 #endif7325 7675 } 7326 7676 } 7327 7677 } else { 7328 #ifdef GENERAL_HANDLER_PRINTING7329 7678 sprintf(generalPrint, "Unable to open file %s",fileName.c_str()); 7330 7679 printGeneralMessage(model_,generalPrint); 7331 #else7332 std::cout << "Unable to open file " << fileName << std::endl;7333 #endif7334 7680 } 7335 7681 } … … 7348 7694 } else { 7349 7695 #ifdef KILL_ZERO_READLP 7350 status = lpSolver>readLp(fileName.c_str(), lpSolver>getSmallElementValue());7696 status = clpSolver>readLp(fileName.c_str(), lpSolver>getSmallElementValue()); 7351 7697 #else 7352 status = lpSolver>readLp(fileName.c_str(), 1.0e12);7698 status = clpSolver>readLp(fileName.c_str(), 1.0e12); 7353 7699 #endif 7354 7700 } … … 7398 7744 } else { 7399 7745 // errors 7400 #ifdef GENERAL_HANDLER_PRINTING7401 7746 sprintf(generalPrint, "There were %d errors on input",status); 7402 7747 printGeneralMessage(model_,generalPrint); 7403 #else7404 std::cout << "There were " << status <<7405 " errors on input" << std::endl;7406 #endif7407 7748 } 7408 7749 } … … 7461 7802 canOpen = true; 7462 7803 } else { 7463 #ifdef GENERAL_HANDLER_PRINTING7464 7804 sprintf(generalPrint, "Unable to open file %s",fileName.c_str()); 7465 7805 printGeneralMessage(model_,generalPrint); 7466 #else7467 std::cout << "Unable to open file " << fileName << std::endl;7468 #endif7469 7806 } 7470 7807 } … … 7535 7872 canOpen = true; 7536 7873 } else { 7537 #ifdef GENERAL_HANDLER_PRINTING7538 7874 sprintf(generalPrint, "Unable to open file %s",fileName.c_str()); 7539 7875 printGeneralMessage(model_,generalPrint); 7540 #else7541 std::cout << "Unable to open file " << fileName << std::endl;7542 #endif7543 7876 } 7544 7877 if (canOpen) { … … 7563 7896 sosIndices = info.sosIndices; 7564 7897 sosReference = info.sosReference; 7565 preSolve = false;7566 7898 clpSolver>setSOSData(numberSOS, info.sosType, sosStart, sosIndices, sosReference); 7567 7899 } 7568 7900 #endif 7901 numberSOS = clpSolver>numberSOS(); 7902 if (numberSOS) 7903 preSolve = false; 7569 7904 #endif 7570 7905 if (preSolve) { … … 7619 7954 } 7620 7955 } 7621 clpSolver>writeMpsNative(fileName.c_str(), const_cast<const char **> (rowNames), const_cast<const char **> (columnNames), 7622 (outputFormat  1) / 2, 1 + ((outputFormat  1)&1)); 7956 // see if extension lp 7957 bool writeLp=false; 7958 { 7959 int lengthName = strlen(fileName.c_str()); 7960 if (lengthName>3&&!strcmp(fileName.c_str()+lengthName3,".lp")) 7961 writeLp=true; 7962 } 7963 if (!writeLp) { 7964 remove(fileName.c_str()); 7965 clpSolver>writeMpsNative(fileName.c_str(), const_cast<const char **> (rowNames), const_cast<const char **> (columnNames), 7966 (outputFormat  1) / 2, 1 + ((outputFormat  1)&1)); 7967 } else { 7968 FILE *fp = fopen(fileName.c_str(), "w"); 7969 assert (fp); 7970 clpSolver>writeLp(fp,1.0e12); 7971 } 7623 7972 if (rowNames) { 7624 7973 for (iRow = 0; iRow < numberRows; iRow++) { … … 7646 7995 } 7647 7996 } else { 7648 #ifndef DISALLOW_PRINTING7649 #ifdef GENERAL_HANDLER_PRINTING7650 7997 sprintf(generalPrint, "** Current model not valid"); 7651 7998 printGeneralMessage(model_,generalPrint); 7652 #else7653 std::cout << "** Current model not valid" << std::endl;7654 #endif7655 #endif7656 7999 } 7657 8000 break; … … 7695 8038 canOpen = true; 7696 8039 } else { 7697 #ifdef GENERAL_HANDLER_PRINTING7698 8040 sprintf(generalPrint, "Unable to open file %s",fileName.c_str()); 7699 8041 printGeneralMessage(model_,generalPrint); 7700 #else7701 std::cout << "Unable to open file " << fileName << std::endl;7702 #endif7703 8042 } 7704 8043 } … … 7715 8054 } 7716 8055 } else { 7717 #ifndef DISALLOW_PRINTING7718 #ifdef GENERAL_HANDLER_PRINTING7719 8056 sprintf(generalPrint, "** Current model not valid"); 7720 8057 printGeneralMessage(model_,generalPrint); 7721 #else7722 std::cout << "** Current model not valid" << std::endl;7723 #endif7724 #endif7725 8058 } 7726 8059 break; … … 7760 8093 int got[] = { 1, 1, 1, 1, 1, 1, 1, 1}; 7761 8094 int order[8]; 8095 bool useMasks = false; 8096 if (strstr(fileName.c_str(),"mask_")) { 8097 // look more closely 8098 const char * name = fileName.c_str(); 8099 int length = strlen(name); 8100 for (int i=length1;i>=0;i) { 8101 if (name[i]==dirsep) { 8102 name += i+1; 8103 break; 8104 } 8105 } 8106 useMasks = !strncmp(name,"mask_",5); 8107 } 7762 8108 assert(sizeof(got) == sizeof(order)); 7763 8109 int nAcross = 0; … … 7826 8172 if (good) { 7827 8173 char ** columnNames = new char * [numberColumns]; 7828 pseudoDown = reinterpret_cast<double *> (malloc(numberColumns * sizeof(double))); 7829 pseudoUp = reinterpret_cast<double *> (malloc(numberColumns * sizeof(double))); 7830 branchDirection = reinterpret_cast<int *> (malloc(numberColumns * sizeof(int))); 8174 //pseudoDown = NULL; 8175 //pseudoUp = NULL; 8176 //branchDirection = NULL; 8177 //if (got[5]!=1) 8178 pseudoDown = reinterpret_cast<double *> (malloc(numberColumns * sizeof(double))); 8179 //if (got[4]!=1) 8180 pseudoUp = reinterpret_cast<double *> (malloc(numberColumns * sizeof(double))); 8181 //if (got[2]!=1) 8182 branchDirection = reinterpret_cast<int *> (malloc(numberColumns * sizeof(int))); 7831 8183 priorities = reinterpret_cast<int *> (malloc(numberColumns * sizeof(int))); 7832 8184 free(solutionIn); … … 7848 8200 columnNames[iColumn] = 7849 8201 CoinStrdup(lpSolver>columnName(iColumn).c_str()); 7850 pseudoDown[iColumn] = 0.0; 7851 pseudoUp[iColumn] = 0.0; 7852 branchDirection[iColumn] = 0; 7853 priorities[iColumn] = 0; 8202 //if (got[5]!=1) 8203 pseudoDown[iColumn] = 0.0; 8204 //if (got[4]!=1) 8205 pseudoUp[iColumn] = 0.0; 8206 //if (got[2]!=1) 8207 branchDirection[iColumn] = 0; 8208 priorities[iColumn] = useMasks ? 123456789 : 0; 7854 8209 } 7855 8210 int nBadPseudo = 0; … … 7859 8214 int nBadLine = 0; 7860 8215 int nLine = 0; 7861 while (fgets(line, 1000, fp)) { 8216 iColumn = 1; 8217 int lowestPriority=COIN_INT_MAX; 8218 while (iColumn>=0  fgets(line, 1000, fp)) { 7862 8219 if (!strncmp(line, "ENDATA", 6)) 7863 8220 break; 7864 8221 nLine++; 7865 iColumn = 1; 8222 if (!useMasks) 8223 iColumn = 1; 7866 8224 double up = 0.0; 7867 8225 double down = 0.0; … … 7901 8259 // name 7902 8260 case 0: 7903 for (iColumn = 0; iColumn < numberColumns; iColumn++) { 8261 iColumn++; 8262 for (; iColumn < numberColumns; iColumn++) { 8263 if (priorities[iColumn]!=123456789) { 7904 8264 if (!strcmp(columnNames[iColumn], pos)) 7905 8265 break; 8266 } else { 8267 // mask (at present ? and trailing *) 8268 const char * name = columnNames[iColumn]; 8269 int length=strlen(name); 8270 int lengthMask=strlen(pos); 8271 bool asterisk = pos[lengthMask1]=='*'; 8272 if (asterisk) 8273 length=lengthMask1; 8274 int i; 8275 for (i=0;i<length;i++) { 8276 if (name[i]!=pos[i]) { 8277 if (pos[i]!='?') 8278 break; 8279 } 8280 } 8281 if (i==length) 8282 break; 8283 } 7906 8284 } 7907 8285 if (iColumn == numberColumns) … … 7934 8312 case 3: 7935 8313 pri = atoi(pos); 8314 lowestPriority=CoinMax(lowestPriority,pri); 7936 8315 break; 7937 8316 // up … … 7978 8357 pri = 0; 7979 8358 } 7980 pseudoDown[iColumn] = down; 7981 pseudoUp[iColumn] = up; 7982 branchDirection[iColumn] = dir; 8359 //if (got[5]!=1) 8360 pseudoDown[iColumn] = down; 8361 //if (got[4]!=1) 8362 pseudoUp[iColumn] = up; 8363 //if (got[2]!=1) 8364 branchDirection[iColumn] = dir; 7983 8365 priorities[iColumn] = pri; 7984 8366 if (solValue != COIN_DBL_MAX) { … … 7990 8372 prioritiesIn[iColumn] = priValue; 7991 8373 } 7992 } else {8374 } else if (!useMasks) { 7993 8375 nBadName++; 7994 8376 } 8377 } 8378 for (iColumn = 0; iColumn < numberColumns; iColumn++) { 8379 if (priorities[iColumn] == 123456789) 8380 priorities[iColumn] = lowestPriority+1; 7995 8381 } 7996 8382 if (!noPrinting_) { … … 8016 8402 fclose(fp); 8017 8403 } else { 8018 #ifdef GENERAL_HANDLER_PRINTING8019 8404 sprintf(generalPrint, "Unable to open file %s",fileName.c_str()); 8020 8405 printGeneralMessage(model_,generalPrint); 8021 #else8022 std::cout << "Unable to open file " << fileName << std::endl;8023 #endif8024 8406 } 8025 8407 } else { 8026 #ifndef DISALLOW_PRINTING8027 #ifdef GENERAL_HANDLER_PRINTING8028 8408 sprintf(generalPrint, "** Current model not valid"); 8029 8409 printGeneralMessage(model_,generalPrint); 8030 #else8031 std::cout << "** Current model not valid" << std::endl;8032 #endif8033 #endif8034 8410 } 8035 8411 break; … … 8076 8452 } 8077 8453 } else { 8078 #ifndef DISALLOW_PRINTING8079 #ifdef GENERAL_HANDLER_PRINTING8080 8454 sprintf(generalPrint, "** Current model not valid"); 8081 8455 printGeneralMessage(model_,generalPrint); 8082 #else8083 std::cout << "** Current model not valid" << std::endl;8084 #endif8085 #endif8086 8456 } 8087 8457 break; … … 8159 8529 fclose(fp); 8160 8530 } else { 8161 #ifdef GENERAL_HANDLER_PRINTING8162 8531 sprintf(generalPrint, "Unable to open file %s",fileName.c_str()); 8163 8532 printGeneralMessage(model_,generalPrint); 8164 #else8165 std::cout << "Unable to open file " << fileName << std::endl;8166 #endif8167 8533 } 8168 8534 } else { 8169 #ifndef DISALLOW_PRINTING8170 #ifdef GENERAL_HANDLER_PRINTING8171 8535 sprintf(generalPrint, "** Current model not valid"); 8172 8536 printGeneralMessage(model_,generalPrint); 8173 #else8174 std::cout << "** Current model not valid" << std::endl;8175 #endif8176 #endif8177 8537 } 8178 8538 break; … … 8223 8583 canOpen = true; 8224 8584 } else { 8225 #ifdef GENERAL_HANDLER_PRINTING8226 8585 sprintf(generalPrint, "Unable to open file %s",fileName.c_str()); 8227 8586 printGeneralMessage(model_,generalPrint); 8228 #else8229 std::cout << "Unable to open file " << fileName << std::endl;8230 #endif8231 8587 } 8232 8588 if (canOpen) { … … 8238 8594 } 8239 8595 } else { 8240 #ifndef DISALLOW_PRINTING8241 #ifdef GENERAL_HANDLER_PRINTING8242 8596 sprintf(generalPrint, "** Current model not valid"); 8243 8597 printGeneralMessage(model_,generalPrint); 8244 #else8245 std::cout << "** Current model not valid" << std::endl;8246 #endif8247 #endif8248 8598 } 8249 8599 break; … … 8281 8631 canOpen = true; 8282 8632 } else { 8283 #ifdef GENERAL_HANDLER_PRINTING8284 8633 sprintf(generalPrint, "Unable to open file %s",fileName.c_str()); 8285 8634 printGeneralMessage(model_,generalPrint); 8286 #else8287 std::cout << "Unable to open file " << fileName << std::endl;8288 #endif8289 8635 } 8290 8636 if (canOpen) { … … 8325 8671 } else { 8326 8672 // errors 8327 #ifdef GENERAL_HANDLER_PRINTING8328 8673 sprintf(generalPrint, "There were errors on output"); 8329 8674 printGeneralMessage(model_,generalPrint); 8330 #else8331 std::cout << "There were errors on output" << std::endl;8332 #endif8333 8675 } 8334 8676 } … … 8368 8710 canOpen = true; 8369 8711 } else { 8370 #ifdef GENERAL_HANDLER_PRINTING8371 8712 sprintf(generalPrint, "Unable to open file %s",fileName.c_str()); 8372 8713 printGeneralMessage(model_,generalPrint); 8373 #else8374 std::cout << "Unable to open file " << fileName << std::endl;8375 #endif8376 8714 } 8377 8715 if (canOpen) { … … 8384 8722 } else { 8385 8723 // errors 8386 #ifdef GENERAL_HANDLER_PRINTING8387 8724 sprintf(generalPrint, "There were errors on input"); 8388 8725 printGeneralMessage(model_,generalPrint); 8389 #else8390 std::cout << "There were errors on input" << std::endl;8391 #endif8392 8726 } 8393 8727 } … … 8506 8840 double value = CoinReadGetDoubleField(argc, argv, &valid); 8507 8841 if (!valid) { 8508 #ifdef GENERAL_HANDLER_PRINTING8509 8842 sprintf(generalPrint, "Setting %s to DEBUG %g",parameters_[iParam].name().c_str(),value); 8510 8843 printGeneralMessage(model_,generalPrint); 8511 #else8512 std::cout << "Setting " << parameters_[iParam].name() <<8513 " to DEBUG " << value << std::endl;8514 #endif8515 8844 int iRow; 8516 8845 int numberRows = lpSolver>numberRows(); … … 8749 9078 fclose(fp); 8750 9079 } else { 8751 #ifdef GENERAL_HANDLER_PRINTING8752 9080 sprintf(generalPrint, "Unable to open file %s",fileName.c_str()); 8753 9081 printGeneralMessage(model_,generalPrint); 8754 #else8755 std::cout << "Unable to open file " << fileName << std::endl;8756 #endif8757 9082 } 8758 9083 } … … 9146 9471 break; 9147 9472 } 9148 if (printMode<9) { 9149 if (lengthName) 9473 if (lengthName) 9150 9474 fprintf(fp,",name"); 9151 fprintf(fp,",increase,variable,decrease,variable\n"); 9152 } 9475 fprintf(fp,",increase,variable,decrease,variable\n"); 9153 9476 int * which = new int [ number]; 9154 9477 if (printMode != 7) { … … 9268 9591 break; 9269 9592 } 9593 char printFormat[50]; 9594 sprintf(printFormat," %s %s\n", 9595 CLP_QUOTE(CLP_OUTPUT_FORMAT), 9596 CLP_QUOTE(CLP_OUTPUT_FORMAT)); 9270 9597 if (printMode > 2 && printMode < 5) { 9271 9598 for (iRow = 0; iRow < numberRows; iRow++) { … … 9293 9620 fprintf(fp, " "); 9294 9621 } 9295 fprintf(fp, " %15.8g %15.8g\n", primalRowSolution[iRow],9622 fprintf(fp, printFormat, primalRowSolution[iRow], 9296 9623 dualRowSolution[iRow]); 9297 9624 } … … 9344 9671 fprintf(fp, " "); 9345 9672 } 9346 fprintf(fp, " %15.8g %15.8g\n",9673 fprintf(fp, printFormat, 9347 9674 primalColumnSolution[iColumn], 9348 9675 dualColumnSolution[iColumn]); … … 9432 9759 } 9433 9760 } else { 9434 #ifdef GENERAL_HANDLER_PRINTING9435 9761 sprintf(generalPrint, "Unable to open file %s",fileName.c_str()); 9436 9762 printGeneralMessage(model_,generalPrint); 9437 #else9438 std::cout << "Unable to open file " << fileName << std::endl;9439 #endif9440 9763 } 9441 9764 } else { 9442 #ifndef DISALLOW_PRINTING9443 #ifdef GENERAL_HANDLER_PRINTING9444 9765 sprintf(generalPrint, "** Current model not valid"); 9445 9766 printGeneralMessage(model_,generalPrint); 9446 #else9447 std::cout << "** Current model not valid" << std::endl;9448 #endif9449 #endif9450 9767 } 9451 9768 break; … … 9479 9796 saveSolution(lpSolver, fileName); 9480 9797 } else { 9481 #ifndef DISALLOW_PRINTING9482 #ifdef GENERAL_HANDLER_PRINTING9483 9798 sprintf(generalPrint, "** Current model not valid"); 9484 9799 printGeneralMessage(model_,generalPrint); 9485 #else9486 std::cout << "** Current model not valid" << std::endl;9487 #endif9488 #endif9489 9800 } 9490 9801 break; … … 9527 9838 time1 = time2; 9528 9839 } else { 9529 #ifdef GENERAL_HANDLER_PRINTING9530 9840 sprintf(generalPrint, "** Current model not valid"); 9531 9841 printGeneralMessage(model_,generalPrint); 9532 #else9533 std::cout << "** Current model not valid" << std::endl;9534 #endif9535 9842 } 9536 9843 break; … … 9844 10151 delete [] numberExact; 9845 10152 } 10153 static void sortOnOther(int * column, 10154 const CoinBigIndex * rowStart, 10155 int * order, 10156 int * other, 10157 int nRow, 10158 int nInRow, 10159 int where) 10160 { 10161 if (nRow < 2  where >= nInRow) 10162 return; 10163 // do initial sort 10164 int kRow; 10165 int iRow; 10166 for ( kRow = 0; kRow < nRow; kRow++) { 10167 iRow = order[kRow]; 10168 other[kRow] = column[rowStart[iRow] + where]; 10169 } 10170 CoinSort_2(other, other + nRow, order); 10171 int first = 0; 10172 iRow = order[0]; 10173 int firstC = column[rowStart[iRow] + where]; 10174 kRow = 1; 10175 while (kRow < nRow) { 10176 int lastC = 9999999;; 10177 for (; kRow < nRow + 1; kRow++) { 10178 if (kRow < nRow) { 10179 iRow = order[kRow]; 10180 lastC = column[rowStart[iRow] + where]; 10181 } else { 10182 lastC = 9999999; 10183 } 10184 if (lastC > firstC) 10185 break; 10186 } 10187 // sort 10188 sortOnOther(column, rowStart, order + first, other, kRow  first, 10189 nInRow, where + 1); 10190 firstC = lastC; 10191 first = kRow; 10192 } 10193 } 9846 10194 static void statistics(ClpSimplex * originalModel, ClpSimplex * model) 9847 10195 { 9848 int numberColumns = originalModel>numberColumns(); 9849 const char * integerInformation = originalModel>integerInformation(); 9850 const double * columnLower = originalModel>columnLower(); 9851 const double * columnUpper = originalModel>columnUpper(); 9852 int numberIntegers = 0; 9853 int numberBinary = 0; 9854 int iRow, iColumn; 9855 if (integerInformation) { 9856 for (iColumn = 0; iColumn < numberColumns; iColumn++) { 9857 if (integerInformation[iColumn]) { 9858 if (columnUpper[iColumn] > columnLower[iColumn]) { 9859 numberIntegers++; 9860 if (columnUpper[iColumn] == 0.0 && columnLower[iColumn] == 1) 9861 numberBinary++; 9862 } 9863 } 9864 } 9865 } 9866 numberColumns = model>numberColumns(); 9867 int numberRows = model>numberRows(); 9868 columnLower = model>columnLower(); 9869 columnUpper = model>columnUpper(); 9870 const double * rowLower = model>rowLower(); 9871 const double * rowUpper = model>rowUpper(); 9872 const double * objective = model>objective(); 9873 CoinPackedMatrix * matrix = model>matrix(); 9874 CoinBigIndex numberElements = matrix>getNumElements(); 9875 const int * columnLength = matrix>getVectorLengths(); 9876 //const CoinBigIndex * columnStart = matrix>getVectorStarts(); 9877 const double * elementByColumn = matrix>getElements(); 9878 int * number = new int[numberRows+1]; 9879 memset(number, 0, (numberRows + 1)*sizeof(int)); 9880 int numberObjSingletons = 0; 9881 /* cType 9882 0 0/inf, 1 0/up, 2 lo/inf, 3 lo/up, 4 free, 5 fix, 6 inf/0, 7 inf/up, 9883 8 0/1 9884 */ 9885 int cType[9]; 9886 std::string cName[] = {"0.0>inf,", "0.0>up,", "lo>inf,", "lo>up,", "free,", "fixed,", "inf>0.0,", 9887 "inf>up,", "0.0>1.0" 9888 }; 9889 int nObjective = 0; 9890 memset(cType, 0, sizeof(cType)); 9891 for (iColumn = 0; iColumn < numberColumns; iColumn++) { 9892 int length = columnLength[iColumn]; 9893 if (length == 1 && objective[iColumn]) 9894 numberObjSingletons++; 9895 number[length]++; 9896 if (objective[iColumn]) 9897 nObjective++; 9898 if (columnLower[iColumn] > 1.0e20) { 9899 if (columnLower[iColumn] == 0.0) { 9900 if (columnUpper[iColumn] > 1.0e20) 9901 cType[0]++; 9902 else if (columnUpper[iColumn] == 1.0) 9903 cType[8]++; 9904 else if (columnUpper[iColumn] == 0.0) 9905 cType[5]++; 9906 else 9907 cType[1]++; 9908 } else { 9909 if (columnUpper[iColumn] > 1.0e20) 9910 cType[2]++; 9911 else if (columnUpper[iColumn] == columnLower[iColumn]) 9912 cType[5]++; 9913 else 9914 cType[3]++; 9915 } 9916 } else { 9917 if (columnUpper[iColumn] > 1.0e20) 9918 cType[4]++; 9919 else if (columnUpper[iColumn] == 0.0) 9920 cType[6]++; 9921 else 9922 cType[7]++; 9923 } 9924 } 9925 /* rType 9926 0 E 0, 1 E 1, 2 E 1, 3 E other, 4 G 0, 5 G 1, 6 G other, 9927 7 L 0, 8 L 1, 9 L other, 10 Range 0/1, 11 Range other, 12 free 9928 */ 9929 int rType[13]; 9930 std::string rName[] = {"E 0.0,", "E 1.0,", "E 1.0,", "E other,", "G 0.0,", "G 1.0,", "G other,", 9931 "L 0.0,", "L 1.0,", "L other,", "Range 0.0>1.0,", "Range other,", "Free" 9932 }; 9933 memset(rType, 0, sizeof(rType)); 9934 for (iRow = 0; iRow < numberRows; iRow++) { 9935 if (rowLower[iRow] > 1.0e20) { 9936 if (rowLower[iRow] == 0.0) { 9937 if (rowUpper[iRow] > 1.0e20) 9938 rType[4]++; 9939 else if (rowUpper[iRow] == 1.0) 9940 rType[10]++; 9941 else if (rowUpper[iRow] == 0.0) 9942 rType[0]++; 9943 else 9944 rType[11]++; 9945 } else if (rowLower[iRow] == 1.0) { 9946 if (rowUpper[iRow] > 1.0e20) 9947 rType[5]++; 9948 else if (rowUpper[iRow] == rowLower[iRow]) 9949 rType[1]++; 9950 else 9951 rType[11]++; 9952 } else if (rowLower[iRow] == 1.0) { 9953 if (rowUpper[iRow] > 1.0e20) 9954 rType[6]++; 9955 else if (rowUpper[iRow] == rowLower[iRow]) 9956 rType[2]++; 9957 else 9958 rType[11]++; 9959 } else { 9960 if (rowUpper[iRow] > 1.0e20) 9961 rType[6]++; 9962 else if (rowUpper[iRow] == rowLower[iRow]) 9963 rType[3]++; 9964 else 9965 rType[11]++; 9966 } 9967 } else { 9968 if (rowUpper[iRow] > 1.0e20) 9969 rType[12]++; 9970 else if (rowUpper[iRow] == 0.0) 9971 rType[7]++; 9972 else if (rowUpper[iRow] == 1.0) 9973 rType[8]++; 9974 else 9975 rType[9]++; 9976 } 9977 } 9978 // Basic statistics 9979 printf("\n\nProblem has %d rows, %d columns (%d with objective) and %d elements\n", 9980 numberRows, numberColumns, nObjective, numberElements); 9981 if (number[0] + number[1]) { 9982 printf("There are "); 9983 if (numberObjSingletons) 9984 printf("%d singletons with objective ", numberObjSingletons); 9985 int numberNoObj = number[1]  numberObjSingletons; 9986 if (numberNoObj) 9987 printf("%d singletons with no objective ", numberNoObj); 9988 if (number[0]) 9989 printf("** %d columns have no entries", number[0]); 9990 printf("\n"); 9991 } 9992 printf("Column breakdown:\n"); 9993 int k; 9994 for (k = 0; k < static_cast<int> (sizeof(cType) / sizeof(int)); k++) { 9995 printf("%d of type %s ", cType[k], cName[k].c_str()); 9996 if (((k + 1) % 3) == 0) 9997 printf("\n"); 9998 } 9999 if ((k % 3) != 0) 10000 printf("\n"); 10001 printf("Row breakdown:\n"); 10002 for (k = 0; k < static_cast<int> (sizeof(rType) / sizeof(int)); k++) { 10003 printf("%d of type %s ", rType[k], rName[k].c_str()); 10004 if (((k + 1) % 3) == 0) 10005 printf("\n"); 10006 } 10007 if ((k % 3) != 0) 10008 printf("\n"); 10009 if (model>logLevel() < 2) 10010 return ; 10011 int kMax = model>logLevel() > 3 ? 1000000 : 10; 10012 k = 0; 10013 for (iRow = 1; iRow <= numberRows; iRow++) { 10014 if (number[iRow]) { 10015 k++; 10016 printf("%d columns have %d entries\n", number[iRow], iRow); 10017 if (k == kMax) 10018 break; 10019 } 10020 } 10021 if (k < numberRows) { 10022 int kk = k; 10023 k = 0; 10024 for (iRow = numberRows; iRow >= 1; iRow) { 10025 if (number[iRow]) { 10026 k++; 10027 if (k == kMax) 10196 int numberColumns = originalModel>numberColumns(); 10197 const char * integerInformation = originalModel>integerInformation(); 10198 const double * columnLower = originalModel>columnLower(); 10199 const double * columnUpper = originalModel>columnUpper(); 10200 int numberIntegers = 0; 10201 int numberBinary = 0; 10202 int iRow, iColumn; 10203 if (integerInformation) { 10204 for (iColumn = 0; iColumn < numberColumns; iColumn++) { 10205 if (integerInformation[iColumn]) { 10206 if (columnUpper[iColumn] > columnLower[iColumn]) { 10207 numberIntegers++; 10208 if (columnLower[iColumn] == 0.0 && columnUpper[iColumn] == 1) 10209 numberBinary++; 10210 } 10211 } 10212 } 10213 printf("Original problem has %d integers (%d of which binary)\n", 10214 numberIntegers,numberBinary); 10215 } 10216 numberColumns = model>numberColumns(); 10217 int numberRows = model>numberRows(); 10218 columnLower = model>columnLower(); 10219 columnUpper = model>columnUpper(); 10220 const double * rowLower = model>rowLower(); 10221 const double * rowUpper = model>rowUpper(); 10222 const double * objective = model>objective(); 10223 if (model>integerInformation()) { 10224 const char * integerInformation = model>integerInformation(); 10225 int numberIntegers = 0; 10226 int numberBinary = 0; 10227 double * obj = new double [numberColumns]; 10228 int * which = new int [numberColumns]; 10229 for (int iColumn = 0; iColumn < numberColumns; iColumn++) { 10230 if (columnUpper[iColumn] > columnLower[iColumn]) { 10231 if (integerInformation[iColumn]) { 10232 numberIntegers++; 10233 if (columnLower[iColumn] == 0.0 && columnUpper[iColumn] == 1) 10234 numberBinary++; 10235 } 10236 } 10237 } 10238 if(numberColumns != originalModel>numberColumns()) 10239 printf("Presolved problem has %d integers (%d of which binary)\n", 10240 numberIntegers,numberBinary); 10241 for (int ifInt=0;ifInt<2;ifInt++) { 10242 for (int ifAbs=0;ifAbs<2;ifAbs++) { 10243 int numberSort=0; 10244 int numberZero=0; 10245 int numberDifferentObj=0; 10246 for (int iColumn = 0; iColumn < numberColumns; iColumn++) { 10247 if (columnUpper[iColumn] > columnLower[iColumn]) { 10248 if (!ifIntintegerInformation[iColumn]) { 10249 obj[numberSort]=(ifAbs) ? fabs(objective[iColumn]) : 10250 objective[iColumn]; 10251 which[numberSort++]=iColumn; 10252 if (!objective[iColumn]) 10253 numberZero++; 10254 } 10255 } 10256 } 10257 CoinSort_2(obj,obj+numberSort,which); 10258 double last=obj[0]; 10259 for (int jColumn = 1; jColumn < numberSort; jColumn++) { 10260 if (fabs(obj[jColumn]last)>1.0e12) { 10261 numberDifferentObj++; 10262 last=obj[jColumn]; 10263 } 10264 } 10265 numberDifferentObj++; 10266 printf("==== "); 10267 if (ifInt) 10268 printf("for integers "); 10269 if (!ifAbs) 10270 printf("%d zero objective ",numberZero); 10271 else 10272 printf("absolute objective values "); 10273 printf("%d different\n",numberDifferentObj); 10274 bool saveModel=false; 10275 int target=model>logLevel(); 10276 if (target>10000) { 10277 if (ifInt&&!ifAbs) 10278 saveModel=true; 10279 target=10000; 10280 } 10281 10282 if (target<=100) 10283 target=12; 10284 else 10285 target=100; 10286 if (numberDifferentObj<target) { 10287 int iLast=0; 10288 double last=obj[0]; 10289 for (int jColumn = 1; jColumn < numberSort; jColumn++) { 10290 if (fabs(obj[jColumn]last)>1.0e12) { 10291 printf("%d variables have objective of %g\n", 10292 jColumniLast,last); 10293 iLast=jColumn; 10294 last=obj[jColumn]; 10295 } 10296 } 10297 printf("%d variables have objective of %g\n", 10298 numberSortiLast,last); 10299 if (saveModel) { 10300 int spaceNeeded=numberSort+numberDifferentObj; 10301 int * columnAdd = new int[spaceNeeded+numberDifferentObj+1]; 10302 double * elementAdd = new double[spaceNeeded]; 10303 int * rowAdd = new int[2*numberDifferentObj+1]; 10304 int * newIsInteger = rowAdd+numberDifferentObj+1; 10305 double * objectiveNew = new double[3*numberDifferentObj]; 10306 double * lowerNew = objectiveNew+numberDifferentObj; 10307 double * upperNew = lowerNew+numberDifferentObj; 10308 memset(columnAdd+spaceNeeded,0, 10309 (numberDifferentObj+1)*sizeof(int)); 10310 ClpSimplex tempModel=*model; 10311 int iLast=0; 10312 double last=obj[0]; 10313 numberDifferentObj=0; 10314 int numberElements=0; 10315 rowAdd[0]=0; 10316 double * objective = tempModel.objective(); 10317 for (int jColumn = 1; jColumn < numberSort+1; jColumn++) { 10318 if (jColumn==numberSortfabs(obj[jColumn]last)>1.0e12) { 10319 // not if just one 10320 if (jColumniLast>1) { 10321 bool allInteger=integerInformation!=NULL; 10322 int iColumn=which[iLast]; 10323 objectiveNew[numberDifferentObj]=objective[iColumn]; 10324 double lower=0.0; 10325 double upper=0.0; 10326 for (int kColumn=iLast;kColumn<jColumn;kColumn++) { 10327 iColumn=which[kColumn]; 10328 objective[iColumn]=0.0; 10329 double lowerValue=columnLower[iColumn]; 10330 double upperValue=columnUpper[iColumn]; 10331 double elementValue=1.0; 10332 if (objectiveNew[numberDifferentObj]*objective[iColumn]<0.0) { 10333 lowerValue=columnUpper[iColumn]; 10334 upperValue=columnLower[iColumn]; 10335 elementValue=1.0; 10336 } 10337 columnAdd[numberElements]=iColumn; 10338 elementAdd[numberElements++]=elementValue; 10339 if (integerInformation&&!integerInformation[iColumn]) 10340 allInteger=false; 10341 if (lower!=COIN_DBL_MAX) { 10342 if (lowerValue!=COIN_DBL_MAX) 10343 lower += lowerValue; 10344 else 10345 lower=COIN_DBL_MAX; 10346 } 10347 if (upper!=COIN_DBL_MAX) { 10348 if (upperValue!=COIN_DBL_MAX) 10349 upper += upperValue; 10350 else 10351 upper=COIN_DBL_MAX; 10352 } 10353 } 10354 columnAdd[numberElements]=numberColumns+numberDifferentObj; 10355 elementAdd[numberElements++]=1.0; 10356 newIsInteger[numberDifferentObj]= (allInteger) ? 1 : 0; 10357 lowerNew[numberDifferentObj]=lower; 10358 upperNew[numberDifferentObj]=upper; 10359 numberDifferentObj++; 10360 rowAdd[numberDifferentObj]=numberElements; 10361 } 10362 iLast=jColumn; 10363 last=obj[jColumn]; 10364 } 10365 } 10366 // add columns 10367 tempModel.addColumns(numberDifferentObj, lowerNew, upperNew, 10368 objectiveNew, 10369 columnAdd+spaceNeeded, NULL, NULL); 10370 // add constraints and make integer if all integer in group 10371 for (int iObj=0; iObj < numberDifferentObj; iObj++) { 10372 lowerNew[iObj]=0.0; 10373 upperNew[iObj]=0.0; 10374 if (newIsInteger[iObj]) 10375 tempModel.setInteger(numberColumns+iObj); 10376 } 10377 tempModel.addRows(numberDifferentObj, lowerNew, upperNew, 10378 rowAdd,columnAdd,elementAdd); 10379 delete [] columnAdd; 10380 delete [] elementAdd; 10381 delete [] rowAdd; 10382 delete [] objectiveNew; 10383 // save 10384 std::string tempName = model>problemName(); 10385 if (ifInt) 10386 tempName += "_int"; 10387 if (ifAbs) 10388 tempName += "_abs"; 10389 tempName += ".mps"; 10390 tempModel.writeMps(tempName.c_str()); 10391 } 10392 } 10393 } 10394 } 10395 delete [] which; 10396 delete [] obj; 10397 printf("===== end objective counts\n"); 10398 } 10399 CoinPackedMatrix * matrix = model>matrix(); 10400 CoinBigIndex numberElements = matrix>getNumElements(); 10401 const int * columnLength = matrix>getVectorLengths(); 10402 //const CoinBigIndex * columnStart = matrix>getVectorStarts(); 10403 const double * elementByColumn = matrix>getElements(); 10404 int * number = new int[numberRows+1]; 10405 memset(number, 0, (numberRows + 1)*sizeof(int)); 10406 int numberObjSingletons = 0; 10407 /* cType 10408 0 0/inf, 1 0/up, 2 lo/inf, 3 lo/up, 4 free, 5 fix, 6 inf/0, 7 inf/up, 10409 8 0/1 10410 */ 10411 int cType[9]; 10412 std::string cName[] = {"0.0>inf,", "0.0>up,", "lo>inf,", "lo>up,", "free,", "fixed,", "inf>0.0,", 10413 "inf>up,", "0.0>1.0" 10414 }; 10415 int nObjective = 0; 10416 memset(cType, 0, sizeof(cType)); 10417 for (iColumn = 0; iColumn < numberColumns; iColumn++) { 10418 int length = columnLength[iColumn]; 10419 if (length == 1 && objective[iColumn]) 10420 numberObjSingletons++; 10421 number[length]++; 10422 if (objective[iColumn]) 10423 nObjective++; 10424 if (columnLower[iColumn] > 1.0e20) { 10425 if (columnLower[iColumn] == 0.0) { 10426 if (columnUpper[iColumn] > 1.0e20) 10427 cType[0]++; 10428 else if (columnUpper[iColumn] == 1.0) 10429 cType[8]++; 10430 else if (columnUpper[iColumn] == 0.0) 10431 cType[5]++; 10432 else 10433 cType[1]++; 10434 } else { 10435 if (columnUpper[iColumn] > 1.0e20) 10436 cType[2]++; 10437 else if (columnUpper[iColumn] == columnLower[iColumn]) 10438 cType[5]++; 10439 else 10440 cType[3]++; 10441 } 10442 } else { 10443 if (columnUpper[iColumn] > 1.0e20) 10444 cType[4]++; 10445 else if (columnUpper[iColumn] == 0.0) 10446 cType[6]++; 10447 else 10448 cType[7]++; 10449 } 10450 } 10451 /* rType 10452 0 E 0, 1 E 1, 2 E 1, 3 E other, 4 G 0, 5 G 1, 6 G other, 10453 7 L 0, 8 L 1, 9 L other, 10 Range 0/1, 11 Range other, 12 free 10454 */ 10455 int rType[13]; 10456 std::string rName[] = {"E 0.0,", "E 1.0,", "E 1.0,", "E other,", "G 0.0,", "G 1.0,", "G other,", 10457 "L 0.0,", "L 1.0,", "L other,", "Range 0.0>1.0,", "Range other,", "Free" 10458 }; 10459 memset(rType, 0, sizeof(rType)); 10460 for (iRow = 0; iRow < numberRows; iRow++) { 10461 if (rowLower[iRow] > 1.0e20) { 10462 if (rowLower[iRow] == 0.0) { 10463 if (rowUpper[iRow] > 1.0e20) 10464 rType[4]++; 10465 else if (rowUpper[iRow] == 1.0) 10466 rType[10]++; 10467 else if (rowUpper[iRow] == 0.0) 10468 rType[0]++; 10469 else 10470 rType[11]++; 10471 } else if (rowLower[iRow] == 1.0) { 10472 if (rowUpper[iRow] > 1.0e20) 10473 rType[5]++; 10474 else if (rowUpper[iRow] == rowLower[iRow]) 10475 rType[1]++; 10476 else 10477 rType[11]++; 10478 } else if (rowLower[iRow] == 1.0) { 10479 if (rowUpper[iRow] > 1.0e20) 10480 rType[6]++; 10481 else if (rowUpper[iRow] == rowLower[iRow]) 10482 rType[2]++; 10483 else 10484 rType[11]++; 10485 } else { 10486 if (rowUpper[iRow] > 1.0e20) 10487 rType[6]++; 10488 else if (rowUpper[iRow] == rowLower[iRow]) 10489 rType[3]++; 10490 else 10491 rType[11]++; 10492 } 10493 } else { 10494 if (rowUpper[iRow] > 1.0e20) 10495 rType[12]++; 10496 else if (rowUpper[iRow] == 0.0) 10497 rType[7]++; 10498 else if (rowUpper[iRow] == 1.0) 10499 rType[8]++; 10500 else 10501 rType[9]++; 10502 } 10503 } 10504 // Basic statistics 10505 printf("\n\nProblem has %d rows, %d columns (%d with objective) and %d elements\n", 10506 numberRows, numberColumns, nObjective, numberElements); 10507 if (number[0] + number[1]) { 10508 printf("There are "); 10509 if (numberObjSingletons) 10510 printf("%d singletons with objective ", numberObjSingletons); 10511 int numberNoObj = number[1]  numberObjSingletons; 10512 if (numberNoObj) 10513 printf("%d singletons with no objective ", numberNoObj); 10514 if (number[0]) 10515 printf("** %d columns have no entries", number[0]); 10516 printf("\n"); 10517 } 10518 printf("Column breakdown:\n"); 10519 int k; 10520 for (k = 0; k < static_cast<int> (sizeof(cType) / sizeof(int)); k++) { 10521 printf("%d of type %s ", cType[k], cName[k].c_str()); 10522 if (((k + 1) % 3) == 0) 10523 printf("\n"); 10524 } 10525 if ((k % 3) != 0) 10526 printf("\n"); 10527 printf("Row breakdown:\n"); 10528 for (k = 0; k < static_cast<int> (sizeof(rType) / sizeof(int)); k++) { 10529 printf("%d of type %s ", rType[k], rName[k].c_str()); 10530 if (((k + 1) % 3) == 0) 10531 printf("\n"); 10532 } 10533 if ((k % 3) != 0) 10534 printf("\n"); 10535 //#define SYM 10536 #ifndef SYM 10537 if (model>logLevel() < 2) 10538 return ; 10539 #endif 10540 int kMax = model>logLevel() > 3 ? 1000000 : 10; 10541 k = 0; 10542 for (iRow = 1; iRow <= numberRows; iRow++) { 10543 if (number[iRow]) { 10544 k++; 10545 printf("%d columns have %d entries\n", number[iRow], iRow); 10546 if (k == kMax) 10028 10547 break; 10029 } 10030 } 10031 if (k > kk) { 10032 printf("\n .........\n\n"); 10033 iRow = k; 10034 k = 0; 10035 for (; iRow < numberRows; iRow++) { 10036 if (number[iRow]) { 10548 } 10549 } 10550 if (k < numberRows) { 10551 int kk = k; 10552 k = 0; 10553 for (iRow = numberRows; iRow >= 1; iRow) { 10554 if (number[iRow]) { 10037 10555 k++; 10038 printf("%d columns have %d entries\n", number[iRow], iRow);10039 10556 if (k == kMax) 10040 break; 10041 } 10042 } 10043 } 10044 } 10045 delete [] number; 10046 printf("\n\n"); 10047 // get row copy 10048 CoinPackedMatrix rowCopy = *matrix; 10049 rowCopy.reverseOrdering(); 10050 //const int * column = rowCopy.getIndices(); 10051 const int * rowLength = rowCopy.getVectorLengths(); 10052 //const CoinBigIndex * rowStart = rowCopy.getVectorStarts(); 10053 //const double * element = rowCopy.getElements(); 10054 number = new int[numberColumns+1]; 10055 memset(number, 0, (numberColumns + 1)*sizeof(int)); 10056 for (iRow = 0; iRow < numberRows; iRow++) { 10057 int length = rowLength[iRow]; 10058 number[length]++; 10059 } 10060 if (number[0]) 10061 printf("** %d rows have no entries\n", number[0]); 10062 k = 0; 10063 for (iColumn = 1; iColumn <= numberColumns; iColumn++) { 10064 if (number[iColumn]) { 10065 k++; 10066 printf("%d rows have %d entries\n", number[iColumn], iColumn); 10067 if (k == kMax) 10068 break; 10069 } 10070 } 10071 if (k < numberColumns) { 10072 int kk = k; 10073 k = 0; 10074 for (iColumn = numberColumns; iColumn >= 1; iColumn) { 10075 if (number[iColumn]) { 10076 k++; 10077 if (k == kMax) 10557 break; 10558 } 10559 } 10560 if (k > kk) { 10561 printf("\n .........\n\n"); 10562 iRow = k; 10563 k = 0; 10564 for (; iRow < numberRows; iRow++) { 10565 if (number[iRow]) { 10566 k++; 10567 printf("%d columns have %d entries\n", number[iRow], iRow); 10568 if (k == kMax) 10569 break; 10570 } 10571 } 10572 } 10573 } 10574 delete [] number; 10575 printf("\n\n"); 10576 if (model>logLevel() == 63 10577 #ifdef SYM 10578  true 10579 #endif 10580 ) { 10581 // get column copy 10582 CoinPackedMatrix columnCopy = *matrix; 10583 const int * columnLength = columnCopy.getVectorLengths(); 10584 number = new int[numberRows+1]; 10585 memset(number, 0, (numberRows + 1)*sizeof(int)); 10586 for (iColumn = 0; iColumn < numberColumns; iColumn++) { 10587 int length = columnLength[iColumn]; 10588 number[length]++; 10589 } 10590 k = 0; 10591 for (iRow = 1; iRow <= numberRows; iRow++) { 10592 if (number[iRow]) { 10593 k++; 10594 } 10595 } 10596 int * row = columnCopy.getMutableIndices(); 10597 const CoinBigIndex * columnStart = columnCopy.getVectorStarts(); 10598 double * element = columnCopy.getMutableElements(); 10599 int * order = new int[numberColumns]; 10600 int * other = new int[numberColumns]; 10601 for (iColumn = 0; iColumn < numberColumns; iColumn++) { 10602 int length = columnLength[iColumn]; 10603 order[iColumn] = iColumn; 10604 other[iColumn] = length; 10605 CoinBigIndex start = columnStart[iColumn]; 10606 CoinSort_2(row + start, row + start + length, element + start); 10607 } 10608 CoinSort_2(other, other + numberColumns, order); 10609 int jColumn = number[0] + number[1]; 10610 for (iRow = 2; iRow <= numberRows; iRow++) { 10611 if (number[iRow]) { 10612 printf("XX %d columns have %d entries\n", number[iRow], iRow); 10613 int kColumn = jColumn + number[iRow]; 10614 sortOnOther(row, columnStart, 10615 order + jColumn, other, number[iRow], iRow, 0); 10616 // Now print etc 10617 if (iRow < 500000) { 10618 for (int lColumn = jColumn; lColumn < kColumn; lColumn++) { 10619 iColumn = order[lColumn]; 10620 CoinBigIndex start = columnStart[iColumn]; 10621 if (model>logLevel() == 63) { 10622 printf("column %d %g <= ", iColumn, columnLower[iColumn]); 10623 for (CoinBigIndex i = start; i < start + iRow; i++) 10624 printf("( %d, %g) ", row[i], element[i]); 10625 printf("<= %g\n", columnUpper[iColumn]); 10626 } 10627 } 10628 } 10629 jColumn = kColumn; 10630 } 10631 } 10632 delete [] order; 10633 delete [] other; 10634 delete [] number; 10635 } 10636 // get row copy 10637 CoinPackedMatrix rowCopy = *matrix; 10638 rowCopy.reverseOrdering(); 10639 const int * rowLength = rowCopy.getVectorLengths(); 10640 number = new int[numberColumns+1]; 10641 memset(number, 0, (numberColumns + 1)*sizeof(int)); 10642 if (model>logLevel() > 3) { 10643 // get column copy 10644 CoinPackedMatrix columnCopy = *matrix; 10645 const int * columnLength = columnCopy.getVectorLengths(); 10646 const int * row = columnCopy.getIndices(); 10647 const CoinBigIndex * columnStart = columnCopy.getVectorStarts(); 10648 const double * element = columnCopy.getElements(); 10649 const double * elementByRow = rowCopy.getElements(); 10650 const int * rowStart = rowCopy.getVectorStarts(); 10651 const int * column = rowCopy.getIndices(); 10652 int nPossibleZeroCost=0; 10653 int nPossibleNonzeroCost=0; 10654 for (int iColumn = 0; iColumn < numberColumns; iColumn++) { 10655 int length = columnLength[iColumn]; 10656 if (columnLower[iColumn]<1.0e30&&columnUpper[iColumn]>1.0e30) { 10657 if (length==1) { 10658 printf("Singleton free %d  cost %g\n",iColumn,objective[iColumn]); 10659 } else if (length==2) { 10660 int iRow0=row[columnStart[iColumn]]; 10661 int iRow1=row[columnStart[iColumn]+1]; 10662 double element0=element[columnStart[iColumn]]; 10663 double element1=element[columnStart[iColumn]+1]; 10664 int n0=rowLength[iRow0]; 10665 int n1=rowLength[iRow1]; 10666 printf("Doubleton free %d  cost %g  %g in %srow with %d entries and %g in %srow with %d entries\n", 10667 iColumn,objective[iColumn],element0,(rowLower[iRow0]==rowUpper[iRow0]) ? "==" : "",n0, 10668 element1,(rowLower[iRow1]==rowUpper[iRow1]) ? "==" : "",n1); 10669 10670 } 10671 } 10672 if (length==1) { 10673 int iRow=row[columnStart[iColumn]]; 10674 double value=COIN_DBL_MAX; 10675 for (int i=rowStart[iRow];i<rowStart[iRow]+rowLength[iRow];i++) { 10676 int jColumn=column[i]; 10677 if (jColumn!=iColumn) { 10678 if (value!=elementByRow[i]) { 10679 if (value==COIN_DBL_MAX) { 10680 value=elementByRow[i]; 10681 } else { 10682 value = COIN_DBL_MAX; 10683 break; 10684 } 10685 } 10686 } 10687 } 10688 if (!objective[iColumn]) { 10689 if (model>logLevel() > 4) 10690 printf("Singleton %d with no objective in row with %d elements  rhs %g,%g\n",iColumn,rowLength[iRow],rowLower[iRow],rowUpper[iRow]); 10691 nPossibleZeroCost++; 10692 } else if (value!=COIN_DBL_MAX) { 10693 if (model>logLevel() > 4) 10694 printf("Singleton %d (%s) with objective in row %d (%s) with %d equal elements  rhs %g,%g\n",iColumn,model>getColumnName(iColumn).c_str(), 10695 iRow,model>getRowName(iRow).c_str(), 10696 rowLength[iRow],rowLower[iRow],rowUpper[iRow]); 10697 nPossibleNonzeroCost++; 10698 } 10699 } 10700 } 10701 if (nPossibleZeroCostnPossibleNonzeroCost) 10702 printf("%d singletons with zero cost, %d with valid cost\n", 10703 nPossibleZeroCost,nPossibleNonzeroCost); 10704 // look for DW 10705 int * blockStart = new int [2*(numberRows+numberColumns)+1+numberRows]; 10706 int * columnBlock = blockStart+numberRows; 10707 int * nextColumn = columnBlock+numberColumns; 10708 int * blockCount = nextColumn+numberColumns; 10709 int * blockEls = blockCount+numberRows+1; 10710 int direction[2]={1,1}; 10711 int bestBreak=1; 10712 double bestValue=0.0; 10713 int iPass=0; 10714 int halfway=(numberRows+1)/2; 10715 int firstMaster=1; 10716 int lastMaster=2; 10717 while (iPass<2) { 10718 int increment=direction[iPass]; 10719 int start= increment>0 ? 0 : numberRows1; 10720 int stop=increment>0 ? numberRows : 1; 10721 int numberBlocks=0; 10722 int thisBestBreak=1; 10723 double thisBestValue=COIN_DBL_MAX; 10724 int numberRowsDone=0; 10725 int numberMarkedColumns=0; 10726 int maximumBlockSize=0; 10727 for (int i=0;i<numberRows+2*numberColumns;i++) 10728 blockStart[i]=1; 10729 for (int i=0;i<numberRows+1;i++) 10730 blockCount[i]=0; 10731 for (int iRow=start;iRow!=stop;iRow+=increment) { 10732 int iBlock = 1; 10733 for (CoinBigIndex j=rowStart[iRow];j<rowStart[iRow]+rowLength[iRow];j++) { 10734 int iColumn=column[j]; 10735 int whichColumnBlock=columnBlock[iColumn]; 10736 if (whichColumnBlock>=0) { 10737 // column marked 10738 if (iBlock<0) { 10739 // put row in that block 10740 iBlock=whichColumnBlock; 10741 } else if (iBlock!=whichColumnBlock) { 10742 // merge 10743 blockCount[iBlock]+=blockCount[whichColumnBlock]; 10744 blockCount[whichColumnBlock]=0; 10745 int jColumn=blockStart[whichColumnBlock]; 10746 while (jColumn>=0) { 10747 columnBlock[jColumn]=iBlock; 10748 iColumn=jColumn; 10749 jColumn=nextColumn[jColumn]; 10750 } 10751 nextColumn[iColumn]=blockStart[iBlock]; 10752 blockStart[iBlock]=blockStart[whichColumnBlock]; 10753 blockStart[whichColumnBlock]=1; 10754 } 10755 } 10756 } 10757 int n=numberMarkedColumns; 10758 if (iBlock<0) { 10759 //new block 10760 if (rowLength[iRow]) { 10761 numberBlocks++; 10762 iBlock=numberBlocks; 10763 int jColumn=column[rowStart[iRow]]; 10764 columnBlock[jColumn]=iBlock; 10765 blockStart[iBlock]=jColumn; 10766 numberMarkedColumns++; 10767 for (CoinBigIndex j=rowStart[iRow]+1;j<rowStart[iRow]+rowLength[iRow];j++) { 10768 int iColumn=column[j]; 10769 columnBlock[iColumn]=iBlock; 10770 numberMarkedColumns++; 10771 nextColumn[jColumn]=iColumn; 10772 jColumn=iColumn; 10773 } 10774 blockCount[iBlock]=numberMarkedColumnsn; 10775 } else { 10776 // empty 10777 iBlock=numberRows; 10778 } 10779 } else { 10780 // put in existing block 10781 int jColumn=blockStart[iBlock]; 10782 for (CoinBigIndex j=rowStart[iRow];j<rowStart[iRow]+rowLength[iRow];j++) { 10783 int iColumn=column[j]; 10784 assert (columnBlock[iColumn]<0columnBlock[iColumn]==iBlock); 10785 if (columnBlock[iColumn]<0) { 10786 columnBlock[iColumn]=iBlock; 10787 numberMarkedColumns++; 10788 nextColumn[iColumn]=jColumn; 10789 jColumn=iColumn; 10790 } 10791 } 10792 blockStart[iBlock]=jColumn; 10793 blockCount[iBlock]+=numberMarkedColumnsn; 10794 } 10795 maximumBlockSize=CoinMax(maximumBlockSize,blockCount[iBlock]); 10796 numberRowsDone++; 10797 if (thisBestValue*numberRowsDone > maximumBlockSize&&numberRowsDone>halfway) { 10798 thisBestBreak=iRow; 10799 thisBestValue=static_cast<double>(maximumBlockSize)/ 10800 static_cast<double>(numberRowsDone); 10801 } 10802 } 10803 if (thisBestBreak==stop) 10804 thisBestValue=COIN_DBL_MAX; 10805 iPass++; 10806 if (iPass==1) { 10807 bestBreak=thisBestBreak; 10808 bestValue=thisBestValue; 10809 } else { 10810 if (bestValue<thisBestValue) { 10811 firstMaster=0; 10812 lastMaster=bestBreak; 10813 } else { 10814 firstMaster=thisBestBreak; // ? +1 10815 lastMaster=numberRows; 10816 } 10817 } 10818 } 10819 if (firstMaster<lastMaster) { 10820 printf("%d master rows %d <= < %d\n",lastMasterfirstMaster, 10821 firstMaster,lastMaster); 10822 for (int i=0;i<numberRows+2*numberColumns;i++) 10823 blockStart[i]=1; 10824 for (int i=firstMaster;i<lastMaster;i++) 10825 blockStart[i]=2; 10826 int firstRow=0; 10827 int numberBlocks=1; 10828 while (true) { 10829 for (;firstRow<numberRows;firstRow++) { 10830 if (blockStart[firstRow]==1) 10831 break; 10832 } 10833 if (firstRow==numberRows) 10834 break; 10835 int nRows=0; 10836 numberBlocks++; 10837 int numberStack=1; 10838 blockCount[0] = firstRow; 10839 while (numberStack) { 10840 int iRow=blockCount[numberStack]; 10841 for (CoinBigIndex j=rowStart[iRow];j<rowStart[iRow]+rowLength[iRow];j++) { 10842 int iColumn=column[j]; 10843 int iBlock=columnBlock[iColumn]; 10844 if (iBlock<0) { 10845 columnBlock[iColumn]=numberBlocks; 10846 for (CoinBigIndex k=columnStart[iColumn]; 10847 k<columnStart[iColumn]+columnLength[iColumn];k++) { 10848 int jRow=row[k]; 10849 int rowBlock=blockStart[jRow]; 10850 if (rowBlock==1) { 10851 nRows++; 10852 blockStart[jRow]=numberBlocks; 10853 blockCount[numberStack++]=jRow; 10854 } 10855 } 10856 } 10857 } 10858 } 10859 if (!nRows) { 10860 // empty!! 10861 numberBlocks; 10862 } 10863 firstRow++; 10864 } 10865 // adjust 10866 numberBlocks++; 10867 for (int i=0;i<numberBlocks;i++) { 10868 blockCount[i]=0; 10869 nextColumn[i]=0; 10870 } 10871 int numberEmpty=0; 10872 int numberMaster=0; 10873 memset(blockEls,0,numberBlocks*sizeof(int)); 10874 for (int iRow = 0; iRow < numberRows; iRow++) { 10875 int iBlock=blockStart[iRow]; 10876 if (iBlock>=0) { 10877 blockCount[iBlock]++; 10878 blockEls[iBlock]+=rowLength[iRow]; 10879 } else { 10880 if (iBlock==2) 10881 numberMaster++; 10882 else 10883 numberEmpty++; 10884 } 10885 } 10886 int numberEmptyColumns=0; 10887 int numberMasterColumns=0; 10888 for (int iColumn = 0; iColumn < numberColumns; iColumn++) { 10889 int iBlock=columnBlock[iColumn]; 10890 if (iBlock>=0) { 10891 nextColumn[iBlock]++; 10892 } else { 10893 if (columnLength[iColumn]) 10894 numberMasterColumns++; 10895 else 10896 numberEmptyColumns++; 10897 } 10898 } 10899 int largestRows=0; 10900 int largestColumns=0; 10901 for (int i=0;i<numberBlocks;i++) { 10902 if (blockCount[i]+nextColumn[i]>largestRows+largestColumns) { 10903 largestRows=blockCount[i]; 10904 largestColumns=nextColumn[i]; 10905 } 10906 } 10907 bool useful=true; 10908 if (numberMaster>halfwaylargestRows*3>numberRows) 10909 useful=false; 10910 printf("%s %d blocks (largest %d,%d), %d master rows (%d empty) out of %d, %d master columns (%d empty) out of %d\n", 10911 useful ? "**Useful" : "NoGood", 10912 numberBlocks,largestRows,largestColumns,numberMaster,numberEmpty,numberRows, 10913 numberMasterColumns,numberEmptyColumns,numberColumns); 10914 FILE * fp=NULL; 10915 bool justIntegers=true; 10916 bool oneFile=true; 10917 int logLevel = model>logLevel(); 10918 if (logLevel>19) { 10919 logLevel=2; 10920 oneFile=true; 10921 fp = fopen("fake.bnd","w"); 10922 } 10923 if (logLevel==19) 10924 justIntegers=false; 10925 for (int i=0;i<numberBlocks;i++) 10926 printf("Block %d has %d rows and %d columns (%d elements)\n", 10927 i,blockCount[i],nextColumn[i],blockEls[i]); 10928 if (logLevel >= 17 && logLevel <= 21) { 10929 int * whichRows=new int[numberRows+numberColumns]; 10930 int * whichColumns=whichRows+numberRows; 10931 char name[20]; 10932 for (int iBlock=0;iBlock<numberBlocks;iBlock++) { 10933 sprintf(name,"block%d.mps",iBlock); 10934 int nRows=0; 10935 for (int iRow=0;iRow<numberRows;iRow++) { 10936 if (blockStart[iRow]==iBlock) 10937 whichRows[nRows++]=iRow; 10938 } 10939 int nColumns=0; 10940 for (int iColumn=0;iColumn<numberColumns;iColumn++) { 10941 if (columnBlock[iColumn]==iBlock) 10942 whichColumns[nColumns++]=iColumn; 10943 } 10944 ClpSimplex subset(model,nRows,whichRows,nColumns,whichColumns); 10945 for (int jRow=0;jRow<nRows;jRow++) { 10946 int iRow = whichRows[jRow]; 10947 std::string name = model>getRowName(iRow); 10948 subset.setRowName(jRow,name); 10949 } 10950 int nInteger=0; 10951 for (int jColumn=0;jColumn<nColumns;jColumn++) { 10952 int iColumn = whichColumns[jColumn]; 10953 if (model>isInteger(iColumn)) { 10954 subset.setInteger(jColumn); 10955 nInteger++; 10956 } 10957 std::string name = model>getColumnName(iColumn); 10958 subset.setColumnName(jColumn,name); 10959 } 10960 if (logLevel == 17) { 10961 subset.writeMps(name,0,1); 10962 } else if (nInteger) { 10963 OsiClpSolverInterface subset2(&subset); 10964 CbcModel smallModel(subset2); 10965 smallModel.branchAndBound(); 10966 const double * solution = smallModel.bestSolution(); 10967 if (solution) { 10968 if (!oneFile) { 10969 sprintf(name,"block%d.bnd",iBlock); 10970 fp = fopen(name,"w"); 10971 assert (fp); 10972 } 10973 fprintf(fp,"BBB objective %g for block %d\n", 10974 smallModel.getObjValue(),iBlock); 10975 for (int jColumn=0;jColumn<nColumns;jColumn++) { 10976 if (subset.isInteger(jColumn) 10977 !justIntegers) 10978 fprintf(fp," FX BOUND1 %.8s %g\n", 10979 subset.getColumnName(jColumn).c_str(), 10980 solution[jColumn]); 10981 } 10982 if (!oneFile) 10983 fclose(fp); 10984 } else { 10985 printf("***** Problem is infeasible\n"); 10986 abort(); 10987 } 10988 } 10989 } 10990 if (oneFile) 10991 fclose(fp); 10992 delete [] whichRows; 10993 } 10994 } 10995 delete [] blockStart; 10996 } 10997 for (iRow = 0; iRow < numberRows; iRow++) { 10998 int length = rowLength[iRow]; 10999 number[length]++; 11000 } 11001 if (number[0]) 11002 printf("** %d rows have no entries\n", number[0]); 11003 k = 0; 11004 for (iColumn = 1; iColumn <= numberColumns; iColumn++) { 11005 if (number[iColumn]) { 11006 k++; 11007 printf("%d rows have %d entries\n", number[iColumn], iColumn); 11008 if (k == kMax) 10078 11009 break; 10079 } 10080 } 10081 if (k > kk) { 10082 printf("\n .........\n\n"); 10083 iColumn = k; 10084 k = 0; 10085 for (; iColumn < numberColumns; iColumn++) { 10086 if (number[iColumn]) { 11010 } 11011 } 11012 if (k < numberColumns) { 11013 int kk = k; 11014 k = 0; 11015 for (iColumn = numberColumns; iColumn >= 1; iColumn) { 11016 if (number[iColumn]) { 10087 11017 k++; 10088 printf("%d rows have %d entries\n", number[iColumn], iColumn);10089 11018 if (k == kMax) 10090 break; 10091 } 10092 } 10093 } 10094 } 10095 delete [] number; 10096 // Now do breakdown of ranges 10097 breakdown("Elements", numberElements, elementByColumn); 10098 breakdown("RowLower", numberRows, rowLower); 10099 breakdown("RowUpper", numberRows, rowUpper); 10100 breakdown("ColumnLower", numberColumns, columnLower); 10101 breakdown("ColumnUpper", numberColumns, columnUpper); 10102 breakdown("Objective", numberColumns, objective); 11019 break; 11020 } 11021 } 11022 if (k > kk) { 11023 printf("\n .........\n\n"); 11024 iColumn = k; 11025 k = 0; 11026 for (; iColumn < numberColumns; iColumn++) { 11027 if (number[iColumn]) { 11028 k++; 11029 printf("%d rows have %d entries\n", number[iColumn], iColumn); 11030 if (k == kMax) 11031 break; 11032 } 11033 } 11034 } 11035 } 11036 if (model>logLevel() == 63 11037 #ifdef SYM 11038  true 11039 #endif 11040 ) { 11041 int * column = rowCopy.getMutableIndices(); 11042 const CoinBigIndex * rowStart = rowCopy.getVectorStarts(); 11043 double * element = rowCopy.getMutableElements(); 11044 int * order = new int[numberRows]; 11045 int * other = new int[numberRows]; 11046 for (iRow = 0; iRow < numberRows; iRow++) { 11047 int length = rowLength[iRow]; 11048 order[iRow] = iRow; 11049 other[iRow] = length; 11050 CoinBigIndex start = rowStart[iRow]; 11051 CoinSort_2(column + start, column + start + length, element + start); 11052 } 11053 CoinSort_2(other, other + numberRows, order); 11054 int jRow = number[0] + number[1]; 11055 double * weight = new double[numberRows]; 11056 double * randomColumn = new double[numberColumns+1]; 11057 double * randomRow = new double [numberRows+1]; 11058 int * sortRow = new int [numberRows]; 11059 int * possibleRow = new int [numberRows]; 11060 int * backRow = new int [numberRows]; 11061 int * stackRow = new int [numberRows]; 11062 int * sortColumn = new int [numberColumns]; 11063 int * possibleColumn = new int [numberColumns]; 11064 int * backColumn = new int [numberColumns]; 11065 int * backColumn2 = new int [numberColumns]; 11066 int * mapRow = new int [numberRows]; 11067 int * mapColumn = new int [numberColumns]; 11068 int * stackColumn = new int [numberColumns]; 11069 double randomLower = CoinDrand48(); 11070 double randomUpper = CoinDrand48(); 11071 double randomInteger = CoinDrand48(); 11072 int * startAdd = new int[numberRows+1]; 11073 int * columnAdd = new int [2*numberElements]; 11074 double * elementAdd = new double[2*numberElements]; 11075 int nAddRows = 0; 11076 startAdd[0] = 0; 11077 for (iColumn = 0; iColumn < numberColumns; iColumn++) { 11078 randomColumn[iColumn] = CoinDrand48(); 11079 backColumn2[iColumn] = 1; 11080 } 11081 for (iColumn = 2; iColumn <= numberColumns; iColumn++) { 11082 if (number[iColumn]) { 11083 printf("XX %d rows have %d entries\n", number[iColumn], iColumn); 11084 int kRow = jRow + number[iColumn]; 11085 sortOnOther(column, rowStart, 11086 order + jRow, other, number[iColumn], iColumn, 0); 11087 // Now print etc 11088 if (iColumn < 500000) { 11089 int nLook = 0; 11090 for (int lRow = jRow; lRow < kRow; lRow++) { 11091 iRow = order[lRow]; 11092 CoinBigIndex start = rowStart[iRow]; 11093 if (model>logLevel() == 63) { 11094 printf("row %d %g <= ", iRow, rowLower[iRow]); 11095 for (CoinBigIndex i = start; i < start + iColumn; i++) 11096 printf("( %d, %g) ", column[i], element[i]); 11097 printf("<= %g\n", rowUpper[iRow]); 11098 } 11099 int first = column[start]; 11100 double sum = 0.0; 11101 for (CoinBigIndex i = start; i < start + iColumn; i++) { 11102 int jColumn = column[i]; 11103 double value = element[i]; 11104 jColumn = first; 11105 assert (jColumn >= 0); 11106 sum += value * randomColumn[jColumn]; 11107 } 11108 if (rowLower[iRow] > 1.0e30 && rowLower[iRow]) 11109 sum += rowLower[iRow] * randomLower; 11110 else if (!rowLower[iRow]) 11111 sum += 1.234567e7 * randomLower; 11112 if (rowUpper[iRow] < 1.0e30 && rowUpper[iRow]) 11113 sum += rowUpper[iRow] * randomUpper; 11114 else if (!rowUpper[iRow]) 11115 sum += 1.234567e7 * randomUpper; 11116 sortRow[nLook] = iRow; 11117 randomRow[nLook++] = sum; 11118 // best way is to number unique elements and bounds and use 11119 if (fabs(sum) > 1.0e4) 11120 sum *= 1.0e6; 11121 weight[iRow] = sum; 11122 } 11123 assert (nLook <= numberRows); 11124 CoinSort_2(randomRow, randomRow + nLook, sortRow); 11125 randomRow[nLook] = COIN_DBL_MAX; 11126 double last = COIN_DBL_MAX; 11127 int iLast = 1; 11128 for (int iLook = 0; iLook < nLook + 1; iLook++) { 11129 if (randomRow[iLook] > last) { 11130 if (iLast >= 0) { 11131 int n = iLook  iLast; 11132 if (n > 1) { 11133 //printf("%d rows possible?\n",n); 11134 } 11135 } 11136 iLast = iLook; 11137 last = randomRow[iLook]; 11138 } 11139 } 11140 } 11141 jRow = kRow; 11142 } 11143 } 11144 CoinPackedMatrix columnCopy = *matrix; 11145 const int * columnLength = columnCopy.getVectorLengths(); 11146 const int * row = columnCopy.getIndices(); 11147 const CoinBigIndex * columnStart = columnCopy.getVectorStarts(); 11148 const double * elementByColumn = columnCopy.getElements(); 11149 for (iColumn = 0; iColumn < numberColumns; iColumn++) { 11150 int length = columnLength[iColumn]; 11151 CoinBigIndex start = columnStart[iColumn]; 11152 double sum = objective[iColumn]; 11153 if (columnLower[iColumn] > 1.0e30 && columnLower[iColumn]) 11154 sum += columnLower[iColumn] * randomLower; 11155 else if (!columnLower[iColumn]) 11156 sum += 1.234567e7 * randomLower; 11157 if (columnUpper[iColumn] < 1.0e30 && columnUpper[iColumn]) 11158 sum += columnUpper[iColumn] * randomUpper; 11159 else if (!columnUpper[iColumn]) 11160 sum += 1.234567e7 * randomUpper; 11161 if (model>isInteger(iColumn)) 11162 sum += 9.87654321e6 * randomInteger; 11163 for (CoinBigIndex i = start; i < start + length; i++) { 11164 int iRow = row[i]; 11165 sum += elementByColumn[i] * weight[iRow]; 11166 } 11167 sortColumn[iColumn] = iColumn; 11168 randomColumn[iColumn] = sum; 11169 } 11170 { 11171 CoinSort_2(randomColumn, randomColumn + numberColumns, sortColumn); 11172 for (iColumn = 0; iColumn < numberColumns; iColumn++) { 11173 int i = sortColumn[iColumn]; 11174 backColumn[i] = iColumn; 11175 } 11176 randomColumn[numberColumns] = COIN_DBL_MAX; 11177 double last = COIN_DBL_MAX; 11178 int iLast = 1; 11179 for (int iLook = 0; iLook < numberColumns + 1; iLook++) { 11180 if (randomColumn[iLook] > last) { 11181 if (iLast >= 0) { 11182 int n = iLook  iLast; 11183 if (n > 1) { 11184 //printf("%d columns possible?\n",n); 11185 } 11186 for (int i = iLast; i < iLook; i++) { 11187 possibleColumn[sortColumn[i]] = n; 11188 } 11189 } 11190 iLast = iLook; 11191 last = randomColumn[iLook]; 11192 } 11193 } 11194 for (iRow = 0; iRow < numberRows; iRow++) { 11195 CoinBigIndex start = rowStart[iRow]; 11196 double sum = 0.0; 11197 int length = rowLength[iRow]; 11198 for (CoinBigIndex i = start; i < start + length; i++) { 11199 int jColumn = column[i]; 11200 double value = element[i]; 11201 jColumn = backColumn[jColumn]; 11202 sum += value * randomColumn[jColumn]; 11203 //if (iColumn==23089iRow==23729) 11204 //printf("row %d cola %d colb %d value %g rand %g sum %g\n", 11205 // iRow,jColumn,column[i],value,randomColumn[jColumn],sum); 11206 } 11207 sortRow[iRow] = iRow; 11208 randomRow[iRow] = weight[iRow]; 11209 randomRow[iRow] = sum; 11210 } 11211 CoinSort_2(randomRow, randomRow + numberRows, sortRow); 11212 for (iRow = 0; iRow < numberRows; iRow++) { 11213 int i = sortRow[iRow]; 11214 backRow[i] = iRow; 11215 } 11216 randomRow[numberRows] = COIN_DBL_MAX; 11217 last = COIN_DBL_MAX; 11218 iLast = 1; 11219 // Do backward indices from order 11220 for (iRow = 0; iRow < numberRows; iRow++) { 11221 other[order[iRow]] = iRow; 11222 } 11223 for (int iLook = 0; iLook < numberRows + 1; iLook++) { 11224 if (randomRow[iLook] > last) { 11225 if (iLast >= 0) { 11226 int n = iLook  iLast; 11227 if (n > 1) { 11228 //printf("%d rows possible?\n",n); 11229 // Within group sort as for original "order" 11230 for (int i = iLast; i < iLook; i++) { 11231 int jRow = sortRow[i]; 11232 order[i] = other[jRow]; 11233 } 11234 CoinSort_2(order + iLast, order + iLook, sortRow + iLast); 11235 } 11236 for (int i = iLast; i < iLook; i++) { 11237 possibleRow[sortRow[i]] = n; 11238 } 11239 } 11240 iLast = iLook; 11241 last = randomRow[iLook]; 11242 } 11243 } 11244 // Temp out 11245 for (int iLook = 0; iLook < numberRows  1000000; iLook++) { 11246 iRow = sortRow[iLook]; 11247 CoinBigIndex start = rowStart[iRow]; 11248 int length = rowLength[iRow]; 11249 int numberPossible = possibleRow[iRow]; 11250 for (CoinBigIndex i = start; i < start + length; i++) { 11251 int jColumn = column[i]; 11252 if (possibleColumn[jColumn] != numberPossible) 11253 numberPossible = 1; 11254 } 11255 int n = numberPossible; 11256 if (numberPossible > 1) { 11257 //printf("pppppossible %d\n",numberPossible); 11258 for (int jLook = iLook + 1; jLook < iLook + numberPossible; jLook++) { 11259 int jRow = sortRow[jLook]; 11260 CoinBigIndex start2 = rowStart[jRow]; 11261 assert (numberPossible == possibleRow[jRow]); 11262 assert(length == rowLength[jRow]); 11263 for (CoinBigIndex i = start2; i < start2 + length; i++) { 11264 int jColumn = column[i]; 11265 if (possibleColumn[jColumn] != numberPossible) 11266 numberPossible = 1; 11267 } 11268 } 11269 if (numberPossible < 2) { 11270 // switch off 11271 for (int jLook = iLook; jLook < iLook + n; jLook++) 11272 possibleRow[sortRow[jLook]] = 1; 11273 } 11274 // skip rest 11275 iLook += n  1; 11276 } else { 11277 possibleRow[iRow] = 1; 11278 } 11279 } 11280 for (int iLook = 0; iLook < numberRows; iLook++) { 11281 iRow = sortRow[iLook]; 11282 int numberPossible = possibleRow[iRow]; 11283 // Only if any integers 11284 int numberIntegers = 0; 11285 CoinBigIndex start = rowStart[iRow]; 11286 int length = rowLength[iRow]; 11287 for (CoinBigIndex i = start; i < start + length; i++) { 11288 int jColumn = column[i]; 11289 if (model>isInteger(jColumn)) 11290 numberIntegers++; 11291 } 11292 if (numberPossible > 1 && !numberIntegers) { 11293 //printf("possible %d  but no integers\n",numberPossible); 11294 } 11295 if (numberPossible > 1 && (numberIntegers  false)) { 11296 // 11297 printf("possible %d  %d integers\n", numberPossible, numberIntegers); 11298 int lastLook = iLook; 11299 int nMapRow = 1; 11300 for (int jLook = iLook + 1; jLook < iLook + numberPossible; jLook++) { 11301 // stop if too many failures 11302 if (jLook > iLook + 10 && nMapRow < 0) 11303 break; 11304 // Create identity mapping 11305 int i; 11306 for (i = 0; i < numberRows; i++) 11307 mapRow[i] = i; 11308 for (i = 0; i < numberColumns; i++) 11309 mapColumn[i] = i; 11310 int offset = jLook  iLook; 11311 int nStackC = 0; 11312 // build up row and column mapping 11313 int nStackR = 1; 11314 stackRow[0] = iLook; 11315 bool good = true; 11316 while (nStackR) { 11317 nStackR; 11318 int look1 = stackRow[nStackR]; 11319 int look2 = look1 + offset; 11320 assert (randomRow[look1] == randomRow[look2]); 11321 int row1 = sortRow[look1]; 11322 int row2 = sortRow[look2]; 11323 assert (mapRow[row1] == row1); 11324 assert (mapRow[row2] == row2); 11325 mapRow[row1] = row2; 11326 mapRow[row2] = row1; 11327 CoinBigIndex start1 = rowStart[row1]; 11328 CoinBigIndex offset2 = rowStart[row2]  start1; 11329 int length = rowLength[row1]; 11330 assert( length == rowLength[row2]); 11331 for (CoinBigIndex i = start1; i < start1 + length; i++) { 11332 int jColumn1 = column[i]; 11333 int jColumn2 = column[i+offset2]; 11334 if (randomColumn[backColumn[jColumn1]] != 11335 randomColumn[backColumn[jColumn2]]) { 11336 good = false; 11337 break; 11338 } 11339 if (mapColumn[jColumn1] == jColumn1) { 11340 // not touched 11341 assert (mapColumn[jColumn2] == jColumn2); 11342 if (jColumn1 != jColumn2) { 11343 // Put on stack 11344 mapColumn[jColumn1] = jColumn2; 11345 mapColumn[jColumn2] = jColumn1; 11346 stackColumn[nStackC++] = jColumn1; 11347 } 11348 } else { 11349 if (mapColumn[jColumn1] != jColumn2  11350 mapColumn[jColumn2] != jColumn1) { 11351 // bad 11352 good = false; 11353 printf("bad col\n"); 11354 break; 11355 } 11356 } 11357 } 11358 if (!good) 11359 break; 11360 while (nStackC) { 11361 nStackC; 11362 int iColumn = stackColumn[nStackC]; 11363 int iColumn2 = mapColumn[iColumn]; 11364 assert (iColumn != iColumn2); 11365 int length = columnLength[iColumn]; 11366 assert (length == columnLength[iColumn2]); 11367 CoinBigIndex start = columnStart[iColumn]; 11368 CoinBigIndex offset2 = columnStart[iColumn2]  start; 11369 for (CoinBigIndex i = start; i < start + length; i++) { 11370 int iRow = row[i]; 11371 int iRow2 = row[i+offset2]; 11372 if (mapRow[iRow] == iRow) { 11373 // First (but be careful) 11374 if (iRow != iRow2) { 11375 //mapRow[iRow]=iRow2; 11376 //mapRow[iRow2]=iRow; 11377 int iBack = backRow[iRow]; 11378 int iBack2 = backRow[iRow2]; 11379 if (randomRow[iBack] == randomRow[iBack2] && 11380 iBack2  iBack == offset) { 11381 stackRow[nStackR++] = iBack; 11382 } else { 11383 //printf("randomRow diff  weights %g %g\n", 11384 // weight[iRow],weight[iRow2]); 11385 // bad 11386 good = false; 11387 break; 11388 } 11389 } 11390 } else { 11391 if (mapRow[iRow] != iRow2  11392 mapRow[iRow2] != iRow) { 11393 // bad 11394 good = false; 11395 printf("bad row\n"); 11396 break; 11397 } 11398 } 11399 } 11400 if (!good) 11401 break; 11402 } 11403 } 11404 // then check OK 11405 if (good) { 11406 for (iRow = 0; iRow < numberRows; iRow++) { 11407 CoinBigIndex start = rowStart[iRow]; 11408 int length = rowLength[iRow]; 11409 if (mapRow[iRow] == iRow) { 11410 for (CoinBigIndex i = start; i < start + length; i++) { 11411 int jColumn = column[i]; 11412 backColumn2[jColumn] = i  start; 11413 } 11414 for (CoinBigIndex i = start; i < start + length; i++) { 11415 int jColumn = column[i]; 11416 if (mapColumn[jColumn] != jColumn) { 11417 int jColumn2 = mapColumn[jColumn]; 11418 CoinBigIndex i2 = backColumn2[jColumn2]; 11419 if (i2 < 0) { 11420 good = false; 11421 } else if (element[i] != element[i2+start]) { 11422 good = false; 11423 } 11424 } 11425 } 11426 for (CoinBigIndex i = start; i < start + length; i++) { 11427 int jColumn = column[i]; 11428 backColumn2[jColumn] = 1; 11429 } 11430 } else { 11431 int row2 = mapRow[iRow]; 11432 assert (iRow = mapRow[row2]); 11433 if (rowLower[iRow] != rowLower[row2]  11434 rowLower[row2] != rowLower[iRow]) 11435 good = false; 11436 CoinBigIndex offset2 = rowStart[row2]  start; 11437 for (CoinBigIndex i = start; i < start + length; i++) { 11438 int jColumn = column[i]; 11439 double value = element[i]; 11440 int jColumn2 = column[i+offset2]; 11441 double value2 = element[i+offset2]; 11442 if (value != value2  mapColumn[jColumn] != jColumn2  11443 mapColumn[jColumn2] != jColumn) 11444 good = false; 11445 } 11446 } 11447 } 11448 if (good) { 11449 // check rim 11450 for (iColumn = 0; iColumn < numberColumns; iColumn++) { 11451 if (mapColumn[iColumn] != iColumn) { 11452 int iColumn2 = mapColumn[iColumn]; 11453 if (objective[iColumn] != objective[iColumn2]) 11454 good = false; 11455 if (columnLower[iColumn] != columnLower[iColumn2]) 11456 good = false; 11457 if (columnUpper[iColumn] != columnUpper[iColumn2]) 11458 good = false; 11459 if (model>isInteger(iColumn) != model>isInteger(iColumn2)) 11460 good = false; 11461 } 11462 } 11463 } 11464 if (good) { 11465 // temp 11466 if (nMapRow < 0) { 11467 //const double * solution = model>primalColumnSolution(); 11468 // find mapped 11469 int nMapColumn = 0; 11470 for (int i = 0; i < numberColumns; i++) { 11471 if (mapColumn[i] > i) 11472 nMapColumn++; 11473 } 11474 nMapRow = 0; 11475 int kRow = 1; 11476 for (int i = 0; i < numberRows; i++) { 11477 if (mapRow[i] > i) { 11478 nMapRow++; 11479 kRow = i; 11480 } 11481 } 11482 printf("%d columns, %d rows\n", nMapColumn, nMapRow); 11483 if (nMapRow == 1) { 11484 CoinBigIndex start = rowStart[kRow]; 11485 int length = rowLength[kRow]; 11486 printf("%g <= ", rowLower[kRow]); 11487 for (CoinBigIndex i = start; i < start + length; i++) { 11488 int jColumn = column[i]; 11489 if (mapColumn[jColumn] != jColumn) 11490 printf("* "); 11491 printf("%d,%g ", jColumn, element[i]); 11492 } 11493 printf("<= %g\n", rowUpper[kRow]); 11494 } 11495 } 11496 // temp 11497 int row1 = sortRow[lastLook]; 11498 int row2 = sortRow[jLook]; 11499 lastLook = jLook; 11500 CoinBigIndex start1 = rowStart[row1]; 11501 CoinBigIndex offset2 = rowStart[row2]  start1; 11502 int length = rowLength[row1]; 11503 assert( length == rowLength[row2]); 11504 CoinBigIndex put = startAdd[nAddRows]; 11505 double multiplier = length < 11 ? 2.0 : 1.125; 11506 double value = 1.0; 11507 for (CoinBigIndex i = start1; i < start1 + length; i++) { 11508 int jColumn1 = column[i]; 11509 int jColumn2 = column[i+offset2]; 11510 columnAdd[put] = jColumn1; 11511 elementAdd[put++] = value; 11512 columnAdd[put] = jColumn2; 11513 elementAdd[put++] = value; 11514 value *= multiplier; 11515 } 11516 nAddRows++; 11517 startAdd[nAddRows] = put; 11518 } else { 11519 printf("ouch  did not check out as good\n"); 11520 } 11521 } 11522 } 11523 // skip rest 11524 iLook += numberPossible  1; 11525 } 11526 } 11527 } 11528 if (nAddRows) { 11529 double * lower = new double [nAddRows]; 11530 double * upper = new double[nAddRows]; 11531 int i; 11532 //const double * solution = model>primalColumnSolution(); 11533 for (i = 0; i < nAddRows; i++) { 11534 lower[i] = 0.0; 11535 upper[i] = COIN_DBL_MAX; 11536 } 11537 printf("Adding %d rows with %d elements\n", nAddRows, 11538 startAdd[nAddRows]); 11539 //ClpSimplex newModel(*model); 11540 //newModel.addRows(nAddRows,lower,upper,startAdd,columnAdd,elementAdd); 11541 //newModel.writeMps("modified.mps"); 11542 delete [] lower; 11543 delete [] upper; 11544 } 11545 delete [] startAdd; 11546 delete [] columnAdd; 11547 delete [] elementAdd; 11548 delete [] order; 11549 delete [] other; 11550 delete [] randomColumn; 11551 delete [] weight; 11552 delete [] randomRow; 11553 delete [] sortRow; 11554 delete [] backRow; 11555 delete [] possibleRow; 11556 delete [] sortColumn; 11557 delete [] backColumn; 11558 delete [] backColumn2; 11559 delete [] possibleColumn; 11560 delete [] mapRow; 11561 delete [] mapColumn; 11562 delete [] stackRow; 11563 delete [] stackColumn; 11564 } 11565 delete [] number; 11566 // Now do breakdown of ranges 11567 breakdown("Elements", numberElements, elementByColumn); 11568 breakdown("RowLower", numberRows, rowLower); 11569 breakdown("RowUpper", numberRows, rowUpper); 11570 breakdown("ColumnLower", numberColumns, columnLower); 11571 breakdown("ColumnUpper", numberColumns, columnUpper); 11572 breakdown("Objective", numberColumns, objective); 10103 11573 } 10104 11574 … … 10326 11796 printf("C++ file written to %s\n", fileName); 10327 11797 } 10328 #ifdef GENERAL_HANDLER_PRINTING10329 11798 // Print a general message 10330 11799 static void printGeneralMessage(CbcModel &model,const char * message) 10331 11800 { 11801 #ifndef DISALLOW_PRINTING 10332 11802 model.messageHandler()>message(CBC_FPUMP1, model.messages()) 10333 11803 << message 10334 11804 << CoinMessageEol; 11805 #endif 10335 11806 } 10336 #endif10337 11807 /* 10338 11808 Version 1.00.00 November 16 2005.
Note: See TracChangeset
for help on using the changeset viewer.