Ignore:
Timestamp:
Apr 6, 2013 9:33:15 AM (6 years ago)
Author:
stefan
Message:

sync with trunk rev 1882

Location:
stable/2.8/Cbc
Files:
2 edited

Legend:

Unmodified
Added
Removed
  • stable/2.8/Cbc

  • stable/2.8/Cbc/src/CbcGeneralDepth.cpp

    r1854 r1883  
    2323#include "CbcGeneralDepth.hpp"
    2424#include "CbcBranchActual.hpp"
     25#include "CbcHeuristicDive.hpp"
    2526#include "CoinSort.hpp"
    2627#include "CoinError.hpp"
     
    160161        = dynamic_cast<OsiClpSolverInterface *> (solver);
    161162        if (clpSolver) {
     163          if ((model_->moreSpecialOptions()&33554432)==0) {
    162164            ClpNodeStuff * info = nodeInfo_;
    163165            info->integerTolerance_ = model_->getIntegerTolerance();
     
    246248            simplex->setLogLevel(saveLevel);
    247249            numberNodes_ = info->nNodes_;
    248             int numberDo = numberNodes_;
    249             if (whichSolution_ >= 0)
    250                 numberDo--;
    251             if (numberDo > 0) {
    252                 return 0.5;
    253             } else {
    254                 // no solution
    255                 return COIN_DBL_MAX; // say infeasible
    256             }
     250          } else {
     251            // Try diving
     252            // See if any diving heuristics set to do dive+save
     253            CbcHeuristicDive * dive=NULL;
     254            for (int i = 0; i < model_->numberHeuristics(); i++) {
     255              CbcHeuristicDive * possible = dynamic_cast<CbcHeuristicDive *>(model_->heuristic(i));
     256              if (possible&&possible->maxSimplexIterations()==COIN_INT_MAX) {
     257                // if more than one then rotate later?
     258                //if (possible->canHeuristicRun()) {
     259                dive=possible;
     260                break;
     261              }
     262            }
     263            assert (dive); // otherwise moreSpecial should have been turned off
     264            CbcSubProblem ** nodes=NULL;
     265            int branchState=dive->fathom(model_,numberNodes_,nodes);
     266            if (branchState) {
     267              printf("new solution\n");
     268              whichSolution_=numberNodes_-1;
     269            } else {
     270              whichSolution_=-1;
     271            }
     272#if 0
     273            if (0) {
     274              for (int iNode=0;iNode<numberNodes;iNode++) {
     275                //tree_->push(nodes[iNode]) ;
     276              }
     277              assert (node->nodeInfo());
     278              if (node->nodeInfo()->numberBranchesLeft()) {
     279                tree_->push(node) ;
     280              } else {
     281                node->setActive(false);
     282              }
     283            }
     284#endif
     285            //delete [] nodes;
     286            model_->setTemporaryPointer(reinterpret_cast<void *>(nodes));
     287            // end try diving
     288          }
     289          int numberDo = numberNodes_;
     290          if (numberDo > 0 || whichSolution_ >= 0) {
     291            return 0.5;
     292          } else {
     293            // no solution
     294            return COIN_DBL_MAX; // say infeasible
     295          }
    257296        } else {
    258297            return -1.0;
     
    284323#endif
    285324CbcBranchingObject *
    286 CbcGeneralDepth::createCbcBranch(OsiSolverInterface * solver, const OsiBranchingInformation * /*info*/, int /*way*/)
     325CbcGeneralDepth::createCbcBranch(OsiSolverInterface * solver, const OsiBranchingInformation * info, int /*way*/)
    287326{
    288327    int numberDo = numberNodes_;
    289     if (whichSolution_ >= 0)
     328    if (whichSolution_ >= 0 && (model_->moreSpecialOptions()&33554432)==0)
    290329        numberDo--;
    291330    assert (numberDo > 0);
     
    308347    ClpSimplex * simplex = clpSolver->getModelPtr();
    309348    int numberColumns = simplex->numberColumns();
    310     double * lowerBefore = CoinCopyOfArray(simplex->getColLower(),
    311                                            numberColumns);
    312     double * upperBefore = CoinCopyOfArray(simplex->getColUpper(),
    313                                            numberColumns);
    314     ClpNodeStuff * info = nodeInfo_;
    315     double * weight = new double[numberNodes_];
    316     int * whichNode = new int [numberNodes_];
    317     // Sort
    318     for (iNode = 0; iNode < numberNodes_; iNode++) {
     349    if ((model_->moreSpecialOptions()&33554432)==0) {
     350      double * lowerBefore = CoinCopyOfArray(simplex->getColLower(),
     351                                             numberColumns);
     352      double * upperBefore = CoinCopyOfArray(simplex->getColUpper(),
     353                                             numberColumns);
     354      ClpNodeStuff * info = nodeInfo_;
     355      double * weight = new double[numberNodes_];
     356      int * whichNode = new int [numberNodes_];
     357      // Sort
     358      for (iNode = 0; iNode < numberNodes_; iNode++) {
    319359        if (iNode != whichSolution_) {
    320             double objectiveValue = info->nodeInfo_[iNode]->objectiveValue();
    321             double sumInfeasibilities = info->nodeInfo_[iNode]->sumInfeasibilities();
    322             int numberInfeasibilities = info->nodeInfo_[iNode]->numberInfeasibilities();
    323             double thisWeight = 0.0;
     360          double objectiveValue = info->nodeInfo_[iNode]->objectiveValue();
     361          double sumInfeasibilities = info->nodeInfo_[iNode]->sumInfeasibilities();
     362          int numberInfeasibilities = info->nodeInfo_[iNode]->numberInfeasibilities();
     363          double thisWeight = 0.0;
    324364#if 1
    325             // just closest
    326             thisWeight = 1.0e9 * numberInfeasibilities;
    327             thisWeight += sumInfeasibilities;
    328             thisWeight += 1.0e-7 * objectiveValue;
    329             // Try estimate
    330             thisWeight = info->nodeInfo_[iNode]->estimatedSolution();
     365          // just closest
     366          thisWeight = 1.0e9 * numberInfeasibilities;
     367          thisWeight += sumInfeasibilities;
     368          thisWeight += 1.0e-7 * objectiveValue;
     369          // Try estimate
     370          thisWeight = info->nodeInfo_[iNode]->estimatedSolution();
    331371#else
    332             thisWeight = 1.0e-3 * numberInfeasibilities;
    333             thisWeight += 1.0e-5 * sumInfeasibilities;
    334             thisWeight += objectiveValue;
     372          thisWeight = 1.0e-3 * numberInfeasibilities;
     373          thisWeight += 1.0e-5 * sumInfeasibilities;
     374          thisWeight += objectiveValue;
    335375#endif
    336             whichNode[iProb] = iNode;
    337             weight[iProb++] = thisWeight;
    338         }
    339     }
    340     assert (iProb == numberDo);
    341     CoinSort_2(weight, weight + numberDo, whichNode);
    342     for (iProb = 0; iProb < numberDo; iProb++) {
     376          whichNode[iProb] = iNode;
     377          weight[iProb++] = thisWeight;
     378        }
     379      }
     380      assert (iProb == numberDo);
     381      CoinSort_2(weight, weight + numberDo, whichNode);
     382      for (iProb = 0; iProb < numberDo; iProb++) {
    343383        iNode = whichNode[iProb];
    344384        ClpNode * node = info->nodeInfo_[iNode];
     
    353393#ifdef CHECK_PATH
    354394        if (simplex->numberColumns() == numberColumns_Z) {
    355             bool onOptimal = true;
    356             const double * columnLower = simplex->columnLower();
    357             const double * columnUpper = simplex->columnUpper();
    358             for (int i = 0; i < numberColumns_Z; i++) {
    359                 if (iNode == gotGoodNode_Z)
    360                     printf("good %d %d %g %g\n", iNode, i, columnLower[i], columnUpper[i]);
    361                 if (columnUpper[i] < debuggerSolution_Z[i] || columnLower[i] > debuggerSolution_Z[i] && simplex->isInteger(i)) {
    362                     onOptimal = false;
    363                     break;
    364                 }
    365             }
    366             if (onOptimal) {
    367                 printf("adding to node %x as %d - objs\n", this, iProb);
    368                 for (int j = 0; j <= iProb; j++)
    369                     printf("%d %g\n", j, sub[j].objectiveValue_);
    370             }
     395          bool onOptimal = true;
     396          const double * columnLower = simplex->columnLower();
     397          const double * columnUpper = simplex->columnUpper();
     398          for (int i = 0; i < numberColumns_Z; i++) {
     399            if (iNode == gotGoodNode_Z)
     400              printf("good %d %d %g %g\n", iNode, i, columnLower[i], columnUpper[i]);
     401            if (columnUpper[i] < debuggerSolution_Z[i] || columnLower[i] > debuggerSolution_Z[i] && simplex->isInteger(i)) {
     402              onOptimal = false;
     403              break;
     404            }
     405          }
     406          if (onOptimal) {
     407            printf("adding to node %x as %d - objs\n", this, iProb);
     408            for (int j = 0; j <= iProb; j++)
     409              printf("%d %g\n", j, sub[j].objectiveValue_);
     410          }
    371411        }
    372412#endif
    373     }
    374     delete [] weight;
    375     delete [] whichNode;
    376     const double * lower = solver->getColLower();
    377     const double * upper = solver->getColUpper();
    378     // restore bounds
    379     for ( int j = 0; j < numberColumns; j++) {
     413      }
     414      delete [] weight;
     415      delete [] whichNode;
     416      const double * lower = solver->getColLower();
     417      const double * upper = solver->getColUpper();
     418      // restore bounds
     419      for ( int j = 0; j < numberColumns; j++) {
    380420        if (lowerBefore[j] != lower[j])
    381             solver->setColLower(j, lowerBefore[j]);
     421          solver->setColLower(j, lowerBefore[j]);
    382422        if (upperBefore[j] != upper[j])
    383             solver->setColUpper(j, upperBefore[j]);
    384     }
    385     delete [] upperBefore;
    386     delete [] lowerBefore;
     423          solver->setColUpper(j, upperBefore[j]);
     424      }
     425      delete [] upperBefore;
     426      delete [] lowerBefore;
     427    } else {
     428      // from diving
     429      CbcSubProblem ** nodes = reinterpret_cast<CbcSubProblem **>
     430        (model_->temporaryPointer());
     431      assert (nodes);
     432      int adjustDepth=info->depth_;
     433      assert (numberDo);
     434      numberNodes_=0;
     435      for (iProb = 0; iProb < numberDo; iProb++) {
     436        if ((nodes[iProb]->problemStatus_&2)==0) {
     437          // create subproblem (and swap way and/or make inactive)
     438          sub[numberNodes_].takeOver(*nodes[iProb],true);
     439          // but adjust depth
     440          sub[numberNodes_].depth_+=adjustDepth;
     441          numberNodes_++;
     442        }
     443        delete nodes[iProb];
     444      }
     445      branch->numberSubProblems_ = numberNodes_;
     446      branch->numberSubLeft_ = numberNodes_;
     447      branch->setNumberBranches(numberNodes_);
     448      if (!numberNodes_) {
     449        // infeasible
     450        delete branch;
     451        branch=NULL;
     452      }
     453      delete [] nodes;
     454    }
    387455    return branch;
    388456}
Note: See TracChangeset for help on using the changeset viewer.