-
Notifications
You must be signed in to change notification settings - Fork 0
/
MHESonCore.h
280 lines (244 loc) · 10.1 KB
/
MHESonCore.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
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
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
/*
* File: MHESonCore.h
* Author: RM
*
* Created on 18. August 2013, 00:33
*
* Administrates procedure and stores globally needed variables.
* Replaces main() as central hub for governing the program / algorithm.
*
*/
#ifndef MHESONCORE_H
#define MHESONCORE_H
#include <cstdlib>
#include <chrono>
#include <ctime>
#include <windows.h>
#include "Definitions.h"
#include "FileMetadata.h"
#include "InputManagement.h"
#include "Graph.h"
#include "AugmentedNeighbourhoodCDHS_GMH.h"
#include "CDHS_GMH.h"
#include "Chaos_GMH.h"
#include "Degrees_GMH.h"
namespace MHESonCoreMetadata
{
enum Phases {PARSING = 1, IS_PICKING = 2, MP_CALCULATION = 4, GROUP_MAPPING = 8, ITERATIVE_OFFERING = 16, ALL = 32};
}
class MHESonCore
{
public:
MHESonCore();
MHESonCore(const MHESonCore& orig);
virtual ~MHESonCore();
/**
* PHASE 0: Preparations
* Loads settings and makes arrangements for further steps.
* @param fileSpecification Flag for file to be loaded.
* @param heuristic Flag indicating which heuristic to use.
*/
void init( FileMetadataConstants::FileSpecification fileSpecification,
GMHAlgorithm::GMHeuristic heuristic,
GMHAlgorithm::PriceSettingMechanism offerMechanism
);
/**
* PHASES 1 to 6
* Runs actual algorithm, stops after specified phase.
* @param lastPhaseIndex Stops simulation after passed phase index, if set.
* @return Sum of revenues earned.
*/
float run(const uint lastPhaseIndex = MHESonCoreMetadata::ALL);
/**
* Creates instance of MHESonCore with given arguments, runs it speci-
* fied number of times.
* @param fileSpecification Specifies which file is to be examined.
* @param heuristic Group mapping heuristic to be applied.
* @param offerMechanism Offer mechanism to be used.
* @param numberOfRuns Number of iterations (for statistical purposes).
* @param lastPhaseIndex Stops simulation after passed phase index, if set.
* @return Total time elapsed.
*/
static long long run( FileMetadataConstants::FileSpecification fileSpecification,
GMHAlgorithm::GMHeuristic heuristic,
GMHAlgorithm::PriceSettingMechanism offerMechanism,
const uint numberOfRuns,
const uint lastPhaseIndex = MHESonCoreMetadata::ALL
);
/**
* Examines sum and average of myopic prices in simulation with given
* arguments. Stops run after third phase.
* Varies IS entry probability from 0/0.1 to 1/0.9.
* Determines MP average and sum after finishing phase 3; then selects
* dataset-dependent best IS entry probability values.
* @param fileSpecification
* @param heuristic
* @param offerMechanism
* @param numberOfRuns
* @return Milliseconds needed for calculations.
*/
static long long examineMyopicPrices ( FileMetadataConstants::FileSpecification fileSpecification,
GMHAlgorithm::GMHeuristic heuristic,
GMHAlgorithm::PriceSettingMechanism offerMechanism,
const uint numberOfRuns
);
/**
* Follows same pattern as examineMyopicPrices() / run(): Run all phases
* of simulation a given number of times; write protocol in specified
* location.
* Designed for phase 2 of evaluation.
* @param fileSpecification
* @param heuristic
* @param offerMechanism
* @param numberOfRuns
* @return Milliseconds needed for calculations.
*/
static long long runTestSeries_P2 ( FileMetadataConstants::FileSpecification fileSpecification,
GMHAlgorithm::GMHeuristic heuristic,
GMHAlgorithm::PriceSettingMechanism offerMechanism,
const uint numberOfRuns
);
/**
* Follows same pattern as examineMyopicPrices() / run(): Run all phases
* of simulation a given number of times; write protocol in specified
* location.
* Designed for phase 3 of evaluation.
* @param fileSpecification
* @param heuristic
* @param offerMechanism
* @param numberOfRuns
* @return Concatenated string of all results in this run; fitted for
* usage in spreadsheet.
*
*/
static long long runTestSeries_P3 ( FileMetadataConstants::FileSpecification fileSpecification,
GMHAlgorithm::GMHeuristic heuristic,
GMHAlgorithm::PriceSettingMechanism offerMechanism,
const uint numberOfRuns,
ofstream& resultSummaryFile
);
/**
* Auxiliary function; used for code replacement in main().
* Runs MHESonCore::runTestSeries_P2().
*/
static void evaluatePhase2();
/**
* Auxiliary function; used for code replacement in main().
* Runs MHESonCore::runTestSeries_P3().
*/
static void evaluatePhase3();
/**
* Evaluates distribution of MP sum in groups.
* Auxiliary function; used for code replacement in main().
*/
static void evaluateMPDistribution();
/**
* Preprocesses DBLP data in order to increase efficiency of input parsing.
* Usage example (in main()):
* core.prepareDBLP("../resources/DBLP/text/out.dblp_coauthor", "../resources/DBLP/text/out.dblp_coauthor_inverted_reduced_weighted");
* @param inputPath
* @param outputPath
*/
void prepareDBLP(string inputPath, string outputPath);
/**
* Getter/setter for _graph.
* @return Reference to graph used.
*/
Graph& graph();
/**
* Getter/setter for _sigmaMP.
* @return Sum of calculated MPs of all vertices.
*/
double& sigmaMP();
/**
* Collects metadata about MP distribution in groups (number of members
* and MP sum in each group).
* @return Vector of pairs, containing the number members of each group
* in the first and the MP sum in the second element.
*/
vector<pair<uint, float>> getGroupMPMetadata();
/**
* Auxiliary method - determines file path for protocol files. Used in
* runTestSeries().
* @param fileSpecification
* @param heuristic
* @param offerMechanism
* @return Complete file path.
*/
static string generateLogFilePath( FileMetadataConstants::FileSpecification fileSpecification,
GMHAlgorithm::GMHeuristic heuristic,
GMHAlgorithm::PriceSettingMechanism offerMechanism);
private:
/**
* --- Variables ---
*/
/**
* File metadata (path, name, estimated number of vertices, ...)
*/
FileMetadata _fileMetadata;
/**
* Graph containing all read vertices
*/
Graph _graph;
/**
* Heuristic used to calculate myopic prices and map vertices to groups
*/
GroupMappingHeuristic* _gmHeuristic;
/**
* Contains vertex IDs of vertices chosen as part of influence set.
* Realised as unordered set due to its ability to reserve memory
* in advance.
*/
unordered_set<uint> _influenceSet;
/**
* Contains vertex IDs of vertices which accepted the offer. Declining vertices
* are deleted from original container (graph->vertices()), because no
* network effects appear.
*/
unordered_set<uint> _buyerSet;
/**
* Contains vertex groups
*/
vector<VertexGroup> _vertexGroups;
/**
* Sum of all myopic prices (used for statistical/evaluation purposes).
*/
double _sigmaMP;
/**
* --- Methods ---
*/
/**
* PHASE 1: Parse input file, process vertex data.
* Note: Domain of GMH (and descendants).
* Simple wrapper for InputManagement.parseInputFile().
* @return Status code (-1 for error, 1 for success).
*/
int parseInputFile();
/**
* PHASE 2: Picks influence set.
* Note: Domain of GMH (and descendants).
* @return Number of vertices picked for influence set.
*/
uint pickInfluenceSet();
/**
* PHASE 3: Calculates the myopic prices of all vertices.
* Rearranges vertex collection (sorting, erasing vertices not needed anymore)
* after calculation.
* @return Mean myopic price (averaged over all vertices - exempt IS).
*/
float calculateMyopicPrices();
/**
* PHASE 4: Map vertices to groups (depends on implementation of GM heuristic).
* Simple wrapper for GMH::mapGroups().
* @return Number of non-empty groups.
*/
uint mapGroups();
/**
* PHASE 5: Offer product to certain parts (chosen by random) of each
* of the k groups in l rounds.
* @return Revenue made by offering.
* @see ParametrizationSettings
*/
float runIterativeOffering();
} ;
#endif /* MHESONCORE_H */