-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathutils.cpp
157 lines (127 loc) · 2.78 KB
/
utils.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
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
#include "utils.h"
#include <algorithm>
#include "modelePartiel.h"
#include "ModelePartielOnOff.h"
int utils::process(char** argv, int argc)
{
IloEnv env;
env.setDeleter(IloSafeDeleterMode);
try
{
if (argc < 5)
{
usage(std::cerr, argv[0]);
return EXIT_FAILURE;
}
const char* datfile(argv[1]);
IloInt sigma(atoi(argv[2]));
IloInt delta(atoi(argv[3]));
SETUP stype(parseArg(argv[4]));
ModelePartiel::relaxAndFix(env, datfile, sigma, delta, stype);
//ModelePartielOnOff::relaxAndFix(env, datfile,sigma, delta,stype);
}
catch (const IloException& e)
{
std::cout << e << std::endl;
}
}
SETUP utils::parseArg(const char* setup)
{
if (strcmp(setup, "MIN") == 0)
{
std::cout << "MIN" << std::endl;
return SETUP::MIN;
}
else
{
if (strcmp(setup, "MED") == 0)
{
std::cout << "MED" << std::endl;
return SETUP::MED;
}
else
{
if (strcmp(setup, "MAX") == 0)
{
std::cout << "MAX" << std::endl;
return SETUP::MAX;
}
else
{
return SETUP::INVALID;
}
}
}
}
void utils::usage(std::ostream & os, const char* progname)
{
os << progname << " <datfile> <sigma> <delta> <setup> " << std::endl;
os << "<datfile>:" << "string | .dat filename" << std::endl;
os << "<sigma>:" << "int | observation window length " << std::endl;
os << "<delta>:" << "int | number of overlapping periods between two steps" << std::endl;
os << "<setup>:"<< "string : MIN,MED,MAX | setup approximation strategy" << std::endl;
}
std::vector<IloInt> utils::getSetups(const IloInt& j, const std::vector<IloInt>& orders, IloIntMap& s)
{
std::vector<IloInt> setups;
for (IloInt i : orders)
{
if (i != j)
{
setups.push_back(s.getSub(i).get(j));
}
}
return setups;
}
IloInt utils::getMinSetup(const std::vector<IloInt>& setups)
{
return *std::min_element(setups.cbegin(), setups.cend());
}
IloInt utils::getMedSetup(const std::vector<IloInt>& setups)
{
std::vector<IloInt> setups_sorted(setups);
std::sort(setups_sorted.begin(), setups_sorted.end());
size_t nb(setups.size());
if (nb % 2 == 0)
{
IloNum res((setups_sorted.at(nb / 2) + setups_sorted.at((nb+1) / 2))/2 );
return IloRound(res);
}
else
{
IloInt res(setups_sorted.at(nb / 2));
return res;
}
}
IloInt utils::getMaxSetup(const std::vector<IloInt>& setups)
{
return *std::max_element(setups.cbegin(), setups.cend());
}
IloInt utils::computeSetup(SETUP stype, const IloInt& j, const std::vector<IloInt>& orders, IloIntMap& s)
{
IloInt setup(0);
std::vector<IloInt> setups(getSetups(j, orders, s));
switch (stype)
{
case SETUP::MIN:
{
setup = getMinSetup(setups);
break;
}
case SETUP::MED:
{
setup = getMedSetup(setups);
break;
}
case SETUP::MAX:
{
setup = getMaxSetup(setups);
break;
}
case SETUP::INVALID:
{
break;
}
}
return setup;
}