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

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

do not require CbcConfig?.h in example to decide whether sample or miplib3 is present - do this in makefile

  • 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 "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;
39#if defined(SAMPLEDIR)
40  mpsFileName = SAMPLEDIR "/p0033.mps";
41#else
42  if (argc < 2) {
43    fprintf(stderr, "Do not know where to find sample MPS files.\n");
44    exit(1);
45  }
46#endif
47  if (argc>=2) mpsFileName = argv[1];
48  int numMpsReadErrors = solver1.readMps(mpsFileName.c_str(),"");
49  assert(numMpsReadErrors==0);
50  double time1 = CoinCpuTime();
51  // Do complete search
52 
53  solver1.branchAndBound();
54
55  std::cout<<mpsFileName<<" took "<<CoinCpuTime()-time1<<" seconds, "
56           <<solver1.getNodeCount()<<" nodes with objective "
57           <<solver1.getObjValue()
58           <<(!solver1.status() ? " Finished" : " Not finished")
59           <<std::endl;
60
61  // Print solution if finished - we can't get names from Osi!
62
63  if (solver1.getObjValue()*solver1.getObjSense()<1.0e50) {
64    int numberColumns = solver1.getNumCols();
65   
66    const double * solution = solver1.getColSolution();
67   
68    int iColumn;
69    std::cout<<std::setiosflags(std::ios::fixed|std::ios::showpoint)<<std::setw(14);
70   
71    std::cout<<"--------------------------------------"<<std::endl;
72    for (iColumn=0;iColumn<numberColumns;iColumn++) {
73      double value=solution[iColumn];
74      if (fabs(value)>1.0e-7&&solver1.isInteger(iColumn)) 
75        std::cout<<std::setw(6)<<iColumn<<" "<<value<<std::endl;
76    }
77    std::cout<<"--------------------------------------"<<std::endl;
78 
79    std::cout<<std::resetiosflags(std::ios::fixed|std::ios::showpoint|std::ios::scientific);
80  }
81  return 0;
82}   
Note: See TracBrowser for help on using the repository browser.