demo/grid_graph_demo.cc
changeset 1721 c0f5e8401373
parent 1681 84e43c7ca1e3
child 1763 49045f2d28d4
equal deleted inserted replaced
1:fd420fa29687 2:efd970a676fe
    39 
    39 
    40   Bfs<FilteredGraph> bfs(filtered);
    40   Bfs<FilteredGraph> bfs(filtered);
    41   std::cout << "The length of shortest path: " << 
    41   std::cout << "The length of shortest path: " << 
    42     bfs.run(start, stop) << std::endl;
    42     bfs.run(start, stop) << std::endl;
    43 
    43 
    44   GridGraph::NodeMap<xy<double> > coord(graph);
    44   FilteredGraph::EdgeMap<bool> path(filtered, false);
    45   for (int i = 0; i < graph.width(); ++i) {
       
    46     for (int j = 0; j < graph.height(); ++j) {
       
    47       coord[graph(i, j)] = xy<double>( i * 10.0, j * 10.0);
       
    48     }
       
    49   }
       
    50   
       
    51   FilteredGraph::EdgeMap<Color> color(filtered, Color(0.0, 0.0, 0.0));
       
    52   
    45   
    53   for (GridGraph::Node node = stop; 
    46   for (GridGraph::Node node = stop; 
    54        node != start; node = bfs.predNode(node)) {
    47        node != start; node = bfs.predNode(node)) {
    55     color[bfs.pred(node)] = Color(1.0, 0.0, 0.0);
    48     path[bfs.pred(node)] = true;
    56   }
    49   }
    57   
    50   
    58   graphToEps(filtered, "grid_graph.eps").scaleToA4().
    51   graphToEps(filtered, "grid_graph.eps").scaleToA4().
    59     title("Grid graph").
    52     title("Grid graph").
    60     copyright("(C) 2005 LEMON Project").
    53     copyright("(C) 2005 LEMON Project").
    61     coords(coord).
    54     coords(scaleMap(indexMap(graph), 10)).
    62     enableParallel().
    55     enableParallel().
    63     nodeScale(.45).
    56     nodeScale(0.5).
    64     drawArrows().
    57     drawArrows().
    65     edgeColors(color).
    58     edgeColors(composeMap(ColorSet(), path)).
    66     run();
    59     run();
    67   
    60   
    68   std::cout << "The shortest path is written to grid_graph.eps" << std::endl;
    61   std::cout << "The shortest path is written to grid_graph.eps" << std::endl;
    69 
    62 
    70   return 0;
    63   return 0;