source: branches/devel/Cbc/examples/driver2.cpp @ 467

Last change on this file since 467 was 333, checked in by andreasw, 13 years ago

finished examples subdir

  • Property svn:eol-style set to native
  • Property svn:keywords set to Author Date Id Revision
File size: 2.3 KB
Line 
1// Copyright (C) 2005, International Business Machines
2// Corporation and others.  All Rights Reserved.
3#if defined(_MSC_VER)
4// Turn off compiler warning about long names
5#  pragma warning(disable:4786)
6#endif
7
8#include <cassert>
9#include <iomanip>
10
11
12// For Branch and bound
13//#include "CbcStrategy.hpp"
14#include "OsiCbcSolverInterface.hpp"
15
16#include  "CoinTime.hpp"
17
18//#############################################################################
19
20
21/************************************************************************
22
23This main program reads in an integer model from an mps file.
24It then uses default strategy - just cuts at root node
25
26************************************************************************/
27
28int main (int argc, const char *argv[])
29{
30
31  // This would just do cuts at root
32  // OsiCbcSolverInterface solver1;
33  // This does cuts in tree and uses Clp
34  CbcStrategyDefault strategy(false);
35  OsiCbcSolverInterface solver1(NULL,&strategy);
36  // Read in model using argv[1]
37  // and assert that it is a clean model
38  std::string mpsFileName = "../../Data/Sample/p0033.mps";
39  if (argc>=2) mpsFileName = argv[1];
40  int numMpsReadErrors = solver1.readMps(mpsFileName.c_str(),"");
41  assert(numMpsReadErrors==0);
42  double time1 = CoinCpuTime();
43  // Do complete search
44 
45  solver1.branchAndBound();
46
47  std::cout<<mpsFileName<<" took "<<CoinCpuTime()-time1<<" seconds, "
48           <<solver1.getNodeCount()<<" nodes with objective "
49           <<solver1.getObjValue()
50           <<(!solver1.status() ? " Finished" : " Not finished")
51           <<std::endl;
52
53  // Print solution if finished - we can't get names from Osi!
54
55  if (solver1.getObjValue()*solver1.getObjSense()<1.0e50) {
56    int numberColumns = solver1.getNumCols();
57   
58    const double * solution = solver1.getColSolution();
59   
60    int iColumn;
61    std::cout<<std::setiosflags(std::ios::fixed|std::ios::showpoint)<<std::setw(14);
62   
63    std::cout<<"--------------------------------------"<<std::endl;
64    for (iColumn=0;iColumn<numberColumns;iColumn++) {
65      double value=solution[iColumn];
66      if (fabs(value)>1.0e-7&&solver1.isInteger(iColumn)) 
67        std::cout<<std::setw(6)<<iColumn<<" "<<value<<std::endl;
68    }
69    std::cout<<"--------------------------------------"<<std::endl;
70 
71    std::cout<<std::resetiosflags(std::ios::fixed|std::ios::showpoint|std::ios::scientific);
72  }
73  return 0;
74}   
Note: See TracBrowser for help on using the repository browser.