-
Notifications
You must be signed in to change notification settings - Fork 0
/
Vertex.cpp
221 lines (178 loc) · 5.33 KB
/
Vertex.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
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
/*
* File: Vertex.cpp
* Author: RM
*
* Created on 26. Juli 2013, 22:55
*/
#include "Vertex.h"
unordered_set<uint>* Vertex::_influenceSet;
unordered_set<uint>* Vertex::_buyerSet;
map<uint, uint>* Vertex::_vertexIDMap;
Vertex::Vertex()
{
// Set default values
_upperPriceLimit = -1;
_roundAssignation = -1;
_myopicPrice = ParametrizationSettings::MYOPIC_PRICE_DEFAULT;
_emmetropicPrice = ParametrizationSettings::MYOPIC_PRICE_DEFAULT;
}
Vertex::Vertex(uint vertexID, vector<Edge>& edges) : _vertexID(vertexID)
{
// Swap data with delivered vector / argument
_incomingEdges.swap(edges);
// Set default values
_upperPriceLimit = -1;
_roundAssignation = -1;
_myopicPrice = ParametrizationSettings::MYOPIC_PRICE_DEFAULT;
_emmetropicPrice = ParametrizationSettings::MYOPIC_PRICE_DEFAULT;
}
Vertex::Vertex(const Vertex& orig)
{
_vertexID = orig._vertexID;
_upperPriceLimit = orig._upperPriceLimit;
_roundAssignation = orig._roundAssignation;
_incomingEdges = orig._incomingEdges;
_myopicPrice = orig._myopicPrice;
_emmetropicPrice = orig._emmetropicPrice;
_influenceSet = orig._influenceSet;
_buyerSet = orig._buyerSet;
}
Vertex::~Vertex()
{
}
uint& Vertex::vertexID()
{
return _vertexID;
}
float& Vertex::upperPriceLimit()
{
return _upperPriceLimit;
}
float& Vertex::myopicPrice()
{
return _myopicPrice;
}
float& Vertex::emmetropicPrice()
{
return _emmetropicPrice;
}
vector<Edge>& Vertex::incomingEdges()
{
return _incomingEdges;
}
short& Vertex::roundAssignation()
{
return _roundAssignation;
}
uint Vertex::getVertexID() const
{
return _vertexID;
}
float Vertex::getMyopicPrice() const
{
return _myopicPrice;
}
float Vertex::getEmmetropicPrice() const
{
return _emmetropicPrice;
}
size_t Vertex::getIncomingEdgeCount() const
{
return _incomingEdges.size();
}
ostream& operator<<(ostream& stream, const Vertex& vertex)
{
stream << "<> Vertex with ID = " << vertex._vertexID << endl;
stream << " > Number of edges = " << vertex._incomingEdges.size() << endl;
stream << " > Upper price limit = " << vertex._upperPriceLimit << endl;
stream << " > Myopic price = " << vertex._myopicPrice << endl;
stream << " > Assigned round = " << vertex._roundAssignation << endl;
return stream;
}
void Vertex::swapEdges(vector<Edge>& edges)
{
_incomingEdges.swap(edges);
}
bool Vertex::operator < (const Vertex& vertex) const
{
return _myopicPrice < vertex._myopicPrice;
}
bool Vertex::compareEmmetropicPrices(const Vertex& a, const Vertex& b)
{
return a._emmetropicPrice < b._emmetropicPrice;
}
bool Vertex::compareIncomingEdgeCount(const Vertex& a, const Vertex& b)
{
return a._incomingEdges.size() < b._incomingEdges.size();
}
float Vertex::calculateMyopicPrice()
{
float edgeWeightSum = 0;
// Check if vertex not deaf
if (_incomingEdges.size()) {
// Add weight of edge to sum, if corresponding vertex is IS member.
for (Edge& edge : _incomingEdges) {
if (_influenceSet->count(edge.destinationID())) {
edgeWeightSum += edge.weight();
}
}
// Calculate final myopic price
_myopicPrice = edgeWeightSum / 2;
return _myopicPrice;
}
// If deaf: Assign special (negative) MP value, so vertex can be deleted afterwards
else {
_myopicPrice = ParametrizationSettings::MYOPIC_PRICE_DEAF_NODES;
// Return 0 so average MP won't be distorted
return 0;
}
}
float Vertex::calculateEmmetropicPrice()
{
float additionalEPSum = 0;
// If positive MP (otherwise vertex will be deleted anyway)
if (_incomingEdges.size()) {
// Base emmetropic on myopic price
_emmetropicPrice = _myopicPrice;
// Calculate emmetropic price for each vertex
for (Edge& edge : _incomingEdges) {
// Calculate EP here: P(r_a > r_b) * W_ba * EP_AF + MP_a
additionalEPSum += ParametrizationSettings::ANCDHS_POST_ROUND_PROBABILITY *
edge.getWeight();
}
// Calculate final emmetropic price (and yes, used constant is a magic
// number. Who cares.)
_emmetropicPrice += additionalEPSum * ParametrizationSettings::ANCHDS_EP_ADJUSTMENT_FACTOR;
return _emmetropicPrice;
}
// Else: Return 0 so average EP won't be distorted
else {
_emmetropicPrice = ParametrizationSettings::MYOPIC_PRICE_DEAF_NODES;
return 0;
}
}
float Vertex::calculatePriceLimit()
{
_upperPriceLimit = 0;
for (Edge& edge : _incomingEdges) {
// If neighbour (incoming edge relative to current vertex!)
// is in posession of product: Take positive influence
// in account.
if (_buyerSet->count(edge.destinationID()) || _influenceSet->count(edge.destinationID())) {
_upperPriceLimit += edge.weight();
}
}
return _upperPriceLimit;
}
void Vertex::setIS(unordered_set<uint>& influenceSet)
{
_influenceSet = &influenceSet;
}
void Vertex::setBS(unordered_set<uint>& buyerSet)
{
_buyerSet = &buyerSet;
}
void Vertex::setVertexIDMap(map<uint, uint>& vertexIDMap)
{
_vertexIDMap = &vertexIDMap;
}