Example Program
Heaviest Increasing Subsequence
Heaviest increasing subsequence code example
A tutorial about the heaviest increasing subsequence algorithm.
1#include <iostream>
2#include <seqan/graph_algorithms.h>
3
4using namespace seqan;
5
6
7int main() {
Creation of a simple sequence and corresponding weights
8    String<char> seq("zeitgeist");
9    String<unsigned int> weights;
10    resize(weights, length(seq), 1);
11    assignProperty(weights, 2, 10);
Out-parameter: A string of positions belonging to the heaviest increasing subsequence
12    typedef Position<String<unsigned int> >::Type TPosition;
13    String<TPosition> pos;
Heaviest increasing subsequence and the corresponding weight
14    unsigned int w = heaviestIncreasingSubsequence(seq, weights, pos);
Console Output
15    for(int i = 0; i< (int) length(seq); ++i) {
16        ::std::cout << seq[i] << "(Weight=" << getProperty(weights, i) << "),";
17    }
18    ::std::cout << ::std::endl;
19    ::std::cout << "His: " << ::std::endl;
20    for(int i = length(pos)-1; i>=0; --i) {
21        ::std::cout << seq[pos[i]] <<  ',';
22    }
23    ::std::cout << "(Weight=" << w << ')' << ::std::endl;
24    return 0;
25}
SeqAn - Sequence Analysis Library - www.seqan.de
 

Page built @2011/02/08 21:37:01