src/work/athos/uf_demo.cc
author beckerjc
Sat, 17 Apr 2004 19:34:43 +0000
changeset 350 3a9a767b841e
child 921 818510fa3d99
permissions -rw-r--r--
Maximum Adjacency Ordering (beta)
     1 //This is just a simple example program to test my union-find structure
     2 
     3 //#include <marciMap.hh>
     4 #include <union_find.h>
     5 #include <iostream>
     6 #include <list_graph.hh>
     7 using namespace hugo;
     8 using namespace std;
     9 
    10 int main (int, char*[])
    11 {
    12   typedef ListGraph::NodeIt NodeIt;
    13   typedef ListGraph::EachNodeIt EachNodeIt;
    14   typedef ListGraph::EdgeIt EdgeIt;
    15 
    16   ListGraph flowG;
    17 
    18   
    19   //Marci példája
    20 
    21 
    22 
    23   NodeIt s=flowG.addNode();
    24   NodeIt v1=flowG.addNode();
    25   NodeIt v2=flowG.addNode();
    26   NodeIt v3=flowG.addNode();
    27   NodeIt v4=flowG.addNode();
    28   NodeIt t=flowG.addNode();
    29 
    30   ListGraph::NodeMap<int> component(flowG);
    31 
    32   component.set(s, -1);
    33   component.set(v1, -1);
    34   component.set(v2, -1);
    35   component.set(v3, -1);
    36   component.set(v4, -1);
    37   component.set(t, -1);
    38 
    39   UnionFind< NodeIt, ListGraph::NodeMap<int> > uf(component);
    40   cout<<"Merge s and v1: "<<uf.findAndMerge(s,v1)<<endl;
    41   cout<<"Merge s and v1: "<<uf.findAndMerge(s,v1)<<endl;
    42   cout<<"Merge s and v2: "<<uf.findAndMerge(s,v3)<<endl;
    43   for(EachNodeIt i=flowG.template first<EachNodeIt>(); i.valid(); ++i) {
    44 
    45     cout<<"Az "<<flowG.id(i)<<". pont itt van: "<<uf.find(i)<<endl;
    46     //std::cout << node_name.get(i) << ": ";
    47   }
    48 }