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

Last change on this file since 1574 was 1574, checked in by lou, 8 years ago

Change to EPL license notice.

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