Ignore:
Timestamp:
Nov 21, 2014 5:57:22 AM (6 years ago)
Author:
forrest
Message:

try and improve memory leaks (and clean up Clp pthread build problem)

File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/Cbc/src/CbcNode.cpp

    r2096 r2097  
    6666{
    6767#ifdef CHECK_NODE
    68     printf("CbcNode %x Constructor\n", this);
     68    printf("CbcNode %p Constructor\n", this);
    6969#endif
    7070}
     
    8989{
    9090#ifdef CHECK_NODE
    91     printf("CbcNode %x Constructor from model\n", this);
     91    printf("CbcNode %p Constructor from model\n", this);
    9292#endif
    9393    model->setObjectiveValue(this, lastNode);
     
    41004100  double * originalSolution;
    41014101  CoinWarmStart * ws;
     4102  double * newObjective;
    41024103# ifdef COIN_HAS_CLP
    41034104  ClpDualRowSteepest * dualRowPivot;
     
    41114112  StrongInfo * choice;
    41124113  OsiSolverInterface * solver;
     4114  double * tempSolution;
     4115  CoinWarmStart * tempBasis;
    41134116  int whichChoice;
    41144117} StrongBundle;
     
    41434146  for (int iWay=0;iWay<2;iWay++) {
    41444147    if (choice->numIters[iWay]==0) {
     4148      int numberColumns=solver->getNumCols();
    41454149      if (solveType!=100) {
    41464150        double saveBound;
     
    41974201        int numberModified=0;
    41984202        double sumModified=0.0;
    4199         int numberColumns=solver->getNumCols();
    42004203        int numberInfeas=0;
    42014204        for (int i=0;i<numberColumns;i++) {
     
    42354238        choice->movement[iWay] = newObjectiveValue ;
    42364239      } else {
     4240# ifdef COIN_HAS_CLP
     4241        OsiClpSolverInterface * osiclp = dynamic_cast< OsiClpSolverInterface*> (solver);
     4242        ClpSimplex * simplex = osiclp ? osiclp->getModelPtr() : NULL;
     4243#endif
    42374244        // doing continuous and general integer
    42384245        solver->setColSolution(staticInfo->originalSolution);
     
    42414248        double newBound;
    42424249        if (iWay==0) {
    4243           solver->setObjCoeff(iColumn,1.0);
    42444250          saveBound=solver->getColUpper()[iColumn];
    42454251          solver->setColUpper(iColumn,choice->downUpperBound);
    42464252          newBound=choice->downUpperBound;
    42474253        } else {
    4248           solver->setObjCoeff(iColumn,-1.0);
    42494254          saveBound=solver->getColLower()[iColumn];
    42504255          solver->setColLower(iColumn,choice->upLowerBound);
    42514256          newBound=choice->upLowerBound;
    42524257        }
     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
    42534264        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
    42544270        solver->resolve();
    42554271        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
    42564278          solver->setColUpper(iColumn,saveBound);
    42574279        } 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
    42584286          solver->setColLower(iColumn,saveBound);
    42594287        }
     
    42654293          choice->movement[iWay] = newBound;
    42664294        } 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          }
    42674305          solver->setColSolution(staticInfo->originalSolution);
    42684306          solver->setWarmStart(staticInfo->ws);
     
    42734311          choice->movement[iWay] = solver->getColSolution()[iColumn];
    42744312          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);
    42754325          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.0e-3) {
     4332#endif
    42764333            choice->modified[0]=1;
    42774334            returnStatus=1;
     4335            solver->writeMps("bad","mps");
     4336            abort();
     4337# ifdef COIN_HAS_CLP
     4338            }
     4339#endif
    42784340          }
    42794341        }
    4280         solver->setObjCoeff(iColumn,0.0);
     4342        //solver->setObjCoeff(iColumn,0.0);
    42814343      }
    42824344    }
     
    42844346  return returnStatus;
    42854347}
    4286 #ifdef CBC_THREAD
     4348#ifdef THREADS_IN_ANALYZE
    42874349void * cbc_parallelManager(void * stuff)
    42884350{
     
    43174379    if (unLock==3)
    43184380      unLock=0;
    4319     //printf("child pointer %x status %d\n",threadInfo,threadInfo->status);
     4381    //printf("child pointer %p status %d\n",threadInfo,threadInfo->status);
    43204382    assert(threadInfo->status>=0);
    43214383    if (threadInfo->status==1000)
     
    45584620  StrongInfo * choices = new StrongInfo[maxChoices];
    45594621  StrongStaticInfo staticInfo;
    4560   StrongBundle * bundles = new StrongBundle[CoinMax(1,numberThreads)];
     4622  int numberBundles = CoinMax(1,numberThreads);
     4623  StrongBundle * bundles = new StrongBundle[numberBundles];
    45614624  /*
    45624625    0 - available - no need to look at results
     
    45934656  }
    45944657#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));
    45964660    bundles[i].staticInfo=&staticInfo;
    4597 #if defined (CBC_THREAD) && defined (COIN_HAS_CLP)
     4661  }
     4662#if defined (THREADS_IN_ANALYZE) && defined (COIN_HAS_CLP)
    45984663#define USE_STRONG_THREADS
    45994664  CoinPthreadStuff threadInfo(numberThreads,cbc_parallelManager);
     
    51435208  if ((solveType&2)!=0) {
    51445209# 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(saveOptions|2048); // off crunch
     5214    }
    51485215#endif
    51495216    double * newLower = new double [2*numberColumns];
     
    51515218    // look at ints/all - should be parametrics - for now primal
    51525219    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.0e-4;
     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    }
    51535247    //temp->setHintParam(OsiDoDualInResolve, false, OsiHintDo) ;
    51545248    temp->setHintParam(OsiDoReducePrint, true, OsiHintTry);
     
    51665260    ws = temp->getWarmStart();
    51675261    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.0e-4;
    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)
    52005266    for (int iThread=0;iThread<numberThreads;iThread++) {
    52015267      OsiSolverInterface * solver=
     
    53185384          // go down
    53195385          double value = choice.movement[0];
    5320           if (value>newLower[iColumn]+10.0*integerTolerance) {
     5386          if (value>newLower[iColumn]+100.0*integerTolerance) {
    53215387            if (back[iColumn]>=0)
    53225388              value = ceil(value);
    53235389            else
    5324               value = CoinMax(newLower[iColumn],value-1.0e-7-1.0e-8*fabs(value));
     5390              value = CoinMax(newLower[iColumn],value-1.0e-5-1.0e-8*fabs(value));
    53255391            if (value>newLower[iColumn]+1.0e-8*(1.0+fabs(value))) {
    53265392              sprintf(general,"Secondary analysis solve increases lower bound on %d from %g to %g%s",
     
    53445410          // go up
    53455411          double value=choice.movement[1];
    5346           if (value<newUpper[iColumn]-10.0*integerTolerance) {
     5412          if (value<newUpper[iColumn]-100.0*integerTolerance) {
    53475413            if (back[iColumn]>=0)
    53485414              value = floor(value);
    53495415            else
    5350               value = CoinMin(newUpper[iColumn],value+1.0e-7+1.0e-8*fabs(value));
     5416              value = CoinMin(newUpper[iColumn],value+1.0e-5+1.0e-8*fabs(value));
    53515417            if (value<newUpper[iColumn]-1.0e-8*(1.0+fabs(value))) {
    53525418              sprintf(general,"Secondary analysis solve decreases upper bound on %d from %g to %g%s",
     
    54005466    delete temp;
    54015467    delete [] newLower;
     5468# ifdef COIN_HAS_CLP
     5469    if (osiclp) {
     5470      //ClpPrimalColumnPivot * primalColumnPivot=NULL;
     5471      osiclp->setSpecialOptions(saveOptions);
     5472    }
     5473#endif
    54025474  }
     5475  delete [] staticInfo.newObjective;
    54035476# ifdef COIN_HAS_CLP
    54045477  if (osiclp) {
     
    54395512  }
    54405513  delete [] choices;
     5514  for (int i=0;i<numberBundles;i++) {
     5515    delete [] bundles[i].tempSolution;
     5516    delete bundles[i].tempBasis;
     5517  }
    54415518  delete [] bundles;
    54425519#ifdef USE_STRONG_THREADS
     
    55155592{
    55165593#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);
    55185595#endif
    55195596    if (rhs.nodeInfo_)
     
    55695646#ifdef CHECK_NODE
    55705647    if (nodeInfo_) {
    5571         printf("CbcNode %x Destructor nodeInfo %x (%d)\n",
     5648        printf("CbcNode %p Destructor nodeInfo %p (%d)\n",
    55725649               this, nodeInfo_, nodeInfo_->numberPointingToThis());
    55735650        //assert(nodeInfo_->numberPointingToThis()>=0);
    55745651    } else {
    5575         printf("CbcNode %x Destructor nodeInfo %x (?)\n",
     5652        printf("CbcNode %p Destructor nodeInfo %p (?)\n",
    55765653               this, nodeInfo_);
    55775654    }
     
    55885665            delete nodeInfo_;
    55895666        } 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());
    55915668            // anyway decrement parent
    55925669            //if (parent)
Note: See TracChangeset for help on using the changeset viewer.