demo/graph_orientation.cc
changeset 1912 d9205a711324
parent 1875 98698b69a902
child 1913 49fe71fce7fb
equal deleted inserted replaced
2:b68ba72fb8ac 3:1edec8381b2e
    47   }
    47   }
    48   
    48   
    49   ListGraph g;
    49   ListGraph g;
    50 
    50 
    51   ListGraph::NodeMap<int> f(g); //in-deg requirement;
    51   ListGraph::NodeMap<int> f(g); //in-deg requirement;
    52   ListGraph::NodeMap<int> id(g);
    52   ListGraph::NodeMap<int> label(g);
    53   ListGraph::NodeMap<xy<double> > coords(g);
    53   ListGraph::NodeMap<xy<double> > coords(g);
    54   
    54   
    55   try {
    55   try {
    56     GraphReader<ListGraph> reader(argv[1],g);
    56     GraphReader<ListGraph> reader(argv[1],g);
    57     reader.readNodeMap("f",f);
    57     reader.readNodeMap("f",f);
    58     reader.readNodeMap("id",id);
    58     reader.readNodeMap("label",label);
    59     reader.readNodeMap("coordinates_x",xMap(coords));
    59     reader.readNodeMap("coordinates_x",xMap(coords));
    60     reader.readNodeMap("coordinates_y",yMap(coords));
    60     reader.readNodeMap("coordinates_y",yMap(coords));
    61     reader.run();
    61     reader.run();
    62   } catch (DataFormatError& error) {
    62   } catch (DataFormatError& error) {
    63     std::cerr << error.what() << std::endl;
    63     std::cerr << error.what() << std::endl;
    78 
    78 
    79   int nodeNum=countNodes(g);
    79   int nodeNum=countNodes(g);
    80   
    80   
    81   Node act;
    81   Node act;
    82   while((act=IterableBoolNodeMap<ListGraph>::TrueIt(active))!=INVALID) {
    82   while((act=IterableBoolNodeMap<ListGraph>::TrueIt(active))!=INVALID) {
    83     std::cout << "Process node " << id[act]
    83     std::cout << "Process node " << label[act]
    84 	      << " (def=" << def[act]
    84 	      << " (def=" << def[act]
    85 	      << " lev=" << level[act] << "): ";
    85 	      << " lev=" << level[act] << "): ";
    86     OutEdgeIt e(g,act);
    86     OutEdgeIt e(g,act);
    87     while(e!=INVALID && level[g.target(e)]>=level[act]) ++e;
    87     while(e!=INVALID && level[g.target(e)]>=level[act]) ++e;
    88     if(e!=INVALID) {
    88     if(e!=INVALID) {
    89       std::cout << " REVERT EDGE " << g.id(e)
    89       std::cout << " REVERT EDGE " << g.id(e)
    90 		<< " (" << id[g.source(e)] << "---"
    90 		<< " (" << label[g.source(e)] << "---"
    91 		<< id[g.target(e)] << ")"
    91 		<< label[g.target(e)] << ")"
    92 		<< std::endl;
    92 		<< std::endl;
    93       if(--def[act]==0) active[act]=false;
    93       if(--def[act]==0) active[act]=false;
    94       if(++def[g.target(e)]>0) active[g.target(e)]=true;
    94       if(++def[g.target(e)]>0) active[g.target(e)]=true;
    95       g.reverseEdge(e);
    95       g.reverseEdge(e);
    96       rev[e]=!rev[e];
    96       rev[e]=!rev[e];