diff options
author | Jaron Kent-Dobias <jaron@kent-dobias.com> | 2019-09-23 17:12:55 -0400 |
---|---|---|
committer | Jaron Kent-Dobias <jaron@kent-dobias.com> | 2019-09-23 17:12:55 -0400 |
commit | 9e3726c6c7762f6292333f85117546acc01f5568 (patch) | |
tree | 6e0f072e0c981bf6aef9e600b9e9f9b1f75f1555 /lib | |
parent | d00d4896955c38818685802de42b4e79e6ef933c (diff) | |
download | fuse_networks-9e3726c6c7762f6292333f85117546acc01f5568.tar.gz fuse_networks-9e3726c6c7762f6292333f85117546acc01f5568.tar.bz2 fuse_networks-9e3726c6c7762f6292333f85117546acc01f5568.zip |
more work, need to finish implementation of searches and make sure existing ones correctly exclude the cycle edges
Diffstat (limited to 'lib')
-rw-r--r-- | lib/src/network.cpp | 55 |
1 files changed, 34 insertions, 21 deletions
diff --git a/lib/src/network.cpp b/lib/src/network.cpp index 6b3873b..2a187c5 100644 --- a/lib/src/network.cpp +++ b/lib/src/network.cpp @@ -78,16 +78,18 @@ void network::get_cycle_edges_helper(std::set<unsigned>& cycle_edges, std::set<unsigned>& seen_vertices, unsigned v_prev, unsigned v_cur) const { for (unsigned ei : G.dual_vertices[v_cur].ne) { - const std::array<unsigned, 2>& e = G.dual_edges[ei].v; - unsigned vn = e[0] == v_cur ? e[1] : e[0]; - - if (vn != v_prev) { - auto it = seen_vertices.find(vn); - if (it == seen_vertices.end()) { - // if (seen_vertices.contains()) { // need to wait for better c++20 support... - cycle_edges.insert(vn); - } else { - this->get_cycle_edges_helper(cycle_edges, seen_vertices, v_cur, vn); + if (fuses[ei]) { + const std::array<unsigned, 2>& e = G.dual_edges[ei].v; + unsigned vn = e[0] == v_cur ? e[1] : e[0]; + + if (vn != v_prev) { + auto it = seen_vertices.find(vn); + if (it == seen_vertices.end()) { + // if (seen_vertices.contains()) { // need to wait for better c++20 support... + cycle_edges.insert(vn); + } else { + this->get_cycle_edges_helper(cycle_edges, seen_vertices, v_cur, vn); + } } } } @@ -102,20 +104,31 @@ std::set<unsigned> network::get_cycle_edges(unsigned v0) const { return cycle_edges; } -std::array<unsigned, 2> network::find_cycle(const std::set<unsigned>& cycle_edges, unsigned v0, unsigned v1) const { - for (unsigned ei : G.dual_vertices[v0].ne) { - const std::array<unsigned, 2>& e = G.dual_edges[ei].v; - unsigned vn = e[0] == v0 ? e[1] : e[0]; - if (vn == v1) { - return {ei}; - } else { - std::list<unsigned> edges = this->get_cycle_edges(vn, v1); - edges.splice(edges.end(), {ei}); - return edges; +bool network::find_cycle_helper(std::array<unsigned, 2>& sig, const std::set<unsigned>& cycle_edges, unsigned vPrev, unsigned vCur, unsigned vEnd) const { + for (unsigned ei : G.dual_vertices[vCur].ne) { + if (fuses[ei]) { + const std::array<unsigned, 2>& e = G.dual_edges[ei].v; + unsigned vn = e[0] == vCur ? e[1] : e[0]; + if (vn != vPrev) { + if (vn == vEnd) { + return true; + } else { + if (find_cycle_helper(sig, cycle_edges, vCur, vn, vEnd)) { + if (G.dual_edges[ei].crossings[0]) sig[0]++; + if (G.dual_edges[ei].crossings[1]) sig[1]++; + return true; + } + } + } } } - return {}; + return false; +} + +std::array<unsigned, 2> network::find_cycle(const std::set<unsigned>& cycle_edges, unsigned v0, unsigned v1) const { + std::array<unsigned, 2> sig; + this->find_cycle_helper(sig, cycle_edges, v0, v0, } void network::update_backbone(const std::vector<double>& c) { |