forked from coin-or/Cbc
-
Notifications
You must be signed in to change notification settings - Fork 0
/
minimum.cpp
46 lines (39 loc) · 1.37 KB
/
minimum.cpp
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
// Copyright (C) 2005, International Business Machines
// Corporation and others. All Rights Reserved.
// This code is licensed under the terms of the Eclipse Public License (EPL).
#include "CbcModel.hpp"
// Using as solver
#include "OsiClpSolverInterface.hpp"
int main(int argc, const char *argv[])
{
OsiClpSolverInterface solver1;
// Read in example model
// and assert that it is a clean model
#if defined(SAMPLEDIR)
int numMpsReadErrors = solver1.readMps(SAMPLEDIR "/p0033.mps", "");
if (numMpsReadErrors != 0) {
printf("%d errors reading MPS file\n", numMpsReadErrors);
return numMpsReadErrors;
}
#else
fprintf(stderr, "Do not know where to find sample MPS files.\n");
exit(1);
#endif
// Pass data and solver to CbcModel
CbcModel model(solver1);
// uncomment to reduce printout
//model.setLogLevel(1);
//model.solver()->setHintParam(OsiDoReducePrint,true,OsiHintTry);
// Do complete search
model.branchAndBound();
/* Print solution. CbcModel clones solver so we
need to get current copy */
int numberColumns = model.solver()->getNumCols();
const double *solution = model.solver()->getColSolution();
for (int iColumn = 0; iColumn < numberColumns; iColumn++) {
double value = solution[iColumn];
if (fabs(value) > 1.0e-7 && model.solver()->isInteger(iColumn))
printf("%d has value %g\n", iColumn, value);
}
return 0;
}