-
Notifications
You must be signed in to change notification settings - Fork 0
/
Graph.h
188 lines (160 loc) · 5.73 KB
/
Graph.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
/*
* File: Graph.h
* Author: RM
*
* Created on 26. Juli 2013, 22:55
*/
#ifndef GRAPH_H
#define GRAPH_H
#include <iostream>
#include <vector>
#include <string>
#include <map>
#include <algorithm>
#include "Definitions.h"
#include "Vertex.h"
#include "Edge.h"
class Graph
{
public:
Graph(string name, bool hasNativeEdgeWeights, bool directed, uint estimatedSize = 0);
Graph(const Graph& orig);
Graph();
virtual ~Graph();
/**
* Adds vertex to internal vertex collection.
* Assumption: Vertices are read in order, so there aren't any duplicates
* used as parameters for addVertex().
* @param vertex
* @deprecated Use vertices() in combination with finalizeInputParsing() instead.
*/
void addVertex(const Vertex& vertex, uint vertexID);
/**
* Finalizes parsing of input file.
* @param roundAssignations Collection containing indices of rounds
* vertices are supposed to enter.
*/
void finalizeInputParsing(const vector<float>& roundAssignations);
/**
*
* @param stream
* @param vertex
* @return
*/
friend ostream& operator<< (ostream& stream, const Graph& graph);
/**
* Returns estimated number of vertices in graph.
* @return
*/
uint& estimatedSize();
/**
* Returns internal vertex collection.
* @return
*/
vector<Vertex>& vertices();
/**
* Returns map representing a vertex ID/index scheme.
* @return
*/
map<uint, uint>& vertexIDMap();
/**
* Returns reference to count of passive/deaf vertices.
* @return Reference to count of passive/deaf vertices.
*/
uint& passiveVertexCount();
/**
* Sorts vertices using the overloaded comparison operator <
* (i. e. sorting by their myopic prices).
*/
void sortVertices();
/**
* Deletes influence set vertices and those without any incoming edges -
* former have already been processed and are available in
* GMH::_influenceSet, latter don't account for any network effects
* and are therefore to dismiss.
* @param isSorted Defines whether or not vertices are sorted by their
* myopic prices (so that not all vertices have to be iterated in order
* to delete inactive ones).
* @return Number of vertices deleted.
*/
uint deleteInactiveVertices(bool sortedByMP);
/**
* Initializes graph settings (same parameters as constructor).
* @param name
* @param hasNativeEdgeWeights
* @param directed
* @param estimatedSize
*/
void init(string name, bool hasNativeEdgeWeights, bool directed, uint estimatedSize = 0);
/**
* Returns original size of graph (i.e. when initialized / after file parsing).
* @return
*/
uint getOriginalSize() const;
/**
* Sorts vertices and deletes deaf or already used ones (i. e.: Members
* of influence set and deaf vertices, as former are stored in a more compact
* form elsewhere and latter don't account for network effects as they
* have a zero percent chance to take up on the offer and influence
* other vertices).
* Used in phase 3.
* @see GroupMappingHeuristics._influenceSet
* @return Number of deleted vertices.
*/
uint restructure(bool sortedByMP);
/**
* Calculates median MP. Necessary if vertices not sorted after MP.
* @return Median MP of vertices in this graph.
*/
float calculateMedianMP();
/**
* Add delivered vector of vertices to vertex collection.
* @param considerNegativeMPs Determines if vertices with negative MPs
* (e. g., deaf-0 and IS vertices) are to be
* @deprecated Not used anymore; mapping takes place on-the-fly in
* InputManagement::parseXFile() instead.
* @return Reference to vertex ID/index map.
*/
const map<uint, uint>& mapVertexCollection(bool considerNegativeMPs = true);
/**
* Clears vertex map.
*/
void clearVertexMap();
private:
/**
* --- Methods ---
*/
/**
* Scans edges of saved vertices for passive vertices (only incoming,
* no outgoing edges. If passive vertices are found, they are added to
* the internal vertex collection.
*/
void scanForPassiveVertices(const vector<float>& roundAssignations);
/**
* Remove-erase idiom for deleting inactive vertices.
* @param vertex
* @return
*/
static bool removeInactiveVertexPred(const Vertex& vertex);
/**
* --- Variables ---
*/
// Actual graph data
vector<Vertex> _vertices;
map<uint, uint> _vertexIDMap;
// Metadata
string _name;
bool _hasNativeEdgeWeights;
bool _isDirected;
uint _estimatedSize;
/**
* Auxiliary variables
*/
uint _vertexCount;
// Stores number of passive/deaf vertices (e. g. vertices not contributing
// to any network effects).
uint _passiveVertexCount;
// Provides information about graph size when initialized.
uint _originalSize;
} ;
#endif /* GRAPH_H */