source: trunk/Cbc/examples/driver2.cpp

Last change on this file was 2469, checked in by unxusr, 3 months ago

formatting

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