Changeset 500


Ignore:
Timestamp:
Apr 25, 2007 2:10:48 PM (12 years ago)
Author:
pbonami
Message:

Make CbcModel? model's a member of Bab2

Location:
trunk
Files:
3 edited

Legend:

Unmodified
Added
Removed
  • trunk/Bonmin/src/CbcBonmin/BonCbc2.cpp

    r481 r500  
    6767  numNodes_(0),
    6868  mipIterationCount_(0),
    69   model_(NULL)
     69  model_()
    7070  {}
    7171 
     
    9393    bonBabInfo.setBabPtr(this);
    9494    s.linearSolver()->setAuxiliaryInfo(&bonBabInfo);
    95     CbcModel model(*s.linearSolver());
    96    
    97     model_ = & model;
     95    OsiSolverInterface * solver = s.linearSolver()->clone();
     96    model_.assignSolver(solver, true);
     97   
    9898   
    9999    if(s.linearSolver()->objects()!=NULL){
    100       model.addObjects(s.linearSolver()->numberObjects(),s.linearSolver()->objects());
     100      model_.addObjects(s.linearSolver()->numberObjects(),s.linearSolver()->objects());
    101101    }
    102102   
     
    105105    int specOpt = s.getIntParameter(BabSetupBase::SpecialOption);
    106106    if(specOpt){
    107       model.setSpecialOptions(specOpt);
     107      model_.setSpecialOptions(specOpt);
    108108      if(specOpt==16){
    109109        CbcNlpStrategy strat(s.getIntParameter(BabSetupBase::MaxFailures), s.getIntParameter(BabSetupBase::MaxInfeasible), s.getIntParameter(BabSetupBase::FailureBehavior));
    110         model.setStrategy(strat);
    111       }
    112     }
    113    
    114  
    115  
    116     model.setMaximumCutPasses(1);
     110        model_.setStrategy(strat);
     111      }
     112    }
     113   
     114 
     115 
     116    model_.setMaximumCutPasses(1);
    117117   
    118118    //Setup cutting plane methods
     
    122122      OaDecompositionBase * oa = dynamic_cast<OaDecompositionBase *>(i->cgl);
    123123      if (oa && oa->reassignLpsolver())
    124         oa->assignLpInterface(model.solver());
     124        oa->assignLpInterface(model_.solver());
    125125      if(i->atSolution)
    126         model.addCutGenerator(i->cgl,i->frequency,i->id.c_str(), false, true);
     126        model_.addCutGenerator(i->cgl,i->frequency,i->id.c_str(), false, true);
    127127      else
    128         model.addCutGenerator(i->cgl,i->frequency,i->id.c_str());
     128        model_.addCutGenerator(i->cgl,i->frequency,i->id.c_str());
    129129    }
    130130   
     
    132132        i != s.heuristics().end() ; i++){
    133133      CbcHeuristic * heu = *i;
    134       heu->setModel(&model);
    135       model.addHeuristic(*i);
     134      heu->setModel(&model_);
     135      model_.addHeuristic(*i);
    136136    }
    137137   
    138138    //Set true branch-and-bound parameters
    139     model.setLogLevel(s.getIntParameter(BabSetupBase::BabLogLevel));   
    140     model.setPrintFrequency(s.getIntParameter(BabSetupBase::BabLogInterval));
     139    model_.setLogLevel(s.getIntParameter(BabSetupBase::BabLogLevel));   
     140    model_.setPrintFrequency(s.getIntParameter(BabSetupBase::BabLogInterval));
    141141       
    142142    bool ChangedObject = false;
     
    151151      const int * directions = nlpSolver->getBranchingDirections();
    152152      bool hasPseudo = (upPsCosts!=NULL);
    153       model.findIntegers(true,hasPseudo);
    154       OsiObject ** simpleIntegerObjects = model.objects();
    155       int numberObjects = model.numberObjects();
     153      model_.findIntegers(true,hasPseudo);
     154      OsiObject ** simpleIntegerObjects = model_.objects();
     155      int numberObjects = model_.numberObjects();
    156156      if(priorities != NULL || directions != NULL || hasPseudo)
    157157      {
     
    191191      bool hasPriorities = false;
    192192      const int * varPriorities = nlpSolver->getPriorities();
    193       int numberObjects = model.numberObjects();
     193      int numberObjects = model_.numberObjects();
    194194      if (varPriorities)
    195195      {
     
    215215        int start = starts[i];
    216216        int length = starts[i + 1] - start;
    217         objects[i] = new CbcSOS(&model, length, &indices[start],
     217        objects[i] = new CbcSOS(&model_, length, &indices[start],
    218218                                &weights[start], i, types[i]);
    219219       
     
    223223        }
    224224      }
    225       model.addObjects(numSos, objects);
     225      model_.addObjects(numSos, objects);
    226226      for (int i = 0 ; i < numSos ; i++)
    227227        delete objects[i];
     
    229229    }
    230230   
    231     replaceIntegers(model.objects(), model.numberObjects());
    232    
    233    
    234     model.setDblParam(CbcModel::CbcCutoffIncrement, s.getDoubleParameter(BabSetupBase::CutoffDecr));
    235    
    236     model.setCutoff(s.getDoubleParameter(BabSetupBase::Cutoff));
    237    
    238     model.setDblParam(CbcModel::CbcAllowableGap, s.getDoubleParameter(BabSetupBase::AllowableGap));
    239     model.setDblParam(CbcModel::CbcAllowableFractionGap, s.getDoubleParameter(BabSetupBase::AllowableFractionGap));
     231    replaceIntegers(model_.objects(), model_.numberObjects());
     232   
     233   
     234    model_.setDblParam(CbcModel::CbcCutoffIncrement, s.getDoubleParameter(BabSetupBase::CutoffDecr));
     235   
     236    model_.setCutoff(s.getDoubleParameter(BabSetupBase::Cutoff));
     237   
     238    model_.setDblParam(CbcModel::CbcAllowableGap, s.getDoubleParameter(BabSetupBase::AllowableGap));
     239    model_.setDblParam(CbcModel::CbcAllowableFractionGap, s.getDoubleParameter(BabSetupBase::AllowableFractionGap));
    240240   
    241241    // Definition of node selection strategy
     
    243243    if (s.nodeSelectionMethod()==BabSetupBase::bestBound) {
    244244      CbcCompareObjective compare;
    245       model.setNodeComparison(compare);
     245      model_.setNodeComparison(compare);
    246246    }
    247247    else if (s.nodeSelectionMethod()==BabSetupBase::DFS) {
    248248      CbcCompareDepth compare;
    249       model.setNodeComparison(compare);
     249      model_.setNodeComparison(compare);
    250250    }
    251251    else if (s.nodeSelectionMethod()==BabSetupBase::BFS) {
    252252      CbcCompareUser compare;
    253253      compare.setWeight(0.0);
    254       model.setNodeComparison(compare);
     254      model_.setNodeComparison(compare);
    255255    }
    256256    else if (s.nodeSelectionMethod()==BabSetupBase::dynamic) {
    257257      CbcCompareUser compare;
    258       model.setNodeComparison(compare);
    259     }
    260    
    261     model.setNumberStrong(s.getIntParameter(BabSetupBase::NumberStrong));
    262    
    263     model.setNumberBeforeTrust(s.getIntParameter(BabSetupBase::MinReliability));
    264    
    265     model.setNumberPenalties(8);
    266    
    267     model.setDblParam(CbcModel::CbcMaximumSeconds, s.getDoubleParameter(BabSetupBase::MaxTime));
    268    
    269     model.setMaximumNodes(s.getIntParameter(BabSetupBase::MaxNodes));
    270    
    271     model.setMaximumSolutions(s.getIntParameter(BabSetupBase::MaxSolutions));
    272    
    273     model.setIntegerTolerance(s.getDoubleParameter(BabSetupBase::IntTol));
     258      model_.setNodeComparison(compare);
     259    }
     260   
     261    model_.setNumberStrong(s.getIntParameter(BabSetupBase::NumberStrong));
     262   
     263    model_.setNumberBeforeTrust(s.getIntParameter(BabSetupBase::MinReliability));
     264   
     265    model_.setNumberPenalties(8);
     266   
     267    model_.setDblParam(CbcModel::CbcMaximumSeconds, s.getDoubleParameter(BabSetupBase::MaxTime));
     268   
     269    model_.setMaximumNodes(s.getIntParameter(BabSetupBase::MaxNodes));
     270   
     271    model_.setMaximumSolutions(s.getIntParameter(BabSetupBase::MaxSolutions));
     272   
     273    model_.setIntegerTolerance(s.getDoubleParameter(BabSetupBase::IntTol));
    274274   
    275275   
     
    277277    CbcBranchUserDecision branch;
    278278    if(s.branchingMethod() != NULL){
    279       s.branchingMethod()->setSolver(model.solver());
    280       s.branchingMethod()->setNumberStrong(model.numberStrong());
     279      s.branchingMethod()->setSolver(model_.solver());
     280      s.branchingMethod()->setNumberStrong(model_.numberStrong());
    281281      OsiChooseStrong * strong = dynamic_cast<OsiChooseStrong *>(s.branchingMethod());
    282282      if(strong)
    283         strong->setNumberBeforeTrusted(model.numberBeforeTrust());
     283        strong->setNumberBeforeTrusted(model_.numberBeforeTrust());
    284284      branch.setChooseMethod(*s.branchingMethod());
    285285    }
    286286   
    287287   
    288     model.setBranchingMethod(&branch);
     288    model_.setBranchingMethod(&branch);
    289289   
    290290    //Get the time and start.
    291     model.initialSolve();
    292    
    293     continuousRelaxation_ =model.solver()->getObjValue();
     291    model_.initialSolve();
     292   
     293    continuousRelaxation_ =model_.solver()->getObjValue();
    294294    if(specOpt==16)//Set warm start point for Ipopt
    295295    {
    296       const double * colsol = model.solver()->getColSolution();
    297       const double * duals = model.solver()->getRowPrice();
    298       model.solver()->setColSolution(colsol);
    299       model.solver()->setRowPrice(duals);
     296      const double * colsol = model_.solver()->getColSolution();
     297      const double * duals = model_.solver()->getRowPrice();
     298      model_.solver()->setColSolution(colsol);
     299      model_.solver()->setRowPrice(duals);
    300300    }
    301301   
     
    306306#endif
    307307   
    308     currentBranchModel = &model;
    309     model.branchAndBound();
    310    
    311     model_ = NULL;
    312    
    313     numNodes_ = model.getNodeCount();
    314     bestObj_ = model.getObjValue();
    315     bestBound_ = model.getBestPossibleObjValue();
    316     mipIterationCount_ = model.getIterationCount();
     308    currentBranchModel = &model_;
     309    model_.branchAndBound();
     310   
     311   
     312    numNodes_ = model_.getNodeCount();
     313    bestObj_ = model_.getObjValue();
     314    bestBound_ = model_.getBestPossibleObjValue();
     315    mipIterationCount_ = model_.getIterationCount();
    317316   
    318317    bool hasFailed = false;
    319318    if(specOpt==16)//Did we continue branching on a failure
    320319    {
    321       CbcNlpStrategy * nlpStrategy = dynamic_cast<CbcNlpStrategy *>(model.strategy());
     320      CbcNlpStrategy * nlpStrategy = dynamic_cast<CbcNlpStrategy *>(model_.strategy());
    322321      if (nlpStrategy)
    323322        hasFailed = nlpStrategy->hasFailed();
     
    340339    TMINLP::SolverReturn status;
    341340   
    342     if(model.numberObjects()==0){
     341    if(model_.numberObjects()==0){
    343342      if(bestSolution_)
    344343        delete [] bestSolution_;
     
    349348    }
    350349   
    351     if (model.bestSolution()) {
     350    if (model_.bestSolution()) {
    352351      if (bestSolution_)
    353352        delete [] bestSolution_;
    354353      bestSolution_ = new double[s.nonlinearSolver()->getNumCols()];
    355       CoinCopyN(model.bestSolution(), s.nonlinearSolver()->getNumCols(), bestSolution_);
    356     }
    357     if (model.status() == 0) {
     354      CoinCopyN(model_.bestSolution(), s.nonlinearSolver()->getNumCols(), bestSolution_);
     355    }
     356    if (model_.status() == 0) {
    358357      if (bestSolution_){
    359358        status = TMINLP::SUCCESS;
     
    365364      }
    366365    }
    367     else if(model.status() == 1){
     366    else if(model_.status() == 1){
    368367      status = TMINLP::LIMIT_EXCEEDED;
    369368      if (bestSolution_){
     
    374373      }
    375374    }
    376     else if(model.status()==2){
     375    else if(model_.status()==2){
    377376      status = TMINLP::MINLP_ERROR;
    378377    }
  • trunk/Bonmin/src/CbcBonmin/BonCbc2.hpp

    r481 r500  
    1212
    1313#include "BonBabSetupBase.hpp"
     14#include "CbcModel.hpp"
    1415
    1516namespace Bonmin{
     
    7172  virtual void replaceIntegers(OsiObject ** objects, int numberObjects)
    7273  {};
    73   /** Get pointer to current model. */
    74   CbcModel * model(){
     74  /** Get cbc model used to solve. */
     75  const CbcModel&  model() const{
    7576    return model_;
    7677  }
     78
     79  /** Get cbc model used to solve. */
     80  const CbcModel&  model(){
     81    return model_;
     82  }
     83 
    7784protected:
    7885    /** Stores the solution of MIP. */
     
    9097  /** get total number of iterations in last mip solved.*/
    9198  int mipIterationCount_;
    92   /** Pointer to model currently solved.*/
    93   CbcModel * model_;
     99  /** CbcModel used to solve problem.*/
     100  CbcModel model_;
    94101};
    95102}
  • trunk/configure

    r466 r500  
    2050420504            -e 's/$AR t/lib -nologo -list/' \
    2050520505            -e 's%f_ex_an_ar_oldlib="\($?*1*\)"%f_ex_an_ar_oldlib='\`"$CYGPATH_W"' \1`%' \
    20506             -e 's%^archive_cmds=.*%archive_cmds="\\$CC -o \\$lib \\$libobjs \\$compiler_flags \\\\\\`echo \\\\\\"\\$deplibs\\\\\\" | \\$SED -e '"\'"'s/ -lc\\$//'"\'"'\\\\\\` -link -dll~linknames="%' \\
     20506            -e 's%^archive_cmds=.*%archive_cmds="\\$CC -o \\$lib \\$libobjs \\$compiler_flags \\\\\\`echo \\\\\\"\\$deplibs\\\\\\" | \\$SED -e '"\'"'s/ -lc\\$//'"\'"'\\\\\\` -link -dll~linknames="%' \
    2050720507            -e 's%old_archive_cmds="lib -OUT:\\$oldlib\\$oldobjs\\$old_deplibs"%old_archive_cmds="if test -r \\$oldlib; then bla=\\"\\$oldlib\\"; else bla=; fi; lib -OUT:\\$oldlib \\\\\\$bla\\$oldobjs\\$old_deplibs"%' \
    2050820508        libtool > conftest.bla
Note: See TracChangeset for help on using the changeset viewer.