X-Git-Url: https://ruin.nu/git/?a=blobdiff_plain;f=src%2Fgenealgorithms.cpp;h=174c6f7b0414277b006b562f2736a83077db9fb7;hb=6ba92ada02bfbb04abb8a0c7a039ec63c7c9921e;hp=67c504e77b3f9bdfad9589236e8f65f8e2b2cd5d;hpb=e44303f027e957d05c9e9418fbd68171f3707599;p=germs.git diff --git a/src/genealgorithms.cpp b/src/genealgorithms.cpp index 67c504e..174c6f7 100644 --- a/src/genealgorithms.cpp +++ b/src/genealgorithms.cpp @@ -20,6 +20,7 @@ #include "genealgorithms.h" #include "geneorder.h" +#include "componenttree.h" #include #include @@ -146,7 +147,7 @@ std::vector findComponents(const GeneOrder& go){ s = Sdir.top(); } if (go[i] > 0 && dir[i] == dir[s] && static_cast(i - s) == p[i] - p[s]) - components.push_back(Component(p[s],p[i],(s+1 == i ? 0 : os[s]))); + components.push_back(Component(p[s],p[i],(s+1 == i ? 0 : os[s]),s,i)); //Reverse if (p[i-1] < p[i]) @@ -162,7 +163,7 @@ std::vector findComponents(const GeneOrder& go){ s = Srev.top(); } if (go[i] < 0 && rev[i] == rev[s] && static_cast(i - s) == p[s] - p[i]) - components.push_back(Component(-p[s],-p[i],(s+1 == i ? 0 : os[s]))); + components.push_back(Component(-p[s],-p[i],(s+1 == i ? 0 : os[s]),s,i)); //Update stacks if (go[i] > 0) @@ -173,18 +174,40 @@ std::vector findComponents(const GeneOrder& go){ return components; } +int sign2(Gene g){ + if (g < 0) + return -1; + return 1; +} /** * */ std::vector findIntervals(const GeneOrder& go){ - vector intervals(go.size()-1,Interval(go.size(),go.size())); + const size_t max = go.size(); + vector intervals(go.size()-1,Interval(max,max,false)); size_t n = 0; - for (GeneOrder::iterator g = go.begin(); g != go.end(); ++g, ++n){ + const GeneOrder::iterator end = go.end(); + for (GeneOrder::iterator g = go.begin(); g != end; ++g, ++n){ size_t i = abs(*g); - if (i < go.size() - 1) - intervals[i].first = n + (*g >= 0 ? 1 : 0); - if (i > 0) - intervals[i-1].second = n + (*g < 0 ? 1 : 0); + if (i < max - 1){ + Interval& curr = intervals[i]; + curr.first = n + (*g >= 0 ? 1 : 0); + + if (curr.second == max) + curr.oriented = *g < 0; + else + curr.oriented ^= *g < 0; + } + if (i > 0){ + Interval& prev = intervals[i-1]; + prev.second = n + (*g < 0 ? 1 : 0); + + if (prev.first == max) + prev.oriented = *g < 0; + else + prev.oriented ^= *g < 0; + } + } return intervals; } @@ -194,7 +217,7 @@ std::vector findIntervals(const GeneOrder& go){ */ std::vector findIntervalsAtPoints(const vector& intervals){ size_t max = intervals.size()+1; - vector points(max,Interval(max,max)); + vector points(max,Interval(max,max,false)); size_t n = 0; for (vector::const_iterator i = intervals.begin(); i != intervals.end(); ++i, ++n){ if (points[i->first].first == max){