summaryrefslogtreecommitdiff
path: root/src/analysis_tools.cpp
diff options
context:
space:
mode:
Diffstat (limited to 'src/analysis_tools.cpp')
-rw-r--r--src/analysis_tools.cpp74
1 files changed, 37 insertions, 37 deletions
diff --git a/src/analysis_tools.cpp b/src/analysis_tools.cpp
index bc8095e..dea20f0 100644
--- a/src/analysis_tools.cpp
+++ b/src/analysis_tools.cpp
@@ -18,7 +18,7 @@ bool trivial(boost::detail::edge_desc_impl<boost::undirected_tag,unsigned long>)
return true;
}
-std::list<unsigned> find_minimal_crack(const Graph& G, const network& n) {
+std::list<std::pair<std::array<unsigned, 2>, std::list<unsigned>>> find_minimal_crack(const Graph& G, const network& n) {
Graph Gtmp(n.G.vertices.size());
std::list<unsigned> removed_edges;
@@ -79,53 +79,53 @@ std::list<unsigned> find_minimal_crack(const Graph& G, const network& n) {
}
}
- if (cycles.size() > 1) {
- std::list<std::valarray<uint8_t>> bool_cycles;
- for (auto cycle : cycles) {
- std::valarray<uint8_t> bool_cycle(n.G.edges.size());
- for (auto v : cycle) {
- bool_cycle[v] = 1;
- }
- bool_cycles.push_back(bool_cycle);
+ std::list<std::valarray<uint8_t>> bool_cycles;
+ for (auto cycle : cycles) {
+ std::valarray<uint8_t> bool_cycle(n.G.edges.size());
+ for (auto v : cycle) {
+ bool_cycle[v] = 1;
}
+ bool_cycles.push_back(bool_cycle);
+ }
- // generate all possible cycles by taking xor of the edge sets of the known cycles
- for (auto it1 = bool_cycles.begin(); it1 != std::prev(bool_cycles.end()); it1++) {
- for (auto it2 = std::next(it1); it2 != bool_cycles.end(); it2++) {
- std::valarray<uint8_t> new_bool_cycle = (*it1) ^ (*it2);
- std::list<unsigned> new_cycle;
- unsigned pos = 0;
- for (uint8_t included : new_bool_cycle) {
- if (included) {
- new_cycle.push_back(pos);
- }
- pos++;
+ // generate all possible cycles by taking xor of the edge sets of the known cycles
+ for (auto it1 = bool_cycles.begin(); it1 != std::prev(bool_cycles.end()); it1++) {
+ for (auto it2 = std::next(it1); it2 != bool_cycles.end(); it2++) {
+ std::valarray<uint8_t> new_bool_cycle = (*it1) ^ (*it2);
+ std::list<unsigned> new_cycle;
+ unsigned pos = 0;
+ for (uint8_t included : new_bool_cycle) {
+ if (included) {
+ new_cycle.push_back(pos);
}
- cycles.push_back(new_cycle);
+ pos++;
}
+ cycles.push_back(new_cycle);
}
+ }
- // find the cycle representing the crack by counting boundary crossings
- for (auto cycle : cycles) {
- std::array<unsigned, 2> crossing_count{0,0};
+ std::list<std::pair<std::array<unsigned, 2>, std::list<unsigned>>> output;
- for (auto edge : cycle) {
- if (n.G.dual_edges[edge].crossings[0]) {
- crossing_count[0]++;
- }
- if (n.G.dual_edges[edge].crossings[1]) {
- crossing_count[1]++;
- }
- }
+ // find the cycle representing the crack by counting boundary crossings
+ for (auto cycle : cycles) {
+ std::array<unsigned, 2> crossing_count{0,0};
- if (crossing_count[0] % 2 == 1 && crossing_count[1] % 2 == 0) {
- return cycle;
+ for (auto edge : cycle) {
+ if (n.G.dual_edges[edge].crossings[0]) {
+ crossing_count[0]++;
+ }
+ if (n.G.dual_edges[edge].crossings[1]) {
+ crossing_count[1]++;
}
}
- } else {
- return cycles.front();
+
+ if (crossing_count[0] % 2 == 1 && crossing_count[1] % 2 == 0) {
+ output.push_back({{1, 0}, cycle});
+ } else if (crossing_count[0] % 2 == 0 && crossing_count[1] % 2 == 1) {
+ output.push_back({{0, 1}, cycle});
+ }
}
- throw badcycleex;
+ return output;
}