Example Program
Kruskals Algorithm
Kruskal's algorithm for computing a minimum spanning tree.
 1 #include  2 #include  3 4 using namespace seqan; 5 6 7 int main() { 8 typedef Graph > TGraph; 9 typedef VertexDescriptor::Type TVertexDescriptor; 10 typedef EdgeDescriptor::Type TEdgeDescriptor; 11 typedef Size::Type TSize;
Graph creation: 14 undirected edges {0,1}, {0,6}, ...
 12 TSize numEdges = 14; 13 TVertexDescriptor edges[] = {0,1, 0,6, 1,2, 1,6, 2,3, 2,4, 2,8, 3,5, 3,8, 4,6, 4,7, 5,8, 6,7, 7,8}; 14 TGraph g; 15 addEdges(g,edges, numEdges); 16 ::std::cout << g << std::endl;
Two external property maps: Weight and vertex names
 17 unsigned int weights[] =  {4,   8,   8,   11,  7,   2,   4,   9,   14,  7,   6,   10,  1,   2  }; 18 char names[] = {'a', 'b', 'c', 'd', 'i', 'e', 'h', 'g', 'f'}; 19 String weightMap; 20 resizeEdgeMap(g, weightMap, weights); 21 String nameMap; 22 resizeVertexMap(g,nameMap, names);
Out-parameter: Selected tree edges
 23 String treeEdges;
Kruskal's algorithm
 24 kruskalsAlgorithm(g, 0, weightMap, treeEdges);
Console output
 25 ::std::cout << "Minimum Spanning Tree (Kruskal's algorithm): " << ::std::endl; 26 ::std::cout << "Tree Edges: "; 27 typedef Iterator >::Type TStrIterator; 28 TStrIterator it = begin(treeEdges); 29 TStrIterator itEnd = end(treeEdges); 30 while(it!=itEnd) { 31 ::std::cout << "(" << getProperty(nameMap,getValue(it)) << ","; 32 goNext(it); 33 ::std::cout << getProperty(nameMap,getValue(it)) << "), "; 34 goNext(it); 35 } 36 ::std::cout << ::std::endl; 37 return 0; 38 }
SeqAn - Sequence Analysis Library - www.seqan.de

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