#include "geneorder.h"
#include <algorithm>
+#include <set>
#include <cstdlib>
+#include <iostream>
using namespace std;
std::pair<int,int> longestSequences(const GeneOrder& go){
+ vector<vector<int> > v = robinsonSchensted(go);
+ return pair<int,int>(v[0].size(),v.size());
}
-
-/*
-robSche2 :: [Int] -> [[Int]] -> [[Int]]
-robSche2 [] ys = ys
-robSche2 (x:xs) ys = robSche2 xs $ robSche4 x ys
-
-robSche3 :: Int -> [Int] -> (Maybe Int,[Int])
-robSche3 x ys = let yless = [y | y <- ys, y < x] in
- let ymore = [y | y <- ys, y > x] in
- case ymore of
- [] -> (Nothing, yless++[x])
- (y:ys) -> (Just y, yless++(x:ys))
-
-robSche4 :: Int -> [[Int]] -> [[Int]]
-robSche4 x [] = [[x]]
-robSche4 x (y:ys) = case robSche3 x y of
- (Nothing, y) -> y:ys
- (Just x, y) -> y:robSche4 x ys
-*/
std::vector<std::vector<int> > robinsonSchensted(const GeneOrder& go){
vector<vector<int> > v;
for (GeneOrder::iterator i = go.begin(); i != go.end(); ++i){
}
return v;
}
+
+struct FindP{
+ size_t p;
+ FindP(size_t p) : p(p) {}
+ bool operator()(Interval i){
+ return (i.first == p || i.second == p);
+ }
+};
+
+
+int countCycles(const GeneOrder& go){
+ int cycles = 0;
+ set<size_t> marked;
+ vector<Interval> intervals = findIntervals(go);
+ vector<Interval> points = findIntervalsAtPoints(intervals);
+ for (size_t p = 1; p < go.size(); ++p){
+ if (marked.find(p) != marked.end())
+ continue;
+ Interval i = intervals[points[p].first];
+ while (marked.find(p) == marked.end()){
+ marked.insert(p);
+ if (i == intervals[points[p].first])
+ i = intervals[points[p].second];
+ else
+ i = intervals[points[p].first];
+
+ if (p == i.first)
+ p = i.second;
+ else
+ p = i.first;
+ }
+ ++cycles;
+ }
+ return cycles;
+}
+
+std::vector<Component> findComponents(const GeneOrder& go){
+ return vector<Component>();
+}
+
+/**
+ *
+ */
+std::vector<Interval> findIntervals(const GeneOrder& go){
+ vector<Interval> intervals(go.size()-1,Interval(go.size(),go.size()));
+ size_t n = 0;
+ for (GeneOrder::iterator g = go.begin(); g != go.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);
+ }
+ return intervals;
+}
+
+/**
+ *
+ */
+std::vector<Interval> findIntervalsAtPoints(const vector<Interval>& intervals){
+ size_t max = intervals.size()+1;
+ vector<Interval> points(max,Interval(max,max));
+ size_t n = 0;
+ for (vector<Interval>::const_iterator i = intervals.begin(); i != intervals.end(); ++i, ++n){
+ if (points[i->first].first == max){
+ points[i->first].first = n;
+ }else
+ points[i->first].second = n;
+
+ if (points[i->second].first == max){
+ points[i->second].first = n;
+ }else
+ points[i->second].second = n;
+ }
+ return points;
+
+}