Ignore:
Timestamp:
Sep 3, 2018 9:09:44 AM (2 years ago)
Author:
forrest
Message:

coding for getting postprocessed model

File:
1 edited

Legend:

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

    r2380 r2382  
    56105610        testSolution_(NULL),
    56115611        globalConflictCuts_(NULL),
    5612         minimumDrop_(1.0e-4),
     5612        minimumDrop_(1.0e-7),
    56135613        numberSolutions_(0),
    56145614        numberSavedSolutions_(0),
     
    56335633        maximumDepth_(0),
    56345634        walkback_(NULL),
     5635        preProcess_(NULL),
    56355636        lastNodeInfo_(NULL),
    56365637        lastCut_(NULL),
     
    57845785        sumChangeObjective2_(0.0),
    57855786        globalConflictCuts_(NULL),
    5786         minimumDrop_(1.0e-4),
     5787        minimumDrop_(1.0e-7),
    57875788        numberSolutions_(0),
    57885789        numberSavedSolutions_(0),
     
    58065807        maximumDepth_(0),
    58075808        walkback_(NULL),
     5809        preProcess_(NULL),
    58085810        lastNodeInfo_(NULL),
    58095811        lastCut_(NULL),
     
    61176119        status_(rhs.status_),
    61186120        secondaryStatus_(rhs.secondaryStatus_),
     6121        preProcess_(rhs.preProcess_),
    61196122        specialOptions_(rhs.specialOptions_),
    61206123        moreSpecialOptions_(rhs.moreSpecialOptions_),
     
    65176520        numberExtraIterations_ = rhs.numberExtraIterations_;
    65186521        numberExtraNodes_ = rhs.numberExtraNodes_;
     6522        preProcess_ = rhs.preProcess_;
    65196523        numberFathoms_ = rhs.numberFathoms_;
    65206524        continuousObjective_ = rhs.continuousObjective_;
     
    1879618800    solver_ = process->originalModel();
    1879718801}
     18802
    1879818803/* Process root node and return a strengthened model
    1879918804
     
    1980619811  return cleanVariables;
    1980719812}
    19808 
    19809 
     19813/* Returns postProcessed solution in solver(called from event handler)
     19814   Normally used for integer solution (not really tested otherwise)
     19815   solutionType 1 is best integer so far, 0 is current solution
     19816   (may not be integer) */
     19817const OsiSolverInterface *
     19818CbcModel::postProcessedSolver(int solutionType)
     19819{
     19820  CbcModel * model = this;
     19821  CglPreProcess * processPointer = model->preProcess();
     19822  OsiSolverInterface * originalModel = NULL;
     19823  const double * solution = bestSolution();
     19824  while (processPointer) {
     19825    int numberSolvers = processPointer->numberSolvers();
     19826    OsiSolverInterface * solver =
     19827      processPointer->presolve(numberSolvers-1)->presolvedModel();
     19828    if (solutionType) {
     19829      // massage solution
     19830      int numberColumns = solver->getNumCols();
     19831      double * saveLower = CoinCopyOfArray(model->solver()->getColLower(),numberColumns);
     19832      double * saveUpper = CoinCopyOfArray(model->solver()->getColUpper(),numberColumns);
     19833      const double * saveSolution = testSolution_;
     19834      setTestSolution(solution);
     19835      model->solver()->setColLower(solution);
     19836      model->solver()->setColUpper(solution);
     19837      OsiBranchingInformation usefulInfo = model->usefulInformation();
     19838      /*
     19839        Run through the objects and use feasibleRegion() to set variable bounds
     19840        so as to fix the variables specified in the objects at their value in this
     19841        solution. Since the object list contains (at least) one object for every
     19842        integer variable, this has the effect of fixing all integer variables.
     19843      */
     19844      for (int i = 0; i < model->numberObjects(); i++)
     19845        model->object(i)->feasibleRegion(solver, &usefulInfo);
     19846      setTestSolution(saveSolution);
     19847      model->solver()->setColLower(saveLower);
     19848      model->solver()->setColUpper(saveUpper);
     19849      delete [] saveLower;
     19850      delete [] saveUpper;
     19851    }
     19852    solver->resolve();
     19853    processPointer->postProcess(*solver,false);
     19854    originalModel = processPointer->originalModel();
     19855    solution = originalModel->getColSolution();
     19856    processPointer=NULL;
     19857    model = model->parentModel();
     19858    processPointer = model ? model->preProcess() : NULL;
     19859  }
     19860  return originalModel;
     19861}
Note: See TracChangeset for help on using the changeset viewer.