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

Last change on this file since 1898 was 1898, checked in by stefan, 5 years ago

fixup examples

  • Property svn:eol-style set to native
  • Property svn:keywords set to Author Date Id Revision
File size: 2.6 KB
Line 
1// $Id: driver2.cpp 1898 2013-04-09 18:06:04Z stefan $
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#include <cassert>
7#include <iomanip>
8
9
10// For Branch and bound
11//#include "CbcStrategy.hpp"
12#include "CoinPragma.hpp"
13#include "OsiCbcSolverInterface.hpp"
14
15#include "CoinTime.hpp"
16
17//#############################################################################
18
19
20/************************************************************************
21
22This main program reads in an integer model from an mps file.
23It then uses default strategy - just cuts at root node
24
25************************************************************************/
26
27int main (int argc, const char *argv[])
28{
29
30  // This would just do cuts at root
31  // OsiCbcSolverInterface solver1;
32  // This does cuts in tree and uses Clp
33  CbcStrategyDefault strategy(false);
34  OsiCbcSolverInterface solver1(NULL,&strategy);
35  // Read in model using argv[1]
36  // and assert that it is a clean model
37  std::string mpsFileName;
38#if defined(SAMPLEDIR)
39  mpsFileName = SAMPLEDIR "/p0033.mps";
40#else
41  if (argc < 2) {
42    fprintf(stderr, "Do not know where to find sample MPS files.\n");
43    exit(1);
44  }
45#endif
46  if (argc>=2) mpsFileName = argv[1];
47  int numMpsReadErrors = solver1.readMps(mpsFileName.c_str(),"");
48  if( numMpsReadErrors != 0 )
49  {
50     printf("%d errors reading MPS file\n", numMpsReadErrors);
51     return numMpsReadErrors;
52  }
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.