-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathCoinMP.h
105 lines (82 loc) · 2.66 KB
/
CoinMP.h
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
/*
* File: CoinMP.h
* Author: raffa
*
* Created on March 8, 2015, 6:53 PM
*/
#ifndef COINMP_H
#define COINMP_H
#include <string>
#include "coin/CoinMP.h"
#include <vector>
#include <Eigen/SparseCore>
#include <functional>
#include <iostream>
using std::string;
using std::vector;
using Eigen::SparseMatrix;
using std::function;
using std::cout;
class CoinMP
{
public:
typedef function<void(string)> writeDelegate;
CoinMP(writeDelegate write = nullptr);
CoinMP(const CoinMP& orig) = delete;
virtual ~CoinMP();
inline string getSolverName() const { return CoinGetSolverName(); };
inline double getVersion() const { return CoinGetVersion(); };
inline string getVersionString() const { return CoinGetVersionStr(); };
void writeSolution();
void writeProblem();
virtual void writeOutput();
void reset();
virtual bool solve(const string& filename) = 0;
protected:
writeDelegate _write;
enum class eSolveMethod : int {
Default = SOLV_METHOD_DEFAULT,
Barrier = SOLV_METHOD_BARRIER,
Benders = SOLV_METHOD_BENDERS,
Deq = SOLV_METHOD_DEQ,
Dual = SOLV_METHOD_DUAL,
Ev = SOLV_METHOD_EV,
Network = SOLV_METHOD_NETWORK,
Primal = SOLV_METHOD_PRIMAL
};
SparseMatrix<double> _matrix;
bool createProblem(const string& problemName);
void destroyProblem();
bool loadProblem();
bool unloadProblem();
bool solveProblem(const eSolveMethod method = eSolveMethod::Default);
inline void setObjectSense(bool max) { ((max)? _objSense = SOLV_OBJSENS_MAX : _objSense = SOLV_OBJSENS_MIN); }
double _objConst = 0.0;
vector<double> _objCoeff;
vector<double> _lb;
vector<double> _ub;
vector<double> _rhsValue;
vector<char> _rowType;
vector<string> _colNames;
vector<string> _rowNames;
vector<char> _colTypes;
vector<double> _initValues;
vector<double> _rangeValues;
virtual bool loadFile(const string& filename) = 0;
virtual bool setUpProblem() = 0;
string _filename = "";
private:
HPROB _hprob = nullptr;
const char* _objName = "obj";
int _objSense = SOLV_OBJSENS_MIN;
int _rangeCount = 0;
bool loaded = false;
bool loadMatrix();
bool loadNames();
bool loadColumnType();
inline static void print(const string str) { _print(str.c_str(), nullptr); };
inline static int _print(const char* str, void* p) { cout << str; };
//COIN_MSGLOG_CB _writeMsg;
inline int _printMsg(const char*str, void* p) { _write(str); }
};
#endif /* COINMP_H */