Example Program
Transitive Closure
Transitive closure code example
A tutorial about the transitive closure algorithm.
1#include <iostream>
2#include <seqan/graph_algorithms.h>
3
4using namespace seqan;
5
6int main() {
7    typedef Graph<Directed<> > TGraph;
8    typedef VertexDescriptor<TGraph>::Type TVertexDescriptor;
9    typedef EdgeDescriptor<TGraph>::Type TEdgeDescriptor;
10    typedef Size<TGraph>::Type TSize;
Graph creation: 5 directed edges (3,0), (1,2), ...
11    TSize numEdges = 5;
12    TVertexDescriptor edges[] = {3,0, 1,2, 2,1, 1,3, 3,2};
13    TGraph g;
14    addEdges(g, edges, numEdges);
15    ::std::cout << g << ::std::endl;
Out-parameter: Closure matrix
16    String<bool> closure;
Transitive-Closure
17    transitiveClosure(g,closure);
Console output
18    TSize len = (TSize) ::std::sqrt((double) length(closure));
19    for (TSize row=0;row < len;++row) {
20        for (TSize col=0;col < len;++col) {
21            ::std::cout << getValue(closure, row*len+col) << ",";
22        }
23        ::std::cout << ::std::endl;
24    }
25    return 0;
26}
SeqAn - Sequence Analysis Library - www.seqan.de
 

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