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