source: trunk/Cbc/examples/minimum.cpp

Last change on this file was 2469, checked in by unxusr, 2 weeks ago

formatting

  • Property svn:eol-style set to native
  • Property svn:keywords set to Author Date Id Revision
File size: 1.4 KB
Line 
1// $Id: minimum.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 "CbcModel.hpp"
7
8// Using as solver
9#include "OsiClpSolverInterface.hpp"
10
11int main(int argc, const char *argv[])
12{
13  OsiClpSolverInterface solver1;
14  // Read in example model
15  // and assert that it is a clean model
16#if defined(SAMPLEDIR)
17  int numMpsReadErrors = solver1.readMps(SAMPLEDIR "/p0033.mps", "");
18  if (numMpsReadErrors != 0) {
19    printf("%d errors reading MPS file\n", numMpsReadErrors);
20    return numMpsReadErrors;
21  }
22#else
23  fprintf(stderr, "Do not know where to find sample MPS files.\n");
24  exit(1);
25#endif
26
27  // Pass data and solver to CbcModel
28  CbcModel model(solver1);
29
30  // uncomment to reduce printout
31  //model.setLogLevel(1);
32  //model.solver()->setHintParam(OsiDoReducePrint,true,OsiHintTry);
33  // Do complete search
34  model.branchAndBound();
35  /* Print solution.  CbcModel clones solver so we
36     need to get current copy */
37  int numberColumns = model.solver()->getNumCols();
38
39  const double *solution = model.solver()->getColSolution();
40
41  for (int iColumn = 0; iColumn < numberColumns; iColumn++) {
42    double value = solution[iColumn];
43    if (fabs(value) > 1.0e-7 && model.solver()->isInteger(iColumn))
44      printf("%d has value %g\n", iColumn, value);
45  }
46  return 0;
47}
Note: See TracBrowser for help on using the repository browser.