Changeset 477 for branches/devel/Cbc/src/CbcModel.cpp
 Timestamp:
 Nov 3, 2006 3:48:00 PM (13 years ago)
 File:

 1 edited
Legend:
 Unmodified
 Added
 Removed

branches/devel/Cbc/src/CbcModel.cpp
r473 r477 281 281 282 282 283 283 static double trueIncrement=0.0; 284 284 void 285 285 CbcModel::analyzeObjective () … … 311 311 */ 312 312 double maximumCost = 0.0 ; 313 trueIncrement=0.0; 313 314 bool possibleMultiple = true ; 314 315 int iColumn ; … … 335 336 while (10.0*multiplier*maximumCost < 1.0e8) 336 337 multiplier *= 10.0 ; 337 338 for (iColumn = 0 ; iColumn < numberColumns ; iColumn++) 339 { if (upper[iColumn] > lower[iColumn]+1.0e8) 340 { if (isInteger(iColumn)&&objective[iColumn]) 341 { double value = fabs(objective[iColumn])*multiplier ; 338 int bigIntegers = 0; // Count of large costs which are integer 339 for (iColumn = 0 ; iColumn < numberColumns ; iColumn++) { 340 if (upper[iColumn] > lower[iColumn]+1.0e8) { 341 if (isInteger(iColumn)&&objective[iColumn]) { 342 double value = fabs(objective[iColumn])*multiplier ; 343 if (value <2.1e9) { 342 344 int nearest = (int) floor(value+0.5) ; 343 345 if (fabs(valuefloor(value+0.5)) > 1.0e8) 344 { increment = 0 ;346 { increment = 0 ; 345 347 break ; } 346 348 else if (!increment) 347 { increment = nearest ; }349 { increment = nearest ; } 348 350 else 349 { increment = gcd(increment,nearest) ; } } } } 351 { increment = gcd(increment,nearest) ; } 352 } else { 353 // large value  may still be multiple of 1.0 354 value = fabs(objective[iColumn]); 355 if (fabs(valuefloor(value+0.5)) > 1.0e8) { 356 increment=0; 357 break; 358 } else { 359 bigIntegers++; 360 } 361 } 362 } 363 } 364 } 365 350 366 /* 351 367 If the increment beats the current value for objective change, install it. … … 354 370 { double value = increment ; 355 371 double cutoff = getDblParam(CbcModel::CbcCutoffIncrement) ; 372 if (bigIntegers) { 373 // allow for 1.0 374 increment = gcd(increment,(int) multiplier); 375 value = increment; 376 } 356 377 value /= multiplier ; 378 trueIncrement=CoinMax(cutoff,value);; 357 379 if (value*0.999 > cutoff) 358 380 { messageHandler()>message(CBC_INTEGERINCREMENT, … … 748 770 solver_>findIntegersAndSOS(false); 749 771 numberObjects_=solver_>numberObjects(); 750 object_ = new OsiObject * [numberObjects_]; 751 for (int iObject = 0 ; iObject < numberObjects_ ; iObject++) { 752 object_[iObject]=solver_>object(iObject)>clone(); 753 } 772 object_ = solver_>objects(); 773 ownObjects_ = false; 754 774 } 755 775 branchingMethod_>chooseMethod()>setSolver(solver_); … … 2196 2216 if (originalObject) { 2197 2217 int iColumn; 2218 assert (ownObjects_); 2198 2219 for (iColumn=0;iColumn<numberObjects_;iColumn++) 2199 2220 delete object_[iColumn]; … … 2353 2374 numberObjects_(0), 2354 2375 object_(NULL), 2376 ownObjects_(true), 2355 2377 originalColumns_(NULL), 2356 2378 howOftenGlobalScan_(1), … … 2481 2503 numberObjects_(0), 2482 2504 object_(NULL), 2505 ownObjects_(true), 2483 2506 originalColumns_(NULL), 2484 2507 howOftenGlobalScan_(1), … … 2767 2790 else 2768 2791 { eventHandler_ = NULL ; } 2769 numberObjects_=rhs.numberObjects_; 2770 if (numberObjects_) { 2771 object_ = new OsiObject * [numberObjects_]; 2772 int i; 2773 for (i=0;i<numberObjects_;i++) 2774 object_[i]=(rhs.object_[i])>clone(); 2792 ownObjects_ = rhs.ownObjects_; 2793 if (ownObjects_) { 2794 numberObjects_=rhs.numberObjects_; 2795 if (numberObjects_) { 2796 object_ = new OsiObject * [numberObjects_]; 2797 int i; 2798 for (i=0;i<numberObjects_;i++) 2799 object_[i]=(rhs.object_[i])>clone(); 2800 } else { 2801 object_=NULL; 2802 } 2775 2803 } else { 2804 // assume will be redone 2805 numberObjects_=0; 2776 2806 object_=NULL; 2777 2807 } … … 3047 3077 else 3048 3078 { eventHandler_ = NULL ; } 3049 for (i=0;i<numberObjects_;i++) 3050 delete object_[i]; 3051 delete [] object_; 3052 numberObjects_=rhs.numberObjects_; 3053 if (numberObjects_) { 3054 object_ = new OsiObject * [numberObjects_]; 3055 int i; 3056 for (i=0;i<numberObjects_;i++) 3057 object_[i]=(rhs.object_[i])>clone(); 3079 if (ownObjects_) { 3080 for (i=0;i<numberObjects_;i++) 3081 delete object_[i]; 3082 delete [] object_; 3083 numberObjects_=rhs.numberObjects_; 3084 if (numberObjects_) { 3085 object_ = new OsiObject * [numberObjects_]; 3086 int i; 3087 for (i=0;i<numberObjects_;i++) 3088 object_[i]=(rhs.object_[i])>clone(); 3089 } else { 3090 object_=NULL; 3091 } 3058 3092 } else { 3093 // assume will be redone 3094 numberObjects_=0; 3059 3095 object_=NULL; 3060 3096 } … … 3185 3221 integerVariable_=NULL; 3186 3222 int i; 3187 for (i=0;i<numberObjects_;i++) 3188 delete object_[i]; 3189 delete [] object_; 3223 if (ownObjects_) { 3224 for (i=0;i<numberObjects_;i++) 3225 delete object_[i]; 3226 delete [] object_; 3227 } 3228 ownObjects_=true; 3190 3229 object_=NULL; 3191 3230 numberIntegers_=0; … … 3859 3898 objectiveValue= node>objectiveValue(); 3860 3899 int returnCode = resolve(node ? node>nodeInfo() : NULL,1); 3900 #ifdef COIN_DEVELOP 3901 //if (!solver_>getIterationCount()&&solver_>isProvenOptimal()) 3902 //printf("zero iterations on first solve of branch\n"); 3903 #endif 3861 3904 if (node&&!node>nodeInfo()>numberBranchesLeft()) 3862 3905 node>nodeInfo()>allBranchesGone(); // can clean up … … 5213 5256 } 5214 5257 } 5215 if ( !feasible&& continuousObjective_ <1.0e30) {5258 if (false&&!feasible&& continuousObjective_ <1.0e30) { 5216 5259 // at root node  double double check 5217 5260 bool saveTakeHint; … … 5227 5270 } 5228 5271 } 5272 if (feasible&&!solverCharacteristics_>solutionAddsCuts()) { 5273 //double increment = getDblParam(CbcModel::CbcCutoffIncrement) ; 5274 double cutoff ; 5275 solver_>getDblParam(OsiDualObjectiveLimit,cutoff) ; 5276 double distance = fabs(cutoffsolver_>getObjValue()); 5277 if (distance<10.0*trueIncrement) { 5278 double offset; 5279 solver_>getDblParam(OsiObjOffset,offset); 5280 double objFixedValue = offset; 5281 double objValue=0.0; 5282 double direction = solver_>getObjSense(); 5283 const double * solution = solver_>getColSolution(); 5284 const double * objective = solver_>getObjCoefficients(); 5285 const double * columnLower = solver_>getColLower(); 5286 const double * columnUpper = solver_>getColUpper(); 5287 int numberColumns = solver_>getNumCols(); 5288 int increment = 0 ; 5289 double multiplier = 1.0/trueIncrement; 5290 int bigIntegers = 0; // Count of large costs which are integer 5291 for (int iColumn=0;iColumn<numberColumns;iColumn++) { 5292 double value = solution[iColumn]; 5293 // make sure clean 5294 value = CoinMin(value,columnUpper[iColumn]); 5295 value = CoinMax(value,columnLower[iColumn]); 5296 double cost = direction * objective[iColumn]; 5297 if (cost) { 5298 if (columnLower[iColumn]<columnUpper[iColumn]) { 5299 objValue += value*cost; 5300 value = fabs(cost)*multiplier ; 5301 if (value <2.1e9) { 5302 int nearest = (int) floor(value+0.5) ; 5303 assert (fabs(valuefloor(value+0.5)) < 1.0e8); 5304 if (!increment) 5305 increment = nearest ; 5306 else 5307 increment = gcd(increment,nearest) ; 5308 } else { 5309 // large value  may still be multiple of 1.0 5310 value = fabs(objective[iColumn]); 5311 assert(fabs(valuefloor(value+0.5)) < 1.0e8); 5312 bigIntegers++; 5313 } 5314 } else { 5315 // fixed 5316 objFixedValue += value*cost; 5317 } 5318 } 5319 } 5320 if (increment) { 5321 double value = increment ; 5322 value /= multiplier ; 5323 if (value>trueIncrement) { 5324 double x = objValue/value; 5325 x = ceil(x1.0e5); 5326 x *= value; 5327 //printf("fixed %g, variable %g > %g, sum %g  cutoff %g\n", 5328 // objFixedValue,objValue,x,x+objFixedValue,cutoff); 5329 x += objFixedValue; 5330 if (x>cutoff + 1.0e5*fabs(cutoff)+1.0e5) { 5331 //printf("Node cutoff\n"); 5332 feasible=false; 5333 } 5334 } else { 5335 value = trueIncrement; 5336 double x = objValue/value; 5337 x = ceil(x1.0e5); 5338 x *= value; 5339 x += objFixedValue; 5340 if (x>cutoff + 1.0e5*fabs(cutoff)+1.0e5) { 5341 //printf("Node cutoff\n"); 5342 feasible=false; 5343 } 5344 } 5345 } 5346 } 5347 } 5348 5229 5349 setPointers(solver_); 5230 5350 int returnStatus = feasible ? 1 : 0; … … 5504 5624 delete [] element; 5505 5625 newModel>addObjects(numberCliques,object); 5626 assert (ownObjects_); 5506 5627 for (;i<numberCliques;i++) 5507 5628 delete object[i]; … … 5510 5631 return newModel; 5511 5632 } else { 5633 assert (ownObjects_); 5512 5634 if (numberCliques>0) { 5513 5635 addObjects(numberCliques,object); … … 5651 5773 CbcModel::deleteObjects(bool getIntegers) 5652 5774 { 5653 int i; 5654 for (i=0;i<numberObjects_;i++) 5655 delete object_[i]; 5656 delete [] object_; 5775 if (ownObjects_) { 5776 int i; 5777 for (i=0;i<numberObjects_;i++) 5778 delete object_[i]; 5779 delete [] object_; 5780 } 5657 5781 object_ = NULL; 5658 5782 numberObjects_=0; 5659 if (getIntegers )5783 if (getIntegers&&ownObjects_) 5660 5784 findIntegers(true); 5661 5785 } … … 5943 6067 } 5944 6068 delete [] mark; 6069 assert (ownObjects_); 5945 6070 delete [] object_; 5946 6071 object_ = temp; … … 6056 6181 } 6057 6182 delete [] mark; 6183 assert (ownObjects_); 6058 6184 delete [] object_; 6059 6185 object_ = temp; … … 7097 7223 bool weak) 7098 7224 { 7225 printf("DEPRECATED\n"); 7099 7226 status_ = 0; 7100 7227 // solve LP … … 7222 7349 double value = fabs(objective[iColumn])*multiplier; 7223 7350 int nearest = (int) floor(value+0.5); 7224 if (fabs(valuefloor(value+0.5))>1.0e8 ) {7351 if (fabs(valuefloor(value+0.5))>1.0e8value>2.1e9) { 7225 7352 increment=0; 7226 7353 break; // no good
Note: See TracChangeset
for help on using the changeset viewer.