forked from coin-or/Clp
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathdriver3.cpp
112 lines (98 loc) · 3.33 KB
/
driver3.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
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
// Copyright (C) 2007, International Business Machines
// Corporation and others. All Rights Reserved.
// This code is licensed under the terms of the Eclipse Public License (EPL).
#include <cassert>
#include <iomanip>
#include "CoinPragma.hpp"
#include "ClpSimplex.hpp"
#ifdef ABC_INHERIT
#include "AbcSimplex.hpp"
#endif
#include "CoinTime.hpp"
//#############################################################################
/************************************************************************
This main program shows how to take advantage of the standalone clp in your program.
It should perform very nearly the same as clp
First it reads in a model from an mps file
Then it calls ClpMain1 passing all parameters apart from first
Finally it prints solution
************************************************************************/
#ifndef ABC_INHERIT
void ClpMain0(ClpSimplex * models);
int ClpMain1(int argc, const char *argv[],ClpSimplex * model);
#else
void ClpMain0(AbcSimplex * models);
int ClpMain1(int argc, const char *argv[],AbcSimplex * model);
#endif
/*
Somehow with some BLAS we get multithreaded by default
For 99.99% of problems this is not a good idea.
The openblas_set_num_threads(1) seems to work even with other blas
*/
#if CLP_USE_OPENBLAS
extern "C" {
void openblas_set_num_threads(int num_threads);
}
#endif
int main (int argc, const char *argv[])
{
#if CLP_USE_OPENBLAS
openblas_set_num_threads(CLP_USE_OPENBLAS);
#endif
#ifndef ABC_INHERIT
ClpSimplex model;
#else
AbcSimplex model;
#endif
if (argc > 1) {
printf("command line - ");
for (int i = 0; i < argc; i++)
printf("%s ", argv[i]);
printf("\n");
}
// change defaults to match standalone solver
ClpMain0(&model);
// Read in model using argv[1]
// and assert that it is a clean model
std::string mpsFileName;
#if defined(SAMPLEDIR)
mpsFileName = SAMPLEDIR "/p0033.mps";
#else
if (argc < 2) {
fprintf(stderr, "Do not know where to find sample MPS files.\n");
exit(1);
}
#endif
if (argc>=2) mpsFileName = argv[1];
int numMpsReadErrors = model.readMps(mpsFileName.c_str());
if( numMpsReadErrors != 0 )
{
printf("%d errors reading MPS file\n", numMpsReadErrors);
return numMpsReadErrors;
}
/* Now go into code for standalone solver
Could copy arguments and add -quit at end to be safe
but this will do
*/
if (argc>2) {
ClpMain1(argc-1,argv+1,&model);
} else {
const char * argv2[]={"driver3","-solve","-quit"};
ClpMain1(3,argv2,&model);
}
// Print solution
const double * solution = model.primalColumnSolution();
int numberColumns = model.numberColumns();
//const double * reducedCosts = model.dualColumnSolution();
std::cout<<std::setiosflags(std::ios::fixed|std::ios::showpoint)<<std::setw(14);
std::cout<<"--------------------------------------"<<std::endl;
for (int iColumn=0;iColumn<numberColumns;iColumn++) {
double value=solution[iColumn];
if (fabs(value)>1.0e-7)
std::cout<<std::setw(6)<<iColumn<<" "<<std::setw(8)<<std::setiosflags(std::ios::left)<<model.getColumnName(iColumn)
<<std::resetiosflags(std::ios::adjustfield)<<std::setw(14)<<" "<<value<<std::endl;
}
std::cout<<"--------------------------------------"<<std::endl;
std::cout<<std::resetiosflags(std::ios::fixed|std::ios::showpoint|std::ios::scientific);
return 0;
}