File: transitive_closure.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 (34 lines) | stat: -rw-r--r-- 908 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
31
32
33
34
#include <iostream>
#include <seqan/graph_algorithms.h>

using namespace seqan2;

int main()
{
    typedef Graph<Directed<> > TGraph;
    typedef VertexDescriptor<TGraph>::Type TVertexDescriptor;
    typedef Size<TGraph>::Type TSize;

    // Create graph with 5 directed edges (3,0), (1,2), ...
    TSize numEdges = 5;
    TVertexDescriptor edges[] = {3, 0, 1, 2, 2, 1, 1, 3, 3, 2};
    TGraph g;
    addEdges(g, edges, numEdges);
    // Print graph to stdout.
    std::cout << g << "\n";

    // Compute transitive closure.
    String<bool> closure;
    transitiveClosure(closure, g);

    // Print result to stdout.
    TSize len = static_cast<TSize>(std::sqrt((double) length(closure)));
    for (TSize row = 0; row < len; ++row)
    {
        for (TSize col = 0; col < len; ++col)
            std::cout << getValue(closure, row * len + col) << ",";
        std::cout << std::endl;
    }

    return 0;
}