source: branches/devel/Cbc/examples/multiRun.cpp @ 586

Last change on this file since 586 was 586, checked in by forrest, 13 years ago

example on calling cbc main program

File size: 2.3 KB
Line 
1// Copyright (C) 2007, 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#include "CbcModel.hpp"
12#include "OsiClpSolverInterface.hpp"
13
14#include  "CoinTime.hpp"
15
16//#############################################################################
17
18
19/************************************************************************
20
21This main program reads in an integer model from an mps file.
22It then tries four variants of brach and bound - this is to find leaks in callCbc
23
24************************************************************************/
25
26int main (int argc, const char *argv[])
27{
28
29  OsiClpSolverInterface solver1;
30
31  // Read in model using argv[1]
32  // and assert that it is a clean model
33  std::string mpsFileName = "../../Data/Sample/p0033.mps";
34  if (argc>=2) mpsFileName = argv[1];
35  int numMpsReadErrors = solver1.readMps(mpsFileName.c_str(),"");
36  assert(numMpsReadErrors==0);
37  double time1 = CoinCpuTime();
38
39  std::string test[4]= {
40    "-solve",
41    "-rins on -solve",
42    "-preprocess off -solve",
43    "-probing on -solve"};
44  // do 8 runs
45  for (int i=0;i<8;i++) {
46    OsiClpSolverInterface solver2 = solver1;
47    int type = i/4;
48    int j=i-4*type;
49    if (type==0) {
50      callCbc(test[j].c_str(),solver2);
51      printf ("Doing char * %s - took %g seconds\n",test[j].c_str(),CoinCpuTime()-time1);
52    } else {
53      callCbc(test[j],solver2);
54      printf ("Doing string %s - took %g seconds\n",test[j].c_str(),CoinCpuTime()-time1);
55    }
56    int numberColumns = solver2.getNumCols();
57   
58    const double * solution = solver2.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&&solver2.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    time1 = CoinCpuTime();
73  }
74  return 0;
75}   
Note: See TracBrowser for help on using the repository browser.