Changeset 2097 for trunk/Cbc/src/CbcNode.cpp
 Timestamp:
 Nov 21, 2014 5:57:22 AM (6 years ago)
 File:

 1 edited
Legend:
 Unmodified
 Added
 Removed

trunk/Cbc/src/CbcNode.cpp
r2096 r2097 66 66 { 67 67 #ifdef CHECK_NODE 68 printf("CbcNode % xConstructor\n", this);68 printf("CbcNode %p Constructor\n", this); 69 69 #endif 70 70 } … … 89 89 { 90 90 #ifdef CHECK_NODE 91 printf("CbcNode % xConstructor from model\n", this);91 printf("CbcNode %p Constructor from model\n", this); 92 92 #endif 93 93 model>setObjectiveValue(this, lastNode); … … 4100 4100 double * originalSolution; 4101 4101 CoinWarmStart * ws; 4102 double * newObjective; 4102 4103 # ifdef COIN_HAS_CLP 4103 4104 ClpDualRowSteepest * dualRowPivot; … … 4111 4112 StrongInfo * choice; 4112 4113 OsiSolverInterface * solver; 4114 double * tempSolution; 4115 CoinWarmStart * tempBasis; 4113 4116 int whichChoice; 4114 4117 } StrongBundle; … … 4143 4146 for (int iWay=0;iWay<2;iWay++) { 4144 4147 if (choice>numIters[iWay]==0) { 4148 int numberColumns=solver>getNumCols(); 4145 4149 if (solveType!=100) { 4146 4150 double saveBound; … … 4197 4201 int numberModified=0; 4198 4202 double sumModified=0.0; 4199 int numberColumns=solver>getNumCols();4200 4203 int numberInfeas=0; 4201 4204 for (int i=0;i<numberColumns;i++) { … … 4235 4238 choice>movement[iWay] = newObjectiveValue ; 4236 4239 } else { 4240 # ifdef COIN_HAS_CLP 4241 OsiClpSolverInterface * osiclp = dynamic_cast< OsiClpSolverInterface*> (solver); 4242 ClpSimplex * simplex = osiclp ? osiclp>getModelPtr() : NULL; 4243 #endif 4237 4244 // doing continuous and general integer 4238 4245 solver>setColSolution(staticInfo>originalSolution); … … 4241 4248 double newBound; 4242 4249 if (iWay==0) { 4243 solver>setObjCoeff(iColumn,1.0);4244 4250 saveBound=solver>getColUpper()[iColumn]; 4245 4251 solver>setColUpper(iColumn,choice>downUpperBound); 4246 4252 newBound=choice>downUpperBound; 4247 4253 } else { 4248 solver>setObjCoeff(iColumn,1.0);4249 4254 saveBound=solver>getColLower()[iColumn]; 4250 4255 solver>setColLower(iColumn,choice>upLowerBound); 4251 4256 newBound=choice>upLowerBound; 4252 4257 } 4258 # if 0 //def COIN_HAS_CLP 4259 if (simplex) { 4260 // set solution to new bound (if basic will be recomputed) 4261 simplex>primalColumnSolution()[iColumn]=newBound; 4262 } 4263 #endif 4253 4264 solver>setHintParam(OsiDoDualInResolve, true, OsiHintDo) ; 4265 #define PRINT_ANALYZE 0 4266 #if PRINT_ANALYZE>0 4267 osiclp>getModelPtr()>setLogLevel(1); 4268 solver>setHintParam(OsiDoReducePrint, false, OsiHintTry); 4269 #endif 4254 4270 solver>resolve(); 4255 4271 if (iWay==0) { 4272 #if PRINT_ANALYZE>0 4273 printf("column %d down original %g <= %g <= %g upper now %g  result %s\n", 4274 iColumn,solver>getColLower()[iColumn], 4275 staticInfo>originalSolution[iColumn],saveBound, 4276 newBound,solver>isProvenOptimal() ? "ok" : "infeas"); 4277 #endif 4256 4278 solver>setColUpper(iColumn,saveBound); 4257 4279 } else { 4280 #if PRINT_ANALYZE>0 4281 printf("column %d up original %g <= %g <= %g lower now %g  result %s\n", 4282 iColumn,saveBound,staticInfo>originalSolution[iColumn], 4283 solver>getColUpper()[iColumn], 4284 newBound,solver>isProvenOptimal() ? "ok" : "infeas"); 4285 #endif 4258 4286 solver>setColLower(iColumn,saveBound); 4259 4287 } … … 4265 4293 choice>movement[iWay] = newBound; 4266 4294 } else { 4295 // zero objective 4296 double offset; 4297 solver>getDblParam(OsiObjOffset,offset); 4298 solver>setDblParam(OsiObjOffset, 0.0); 4299 solver>setObjective(staticInfo>newObjective+numberColumns); 4300 if (iWay==0) { 4301 solver>setObjCoeff(iColumn,1.0); 4302 } else { 4303 solver>setObjCoeff(iColumn,1.0); 4304 } 4267 4305 solver>setColSolution(staticInfo>originalSolution); 4268 4306 solver>setWarmStart(staticInfo>ws); … … 4273 4311 choice>movement[iWay] = solver>getColSolution()[iColumn]; 4274 4312 choice>numIters[iWay] += solver>getIterationCount(); 4313 #if PRINT_ANALYZE>0 4314 if (iWay==0) { 4315 printf("column %d down can get to %g  result %s\n", 4316 iColumn,solver>getColSolution()[iColumn],solver>isProvenOptimal() ? "ok" : "infeas"); 4317 } else { 4318 printf("column %d up can get to %g  result %s\n", 4319 iColumn,solver>getColSolution()[iColumn],solver>isProvenOptimal() ? "ok" : "infeas"); 4320 } 4321 #endif 4322 // reset objective 4323 solver>setDblParam(OsiObjOffset, offset); 4324 solver>setObjective(staticInfo>newObjective); 4275 4325 if (!solver>isProvenOptimal()) { 4326 # ifdef COIN_HAS_CLP 4327 OsiClpSolverInterface * osiclp = dynamic_cast< OsiClpSolverInterface*> (solver); 4328 ClpSimplex * simplex = osiclp>getModelPtr(); 4329 double sum = simplex>sumPrimalInfeasibilities(); 4330 sum /= static_cast<double>(simplex>numberPrimalInfeasibilities()); 4331 if (sum>1.0e3) { 4332 #endif 4276 4333 choice>modified[0]=1; 4277 4334 returnStatus=1; 4335 solver>writeMps("bad","mps"); 4336 abort(); 4337 # ifdef COIN_HAS_CLP 4338 } 4339 #endif 4278 4340 } 4279 4341 } 4280 solver>setObjCoeff(iColumn,0.0);4342 //solver>setObjCoeff(iColumn,0.0); 4281 4343 } 4282 4344 } … … 4284 4346 return returnStatus; 4285 4347 } 4286 #ifdef CBC_THREAD4348 #ifdef THREADS_IN_ANALYZE 4287 4349 void * cbc_parallelManager(void * stuff) 4288 4350 { … … 4317 4379 if (unLock==3) 4318 4380 unLock=0; 4319 //printf("child pointer % xstatus %d\n",threadInfo,threadInfo>status);4381 //printf("child pointer %p status %d\n",threadInfo,threadInfo>status); 4320 4382 assert(threadInfo>status>=0); 4321 4383 if (threadInfo>status==1000) … … 4558 4620 StrongInfo * choices = new StrongInfo[maxChoices]; 4559 4621 StrongStaticInfo staticInfo; 4560 StrongBundle * bundles = new StrongBundle[CoinMax(1,numberThreads)]; 4622 int numberBundles = CoinMax(1,numberThreads); 4623 StrongBundle * bundles = new StrongBundle[numberBundles]; 4561 4624 /* 4562 4625 0  available  no need to look at results … … 4593 4656 } 4594 4657 #endif 4595 for (int i=0;i<CoinMax(1,numberThreads);i++) 4658 for (int i=0;i<numberBundles;i++) { 4659 memset(bundles+i,0,sizeof(StrongBundle)); 4596 4660 bundles[i].staticInfo=&staticInfo; 4597 #if defined (CBC_THREAD) && defined (COIN_HAS_CLP) 4661 } 4662 #if defined (THREADS_IN_ANALYZE) && defined (COIN_HAS_CLP) 4598 4663 #define USE_STRONG_THREADS 4599 4664 CoinPthreadStuff threadInfo(numberThreads,cbc_parallelManager); … … 5143 5208 if ((solveType&2)!=0) { 5144 5209 # ifdef COIN_HAS_CLP 5145 if (osiclp&&(solveType&2)!=0) { 5146 ClpPrimalColumnPivot * primalColumnPivot=NULL; 5147 } 5210 int saveOptions = osiclp ? osiclp>specialOptions() : 0; 5211 if (osiclp) { 5212 //ClpPrimalColumnPivot * primalColumnPivot=NULL; 5213 osiclp>setSpecialOptions(saveOptions2048); // off crunch 5214 } 5148 5215 #endif 5149 5216 double * newLower = new double [2*numberColumns]; … … 5151 5218 // look at ints/all  should be parametrics  for now primal 5152 5219 OsiSolverInterface * temp = solver>clone(); 5220 // add constraint 5221 int * indices = reinterpret_cast<int *>(newUpper); 5222 double * obj = newLower; 5223 memcpy(obj,solver>getObjCoefficients(),numberColumns*sizeof(double)); 5224 int n=0; 5225 for (int i=0;i<numberColumns;i++) { 5226 if (obj[i]) { 5227 indices[n]=i; 5228 obj[n++]=obj[i]; 5229 } 5230 } 5231 if (n) { 5232 double cutoff=model>getCutoff(); 5233 // relax a little bit 5234 cutoff += 1.0e4; 5235 double offset; 5236 temp>getDblParam(OsiObjOffset, offset); 5237 temp>addRow(n,indices,obj,COIN_DBL_MAX,CoinMin(cutoff,1.0e25)+offset); 5238 temp>setDblParam(OsiObjOffset, 0.0); 5239 #if defined (THREADS_IN_ANALYZE) && defined (COIN_HAS_CLP) 5240 for (int iThread=0;iThread<numberThreads;iThread++) { 5241 OsiSolverInterface * solver= 5242 reinterpret_cast<OsiSolverInterface *>(threadInfo.threadInfo_[iThread].extraInfo2); 5243 solver>addRow(n,indices,obj,COIN_DBL_MAX,CoinMin(cutoff,1.0e25)+offset); 5244 } 5245 #endif 5246 } 5153 5247 //temp>setHintParam(OsiDoDualInResolve, false, OsiHintDo) ; 5154 5248 temp>setHintParam(OsiDoReducePrint, true, OsiHintTry); … … 5166 5260 ws = temp>getWarmStart(); 5167 5261 staticInfo.ws=ws; 5168 // add constraint 5169 int * indices = reinterpret_cast<int *>(newUpper); 5170 double * obj = newLower; 5171 memcpy(obj,solver>getObjCoefficients(),numberColumns*sizeof(double)); 5172 int n=0; 5173 for (int i=0;i<numberColumns;i++) { 5174 if (obj[i]) { 5175 indices[n]=i; 5176 obj[n++]=obj[i]; 5177 } 5178 } 5179 if (n) { 5180 double cutoff=model>getCutoff(); 5181 // relax a little bit 5182 cutoff += 1.0e4; 5183 double offset; 5184 temp>getDblParam(OsiObjOffset, offset); 5185 temp>addRow(n,indices,obj,COIN_DBL_MAX,CoinMin(cutoff,1.0e25)+offset); 5186 #if defined (CBC_THREAD) && defined (COIN_HAS_CLP) 5187 for (int iThread=0;iThread<numberThreads;iThread++) { 5188 OsiSolverInterface * solver= 5189 reinterpret_cast<OsiSolverInterface *>(threadInfo.threadInfo_[iThread].extraInfo2); 5190 solver>addRow(n,indices,obj,COIN_DBL_MAX,CoinMin(cutoff,1.0e25)+offset); 5191 } 5192 #endif 5193 } 5194 // zero objective 5195 for (int i = 0; i < numberColumns; i++) { 5196 newLower[i]=0.0; 5197 } 5198 temp>setObjective(newLower); 5199 #if defined (CBC_THREAD) && defined (COIN_HAS_CLP) 5262 staticInfo.newObjective = new double[2*numberColumns]; 5263 memcpy(staticInfo.newObjective,solver>getObjCoefficients(),numberColumns*sizeof(double)); 5264 memset(staticInfo.newObjective+numberColumns,0,numberColumns*sizeof(double)); 5265 #if defined (THREADS_IN_ANALYZE) && defined (COIN_HAS_CLP) 5200 5266 for (int iThread=0;iThread<numberThreads;iThread++) { 5201 5267 OsiSolverInterface * solver= … … 5318 5384 // go down 5319 5385 double value = choice.movement[0]; 5320 if (value>newLower[iColumn]+10 .0*integerTolerance) {5386 if (value>newLower[iColumn]+100.0*integerTolerance) { 5321 5387 if (back[iColumn]>=0) 5322 5388 value = ceil(value); 5323 5389 else 5324 value = CoinMax(newLower[iColumn],value1.0e 71.0e8*fabs(value));5390 value = CoinMax(newLower[iColumn],value1.0e51.0e8*fabs(value)); 5325 5391 if (value>newLower[iColumn]+1.0e8*(1.0+fabs(value))) { 5326 5392 sprintf(general,"Secondary analysis solve increases lower bound on %d from %g to %g%s", … … 5344 5410 // go up 5345 5411 double value=choice.movement[1]; 5346 if (value<newUpper[iColumn]10 .0*integerTolerance) {5412 if (value<newUpper[iColumn]100.0*integerTolerance) { 5347 5413 if (back[iColumn]>=0) 5348 5414 value = floor(value); 5349 5415 else 5350 value = CoinMin(newUpper[iColumn],value+1.0e 7+1.0e8*fabs(value));5416 value = CoinMin(newUpper[iColumn],value+1.0e5+1.0e8*fabs(value)); 5351 5417 if (value<newUpper[iColumn]1.0e8*(1.0+fabs(value))) { 5352 5418 sprintf(general,"Secondary analysis solve decreases upper bound on %d from %g to %g%s", … … 5400 5466 delete temp; 5401 5467 delete [] newLower; 5468 # ifdef COIN_HAS_CLP 5469 if (osiclp) { 5470 //ClpPrimalColumnPivot * primalColumnPivot=NULL; 5471 osiclp>setSpecialOptions(saveOptions); 5472 } 5473 #endif 5402 5474 } 5475 delete [] staticInfo.newObjective; 5403 5476 # ifdef COIN_HAS_CLP 5404 5477 if (osiclp) { … … 5439 5512 } 5440 5513 delete [] choices; 5514 for (int i=0;i<numberBundles;i++) { 5515 delete [] bundles[i].tempSolution; 5516 delete bundles[i].tempBasis; 5517 } 5441 5518 delete [] bundles; 5442 5519 #ifdef USE_STRONG_THREADS … … 5515 5592 { 5516 5593 #ifdef CHECK_NODE 5517 printf("CbcNode % x Constructor from rhs %x\n", this, &rhs);5594 printf("CbcNode %p Constructor from rhs %p\n", this, &rhs); 5518 5595 #endif 5519 5596 if (rhs.nodeInfo_) … … 5569 5646 #ifdef CHECK_NODE 5570 5647 if (nodeInfo_) { 5571 printf("CbcNode % x Destructor nodeInfo %x(%d)\n",5648 printf("CbcNode %p Destructor nodeInfo %p (%d)\n", 5572 5649 this, nodeInfo_, nodeInfo_>numberPointingToThis()); 5573 5650 //assert(nodeInfo_>numberPointingToThis()>=0); 5574 5651 } else { 5575 printf("CbcNode % x Destructor nodeInfo %x(?)\n",5652 printf("CbcNode %p Destructor nodeInfo %p (?)\n", 5576 5653 this, nodeInfo_); 5577 5654 } … … 5588 5665 delete nodeInfo_; 5589 5666 } else { 5590 //printf("node % x nodeinfo %x parent %x\n",this,nodeInfo_,nodeInfo_>parent());5667 //printf("node %p nodeinfo %p parent %p\n",this,nodeInfo_,nodeInfo_>parent()); 5591 5668 // anyway decrement parent 5592 5669 //if (parent)
Note: See TracChangeset
for help on using the changeset viewer.