File: heaviest_increasing_subsequence.cpp

package info (click to toggle)
seqan2 2.5.2-1
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid
  • size: 228,748 kB
  • sloc: cpp: 257,602; ansic: 91,967; python: 8,326; sh: 1,056; xml: 570; makefile: 229; awk: 51; javascript: 21
file content (30 lines) | stat: -rw-r--r-- 890 bytes parent folder | download | duplicates (2)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
#include <iostream>
#include <seqan/sequence.h>
#include <seqan/graph_algorithms.h>

using namespace seqan2;

int main()
{
    // Fill a string and define corresponding weights.
    String<char> seq("zeitgeist");
    String<unsigned int> weights;
    resize(weights, length(seq), 1);
    assignProperty(weights, 2, 10);

    // Compute heaviest increasing subsequence.
    typedef Position<String<unsigned int> >::Type TPosition;
    String<TPosition> pos;
    unsigned int w = heaviestIncreasingSubsequence(seq, weights, pos);

    // Print the results to stdout.
    for (int i = 0; i < (int) length(seq); ++i)
        std::cout << seq[i] << "(Weight=" << getProperty(weights, i) << "),";
    std::cout << "\n"
              << "His: \n";
    for (int i = length(pos) - 1; i >= 0; --i)
        std::cout << seq[pos[i]] <<  ',';
    std::cout << "(Weight=" << w << ")\n";

    return 0;
}