-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathGraphController.h
More file actions
76 lines (53 loc) · 1.96 KB
/
GraphController.h
File metadata and controls
76 lines (53 loc) · 1.96 KB
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
#include <stdio.h>
#include <stdlib.h>
#include <iostream>
#include <vector>
#include <memory>
#include "WeightedLink.h"
#include "Graph.h"
#include "Ballot.h"
#ifndef GRAPHCONTROLLER_H
#define GRAPHCONTROLLER_H
class GraphController {
public:
std::shared_ptr<Graph> graph;
size_t graphSize;
GraphController(int graphSize) {
this->graphSize = graphSize;
graph = std::make_shared<Graph>(graphSize);
}
void AddToAdjMatrix(int firstNode, int secondNode, int count) {
// once preferances are counted between firstNode and secondNode,
// add to adjMatrix
if(!graph->AddLink(firstNode, secondNode, count)) {
std::cout << "Error: unable to add edge to graph" << std::endl;
}
}
void CalculateStrongestPaths() {
for(int i = 0; i < graphSize; ++i) {
for(int j = 0; j < graphSize; ++j) {
if(i != j) {
if(graph->adjMatrix.at(i).at(j) > graph->adjMatrix.at(j).at(i)) {
graph->strongPaths.at(i).at(j) = graph->adjMatrix.at(i).at(j);
}
else {
graph->strongPaths.at(i).at(j) = 0;
}
}
}
}
for(int i = 0; i < graphSize; ++i) {
for(int j = 0; j < graphSize; ++j) {
if(i != j) {
for(int k = 0; k < graphSize; ++k) {
if(i != k && j != k) {
graph->strongPaths.at(j).at(k) = std::max(graph->strongPaths.at(j).at(k),
std::min(graph->strongPaths.at(j).at(i), graph->strongPaths.at(i).at(k)));
}
}
}
}
}
}
};
#endif // GRAPHCONTROLLER_H