48 const vector<vector<Index>>& chains) {
50 for (
const vector<Index>& chain2 : chains) {
51 if (chain2.size() == chain.size()) {
53 for (
size_t index = 0; index < chain.size(); ++index) {
54 if (chain2.at(index) != chain.at(index)) {
98 unordered_map<Index, Index> vertex_count;
104 if (reduced_edge.loop()) {
108 vector<Index> chain = reduced_edge.getChain();
109 for (; index < chain.size(); ++index) {
110 if (vertex_count.count(chain.at(index))) {
111 vertex_count[chain.at(index)] += increment;
113 vertex_count[chain.at(index)] = increment;
117 set<Index> junctions;
118 for (pair<Index, Index> vertex_and_count : vertex_count) {
119 if (vertex_and_count.second > 2) {
120 junctions.insert(vertex_and_count.first);
155 vector<Edge>& edges,
const ReducedEdge reduced_edge,
156 unordered_map<
Edge, vector<vector<Index>>>& expanded_edges) {
159 if (expanded_edges.count(edge)) {
163 expanded_edges[edge].push_back(reduced_edge.
getChain());
166 expanded_edges[edge].push_back(reduced_edge.
getChain());
168 edges.push_back(edge);
196 size_t ignore_first_and_last_vertex = 2;
197 size_t total_number_to_parse =
198 (chain.size() - ignore_first_and_last_vertex) / 2;
199 bool reverse_vector =
false;
200 for (
size_t count = 0; count < (total_number_to_parse); ++count) {
201 if (chain.at(chain.size() - count - 1) < chain.at(count + 1)) {
202 reverse_vector =
true;
207 if (reverse_vector) {
208 reverse(chain.begin(), chain.end());
214 unordered_map<
Edge, vector<vector<Index>>>& expanded_edges,
215 vector<Index> chain,
Index vertex,
size_t& chain_index) {
217 Edge edge(vertex, vertex);
218 edges.push_back(edge);
219 vector<Index> new_chain;
220 for (
size_t index = 0; index < chain.size(); ++index) {
221 if (((chain_index + index) % chain.size()) == 0) {
224 Index new_chain_index = (chain_index + index) % chain.size();
225 new_chain.push_back(chain.at(new_chain_index));
232 expanded_edges[edge].push_back(new_chain);
240 for (
const ReducedEdge& reduced_edge : reduced_edges) {
241 vector<Index> chain = reduced_edge.getChain();
242 for (
const Index vertex : chain) {
243 vertices.insert(vertex);
250 const unordered_map<
Edge, vector<vector<Index>>>& expanded_edges) {
251 set<Index> all_vertices;
253 for (
const auto& edge_and_chains : expanded_edges) {
254 for (vector<Index> chain : edge_and_chains.second) {
255 all_vertices.insert(chain.begin(), chain.end());
265 unordered_map<Index, GraphNode> nodes) {
271 for (
const ReducedEdge& reduced_edge : reduced_edges) {
273 if (reduced_edge.loop() &&
274 junctions_.count(reduced_edge.getEndPoint1()) == 0) {
275 vector<Index> chain = reduced_edge.getChain();
276 size_t chain_index = 0;
277 bool edge_added =
false;
278 for (
Index vertex : chain) {
306 unordered_map<Index, GraphNode> nodes;
307 for (
const Index vertex : vertices) {
311 init_(reduced_edges, nodes);
315 unordered_map<Index, GraphNode> nodes) {
318 if (nodes.size() < vertices.size()) {
319 throw invalid_argument(
320 "The number of nodes passed into a reduced graph "
321 "must be greater or equivalent to the number of vertices");
323 for (
const Index vertex : vertices) {
324 if (nodes.count(vertex) == 0) {
325 throw invalid_argument(
"A vertex is missing its corresponding node.");
328 init_(reduced_edges, nodes);
331 for (pair<const Index, GraphNode>& id_and_node : nodes) {
332 if (vertices.count(id_and_node.first) == 0) {
339 vector<Edge> all_expanded_edges;
340 for (
const pair<
Edge, vector<vector<Index>>> edge_and_vertices :
342 vector<vector<Edge>> edges_local =
expandEdge(edge_and_vertices.first);
343 for (vector<Edge>& edges : edges_local) {
344 all_expanded_edges.insert(all_expanded_edges.end(), edges.begin(),
352 vector<vector<Edge>> all_edges;
354 for (vector<Index> vertices : chains) {
356 for (
size_t index = 0; index < (vertices.size() - 1); ++index) {
357 Edge edge_temp(vertices.at(index), vertices.at(index + 1));
358 edges.push_back(edge_temp);
360 all_edges.push_back(edges);
367 vector<pair<Index, GraphNode>> nodes;
368 for (
const Index vertex : vertices) {
369 pair<Index, GraphNode> id_and_node(vertex,
nodes_.at(vertex));
370 nodes.push_back(id_and_node);
375 for (pair<Index, GraphNode> id_and_node :
nodes_) {
376 if (!all_connected_vertices.count(id_and_node.first)) {
377 nodes.push_back(id_and_node);
385 set<Index> all_connected_vertices =
387 vector<Index> vertices;
388 for (
const pair<Index, GraphNode> id_and_node :
nodes_) {
389 if (all_connected_vertices.count(id_and_node.first) ==
false) {
390 vertices.push_back(id_and_node.first);
399 os <<
"Graph" << endl;
400 for (
const pair<const Index, GraphNode>& id_and_node : graph.
nodes_) {
401 os <<
"Node " << id_and_node.first << endl;
402 os << id_and_node.second << endl;
409 os <<
"Expanded Edge Chains" << endl;
411 for (
const pair<
const Edge, vector<vector<Index>>>& edge_and_chains :
413 for (
const vector<Index>& chain : edge_and_chains.second) {
414 for (
const Index vertex : chain) {
base class for all analysis tools