source: trunk/Cbc/examples/driver2.cpp @ 1464

Last change on this file since 1464 was 1464, checked in by stefan, 9 years ago

merge split branch into trunk; fix some examples

  • Property svn:eol-style set to native
  • Property svn:keywords set to Author Date Id Revision
File size: 2.5 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 "CbcConfig.h"
15#include "OsiCbcSolverInterface.hpp"
16
17#include  "CoinTime.hpp"
18
19//#############################################################################
20
21
22/************************************************************************
23
24This main program reads in an integer model from an mps file.
25It then uses default strategy - just cuts at root node
26
27************************************************************************/
28
29int main (int argc, const char *argv[])
30{
31
32  // This would just do cuts at root
33  // OsiCbcSolverInterface solver1;
34  // This does cuts in tree and uses Clp
35  CbcStrategyDefault strategy(false);
36  OsiCbcSolverInterface solver1(NULL,&strategy);
37  // Read in model using argv[1]
38  // and assert that it is a clean model
39  std::string mpsFileName;
40#if defined(COIN_HAS_SAMPLE) && defined(SAMPLEDIR)
41  mpsFileName = SAMPLEDIR "/p0033.mps";
42#else
43  if (argc < 2) {
44    fprintf(stderr, "Do not know where to find sample MPS files.\n");
45    exit(1);
46  }
47#endif
48  if (argc>=2) mpsFileName = argv[1];
49  int numMpsReadErrors = solver1.readMps(mpsFileName.c_str(),"");
50  assert(numMpsReadErrors==0);
51  double time1 = CoinCpuTime();
52  // Do complete search
53 
54  solver1.branchAndBound();
55
56  std::cout<<mpsFileName<<" took "<<CoinCpuTime()-time1<<" seconds, "
57           <<solver1.getNodeCount()<<" nodes with objective "
58           <<solver1.getObjValue()
59           <<(!solver1.status() ? " Finished" : " Not finished")
60           <<std::endl;
61
62  // Print solution if finished - we can't get names from Osi!
63
64  if (solver1.getObjValue()*solver1.getObjSense()<1.0e50) {
65    int numberColumns = solver1.getNumCols();
66   
67    const double * solution = solver1.getColSolution();
68   
69    int iColumn;
70    std::cout<<std::setiosflags(std::ios::fixed|std::ios::showpoint)<<std::setw(14);
71   
72    std::cout<<"--------------------------------------"<<std::endl;
73    for (iColumn=0;iColumn<numberColumns;iColumn++) {
74      double value=solution[iColumn];
75      if (fabs(value)>1.0e-7&&solver1.isInteger(iColumn)) 
76        std::cout<<std::setw(6)<<iColumn<<" "<<value<<std::endl;
77    }
78    std::cout<<"--------------------------------------"<<std::endl;
79 
80    std::cout<<std::resetiosflags(std::ios::fixed|std::ios::showpoint|std::ios::scientific);
81  }
82  return 0;
83}   
Note: See TracBrowser for help on using the repository browser.