forked from ORNL/GridKit
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathCircuitGraph.hpp
More file actions
122 lines (107 loc) · 2.72 KB
/
CircuitGraph.hpp
File metadata and controls
122 lines (107 loc) · 2.72 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
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
#include <iostream>
#include <cmath>
#include <vector>
#include <unordered_set>
#include <map>
/**
* @brief A very basic hypergraph setup for circuit representation.
* This forms the hypergraph as a bipartite graph. Doesn't allow
* removing. Can only grab sets of connections to nodes
*
* @todo should replace with something better and more efficent.
* Should replace with a libraries setup instead. This would allow
* fast and easy partitioning of circuits
*
* @todo This is to replace inserting vector size for allocating PowerElectronicsModel
*
* @todo should replace N and E with Node and Component classes respectively.
*
* @note Tested but currently not used in the rest of the code.
*
* @tparam IdxT
* @tparam Label
*/
template <typename N, typename E>
class CircuitGraph
{
private:
std::set<N> hypernodes;
std::set<E> hyperedges;
std::map<E, std::set<N>> edgestonodes;
public:
CircuitGraph();
~CircuitGraph();
bool addHyperEdge(E he);
bool addHyperNode(N hn);
bool addConnection(N hn, E he);
std::set<N> getHyperEdgeConnections(E he);
size_t amountHyperNodes();
size_t amountHyperEdges();
void printBiPartiteGraph(bool verbose = false);
};
template <typename N, typename E>
CircuitGraph<N, E>::CircuitGraph()
{
}
template <typename N, typename E>
CircuitGraph<N, E>::~CircuitGraph()
{
}
template <typename N, typename E>
bool CircuitGraph<N, E>::addHyperNode(N hn)
{
return this->hypernodes.insert(hn).second;
}
template <typename N, typename E>
bool CircuitGraph<N, E>::addHyperEdge(E he)
{
return this->hyperedges.insert(he).second;
}
template <typename N, typename E>
bool CircuitGraph<N, E>::addConnection(N hn, E he)
{
if (this->hyperedges.count(he) == 0 || this->hypernodes.count(hn) == 0)
{
return false;
}
return this->edgestonodes[he].insert(hn).second;
}
template <typename N, typename E>
std::set<N> CircuitGraph<N, E>::getHyperEdgeConnections(E he)
{
return this->edgestonodes[he];
}
template <typename N, typename E>
size_t CircuitGraph<N, E>::amountHyperNodes()
{
return this->hypernodes.size();
}
template <typename N, typename E>
size_t CircuitGraph<N, E>::amountHyperEdges()
{
return this->hyperedges.size();
}
/**
* @brief Printing
*
* @todo need to add verbose printing for connections display
*
* @tparam IdxT
* @param verbose
*/
template <typename N, typename E>
void CircuitGraph<N, E>::printBiPartiteGraph(bool verbose)
{
std::cout << "Amount of HyperNodes: " << this->amountHyperNodes() << std::endl;
std::cout << "Amount of HyperEdges: " << this->amountHyperEdges() << std::endl;
std::cout << "Connections per Edge:" << std::endl;
for (auto i : this->edgestonodes)
{
std::cout << i.first << " : {";
for (auto j : i.second)
{
std::cout << j << ", ";
}
std::cout << "}\n";
}
}