Changeset 834 for trunk


Ignore:
Timestamp:
Nov 2, 2007 10:07:17 AM (12 years ago)
Author:
forrest
Message:

show how to grab solution

Location:
trunk/Cbc/examples
Files:
2 edited

Legend:

Unmodified
Added
Removed
  • trunk/Cbc/examples/Makefile.in

    r706 r834  
    6161
    6262# Libraries necessary to link with Clp
    63 LIBS = -L$(COINLIBDIR) -lCbc -lCgl -lOsiClp -lOsiCbc -lOsi -lClp -lCoinUtils \
     63LIBS = -L$(COINLIBDIR) -lCbcSolver -lCbc -lCgl -lOsiClp -lOsiCbc -lOsi -lClp -lCoinUtils \
    6464        @ADDLIBS@ \
    6565        `cat $(COINLIBDIR)/cgl_addlibs.txt` \
  • trunk/Cbc/examples/driver4.cpp

    r741 r834  
    1313#include "OsiClpSolverInterface.hpp"
    1414#include "CbcCompareUser.hpp"
     15#include "CbcSolver.hpp"
    1516
    1617#include  "CoinTime.hpp"
     
    173174  // If in sub tree carry on
    174175  if (!model_->parentModel()) {
    175     if (whichEvent==solution||whichEvent==heuristicSolution)
     176    if (whichEvent==solution||whichEvent==heuristicSolution) {
     177#ifdef STOP_EARLY
    176178      return stop; // say finished
    177     else
     179#else
     180      // If preprocessing was done solution will be to processed model
     181      int numberColumns = model_->getNumCols();
     182      const double * bestSolution = model_->bestSolution();
     183      assert (bestSolution);
     184      printf("value of solution is %g\n",model_->getObjValue());
     185      for (int i=0;i<numberColumns;i++) {
     186        if (fabs(bestSolution[i])>1.0e-8)
     187          printf("%d %g\n",i,bestSolution[i]);
     188      }
    178189      return noAction; // carry on
     190#endif
     191    } else {
     192      return noAction; // carry on
     193    }
    179194  } else {
    180195      return noAction; // carry on
     
    200215  solver1.getModelPtr()->setMoreSpecialOptions(3);
    201216
     217  /* Two ways of doing this depending on whether NEW_STYLE_SOLVER defined.
     218     So we need pointer to model.  Old way could use modelA. rather than model->
     219   */
     220#ifndef NEW_STYLE_SOLVER
    202221  // Pass to Cbc initialize defaults
    203   CbcModel model(solver1);   
    204   CbcMain0(model);
     222  CbcModel modelA(solver1);
     223  CbcModel * model = &modelA;
     224  CbcMain0(modelA);
    205225  // Event handler
    206226  MyEventHandler3 eventHandler;
    207   model.passInEventHandler(&eventHandler);
     227  model->passInEventHandler(&eventHandler);
    208228  /* Now go into code for standalone solver
    209229     Could copy arguments and add -quit at end to be safe
     
    211231  */
    212232  if (argc>2) {
    213     CbcMain1(argc-1,argv+1,model,callBack);
     233    CbcMain1(argc-1,argv+1,modelA,callBack);
    214234  } else {
    215235    const char * argv2[]={"driver3","-solve","-quit"};
    216     CbcMain1(3,argv2,model,callBack);
    217   }
    218 
     236    CbcMain1(3,argv2,modelA,callBack);
     237  }
     238#else
     239  CbcSolver control(solver1);
     240  // initialize
     241  control.fillValuesInSolver();
     242  // Event handler
     243  MyEventHandler3 eventHandler;
     244  CbcModel * model = control.model();
     245  model->passInEventHandler(&eventHandler);
     246  control.solve (argc-1, argv+1, 1);
     247#endif
    219248  // Solver was cloned so get current copy
    220   OsiSolverInterface * solver = model.solver();
    221   // Print solution if finished (could get from model.bestSolution() as well
    222 
    223   if (model.bestSolution()) {
     249  OsiSolverInterface * solver = model->solver();
     250  // Print solution if finished (could get from model->bestSolution() as well
     251
     252  if (model->bestSolution()) {
    224253   
    225254    const double * solution = solver->getColSolution();
Note: See TracChangeset for help on using the changeset viewer.