return v;
}
+struct FindP{
+ size_t p;
+ FindP(size_t p) : p(p) {}
+ bool operator()(Interval i){
+ return (i.first == p || i.second == p);
+ }
+};
+
+
+std::vector<Interval> findIntervalsAtPoints(const vector<Interval>& intervals){
+ vector<Interval> points;
+ for (size_t p = 1; p <= intervals.size(); ++p){
+ cout << endl << "Point " << p << " : ";
+ size_t f = 0;
+ size_t s = 0;
+ bool found = false;
+ size_t n = 0;
+ for (vector<Interval>::const_iterator i = intervals.begin(); i != intervals.end(); ++i, ++n){
+ if (i->first == p){
+ if (!found){
+ f = n;
+ found = true;
+ }else{
+ s = n;
+ break;
+ }
+ }
+ if (i->second == p){
+ if (!found){
+ f = n;
+ found = true;
+ }else{
+ s = n;
+ break;
+ }
+ }
+ }
+ cout << f << ":" << s << endl;
+ points.push_back(Interval(f,s));
+ }
+ return points;
+
+}
+
int countCycles(const GeneOrder& go){
int cycles = 0;
set<size_t> marked;
- for (size_t p = 1; p < go.size() - 1; ++p){
+ vector<Interval> intervals = findIntervals(go);
+ vector<Interval> points;
+ for (size_t p = 1; p < go.size(); ++p){
if (marked.find(p) != marked.end())
continue;
+ Interval i = intervals[points[p-1].first];
+ while (marked.find(p) != marked.end()){
+ marked.insert(p);
+ if (i == intervals[points[p-1].first])
+ i = intervals[points[p-1].second];
+ else
+ i = intervals[points[p-1].first];
+
+ if (p == i.first)
+ p = i.second;
+ else
+ p = i.first;
+ }
+ ++cycles;
}
return cycles;
}
return vector<Component>();
}
-//TODO: Think of a better than O(n^2) implementation
+/**
+ * TODO: Think of a better than O(n^2) implementation
+ * Possibly move it to GeneOrder too
+ */
std::vector<Interval> findIntervals(const GeneOrder& go){
vector<Interval> intervals;
for (size_t i = 0; i < go.size() - 1; ++i){
}
return intervals;
}
+
*/
std::vector<Interval> findIntervals(const GeneOrder& go);
+/**
+ * Creates a list with the intervals at each point.
+ */
+std::vector<Interval> findIntervalsAtPoints(const std::vector<Interval>& intervals);
+
#endif
CPPUNIT_TEST( testRobinsonSchensted );
CPPUNIT_TEST( testLongestSequences );
CPPUNIT_TEST( testFindIntervals );
- CPPUNIT_TEST( testCountCycles );
+ CPPUNIT_TEST( testFindIntervalsAtPoints );
+ //CPPUNIT_TEST( testCountCycles );
CPPUNIT_TEST_SUITE_END();
protected:
CPPUNIT_ASSERT(go10 == v[0]);
CPPUNIT_ASSERT(go12 == v[2]);
- GeneOrder go2(_validPerm2.begin(),_validPerm2.end());
+ GeneOrder go2(_validPerm3.begin(),_validPerm3.end());
+ v = findIntervals(go2);
+ CPPUNIT_ASSERT_EQUAL(16ul,v.size());
+ Interval go20(1,2);
+ Interval go22(4,2);
+ CPPUNIT_ASSERT(go20 == v[0]);
+ CPPUNIT_ASSERT(go22 == v[2]);
+ }
+ void testFindIntervalsAtPoints (){
+ GeneOrder go(_validPerm.begin(),_validPerm.end());
+ vector<Interval> v = findIntervals(go);
+ v = findIntervalsAtPoints(v);
+ CPPUNIT_ASSERT_EQUAL(4ul,v.size());
+ Interval go10(0,0);
+ Interval go12(2,2);
+ CPPUNIT_ASSERT(go10 == v[0]);
+ CPPUNIT_ASSERT(go12 == v[2]);
+
+ GeneOrder go2(_validPerm3.begin(),_validPerm3.end());
v = findIntervals(go2);
- CPPUNIT_ASSERT_EQUAL(9ul,v.size());
- Interval go20(1,3);
- Interval go22(1,4);
+ v = findIntervalsAtPoints(v);
+ CPPUNIT_ASSERT_EQUAL(16ul,v.size());
+ Interval go20(0,3);
+ Interval go22(1,1);
CPPUNIT_ASSERT(go20 == v[0]);
CPPUNIT_ASSERT(go22 == v[2]);
}