demo/topology_demo.cc
changeset 2369 6ae1a97055a2
parent 2242 16523135943d
child 2391 14a343be7a5a
equal deleted inserted replaced
10:96513deef01e 11:ababe25e0360
    34 ///  Demo what shows the result of some topology functions.
    34 ///  Demo what shows the result of some topology functions.
    35 ///
    35 ///
    36 /// \include topology_demo.cc
    36 /// \include topology_demo.cc
    37 
    37 
    38 using namespace lemon;
    38 using namespace lemon;
       
    39 using namespace lemon::dim2;
    39 using namespace std;
    40 using namespace std;
    40 
    41 
    41 
    42 
    42 Color color(bool val) {
    43 Color color(bool val) {
    43   return val ? RED : BLUE;
    44   return val ? RED : BLUE;
    47 void drawConnectedComponents() {
    48 void drawConnectedComponents() {
    48   typedef ListUGraph Graph;
    49   typedef ListUGraph Graph;
    49   typedef Graph::Node Node;
    50   typedef Graph::Node Node;
    50 
    51 
    51   Graph graph;
    52   Graph graph;
    52   Graph::NodeMap<dim2::Point<double> > coords(graph);
    53   Graph::NodeMap<Point<double> > coords(graph);
    53 
    54 
    54   UGraphReader<Graph>("u_components.lgf", graph).
    55   UGraphReader<Graph>("u_components.lgf", graph).
    55     readNodeMap("coordinates_x", xMap(coords)).
    56     readNodeMap("coordinates_x", xMap(coords)).
    56     readNodeMap("coordinates_y", yMap(coords)).
    57     readNodeMap("coordinates_y", yMap(coords)).
    57     run();
    58     run();
    61   Graph::NodeMap<int> compMap(graph);
    62   Graph::NodeMap<int> compMap(graph);
    62   connectedComponents(graph, compMap);
    63   connectedComponents(graph, compMap);
    63 
    64 
    64   graphToEps(graph, "connected_components.eps").undirected().
    65   graphToEps(graph, "connected_components.eps").undirected().
    65     coords(coords).scaleToA4().enableParallel().
    66     coords(coords).scaleToA4().enableParallel().
    66     parEdgeDist(20.0).edgeWidthScale(2.0).nodeScale(20.0).
       
    67     nodeColors(composeMap(palette, compMap)).run();
    67     nodeColors(composeMap(palette, compMap)).run();
    68 
    68 
    69   std::cout << "Result: connected_components.eps" << std::endl;
    69   std::cout << "Result: connected_components.eps" << std::endl;
    70 }
    70 }
    71 
    71 
    72 void drawStronglyConnectedComponents() {
    72 void drawStronglyConnectedComponents() {
    73   typedef ListGraph Graph;
    73   typedef ListGraph Graph;
    74   typedef Graph::Node Node;
    74   typedef Graph::Node Node;
    75 
    75 
    76   Graph graph;
    76   Graph graph;
    77   Graph::NodeMap<dim2::Point<double> > coords(graph);
    77   Graph::NodeMap<Point<double> > coords(graph);
    78 
    78 
    79   GraphReader<Graph>("dir_components.lgf", graph).
    79   GraphReader<Graph>("dir_components.lgf", graph).
    80     readNodeMap("coordinates_x", xMap(coords)).
    80     readNodeMap("coordinates_x", xMap(coords)).
    81     readNodeMap("coordinates_y", yMap(coords)).
    81     readNodeMap("coordinates_y", yMap(coords)).
    82     run();
    82     run();
    87   Graph::EdgeMap<bool> cutMap(graph);
    87   Graph::EdgeMap<bool> cutMap(graph);
    88   stronglyConnectedComponents(graph, compMap);
    88   stronglyConnectedComponents(graph, compMap);
    89   stronglyConnectedCutEdges(graph, cutMap);
    89   stronglyConnectedCutEdges(graph, cutMap);
    90 
    90 
    91   graphToEps(graph, "strongly_connected_components.eps").
    91   graphToEps(graph, "strongly_connected_components.eps").
    92     coords(coords).scaleToA4().enableParallel().
    92     coords(coords).scaleToA4().enableParallel().drawArrows().
    93     drawArrows().arrowWidth(10.0).arrowLength(10.0).
       
    94     parEdgeDist(20.0).edgeWidthScale(2.0).nodeScale(20.0).
       
    95     nodeColors(composeMap(palette, compMap)).
    93     nodeColors(composeMap(palette, compMap)).
    96     edgeColors(composeMap(functorMap(&color), cutMap)).run();
    94     edgeColors(composeMap(functorMap(&color), cutMap)).run();
    97 
    95 
    98   std::cout << "Result: strongly_connected_components.eps" << std::endl;
    96   std::cout << "Result: strongly_connected_components.eps" << std::endl;
    99 }
    97 }
   102   typedef ListUGraph Graph;
   100   typedef ListUGraph Graph;
   103   typedef Graph::Node Node;
   101   typedef Graph::Node Node;
   104   typedef Graph::UEdge UEdge;
   102   typedef Graph::UEdge UEdge;
   105 
   103 
   106   Graph graph;
   104   Graph graph;
   107   Graph::NodeMap<dim2::Point<double> > coords(graph);
   105   Graph::NodeMap<Point<double> > coords(graph);
   108 
   106 
   109   UGraphReader<Graph>("u_components.lgf", graph).
   107   UGraphReader<Graph>("u_components.lgf", graph).
   110     readNodeMap("coordinates_x", xMap(coords)).
   108     readNodeMap("coordinates_x", xMap(coords)).
   111     readNodeMap("coordinates_y", yMap(coords)).
   109     readNodeMap("coordinates_y", yMap(coords)).
   112     run();
   110     run();
   118   biNodeConnectedComponents(graph, compMap);
   116   biNodeConnectedComponents(graph, compMap);
   119   biNodeConnectedCutNodes(graph, cutMap);
   117   biNodeConnectedCutNodes(graph, cutMap);
   120 
   118 
   121   graphToEps(graph, "bi_node_connected_components.eps").undirected().
   119   graphToEps(graph, "bi_node_connected_components.eps").undirected().
   122     coords(coords).scaleToA4().enableParallel().
   120     coords(coords).scaleToA4().enableParallel().
   123     parEdgeDist(20.0).edgeWidthScale(5.0).nodeScale(20.0).
       
   124     edgeColors(composeMap(palette, compMap)).
   121     edgeColors(composeMap(palette, compMap)).
   125     nodeColors(composeMap(functorMap(&color), cutMap)).
   122     nodeColors(composeMap(functorMap(&color), cutMap)).
   126     run();
   123     run();
   127 
   124 
   128   std::cout << "Result: bi_node_connected_components.eps" << std::endl;
   125   std::cout << "Result: bi_node_connected_components.eps" << std::endl;
   132   typedef ListUGraph Graph;
   129   typedef ListUGraph Graph;
   133   typedef Graph::Node Node;
   130   typedef Graph::Node Node;
   134   typedef Graph::UEdge UEdge;
   131   typedef Graph::UEdge UEdge;
   135 
   132 
   136   Graph graph;
   133   Graph graph;
   137   Graph::NodeMap<dim2::Point<double> > coords(graph);
   134   Graph::NodeMap<Point<double> > coords(graph);
   138 
   135 
   139   UGraphReader<Graph>("u_components.lgf", graph).
   136   UGraphReader<Graph>("u_components.lgf", graph).
   140     readNodeMap("coordinates_x", xMap(coords)).
   137     readNodeMap("coordinates_x", xMap(coords)).
   141     readNodeMap("coordinates_y", yMap(coords)).
   138     readNodeMap("coordinates_y", yMap(coords)).
   142     run();
   139     run();
   148   biEdgeConnectedComponents(graph, compMap);
   145   biEdgeConnectedComponents(graph, compMap);
   149   biEdgeConnectedCutEdges(graph, cutMap);
   146   biEdgeConnectedCutEdges(graph, cutMap);
   150 
   147 
   151   graphToEps(graph, "bi_edge_connected_components.eps").undirected().
   148   graphToEps(graph, "bi_edge_connected_components.eps").undirected().
   152     coords(coords).scaleToA4().enableParallel().
   149     coords(coords).scaleToA4().enableParallel().
   153     parEdgeDist(20.0).edgeWidthScale(2.0).nodeScale(20.0).
       
   154     nodeColors(composeMap(palette, compMap)).
   150     nodeColors(composeMap(palette, compMap)).
   155     edgeColors(composeMap(functorMap(&color), cutMap)).run();
   151     edgeColors(composeMap(functorMap(&color), cutMap)).run();
   156   
   152   
   157   std::cout << "Result: bi_edge_connected_components.eps" << std::endl;
   153   std::cout << "Result: bi_edge_connected_components.eps" << std::endl;
   158 }
   154 }
   161   typedef ListUGraph Graph;
   157   typedef ListUGraph Graph;
   162   typedef Graph::Node Node;
   158   typedef Graph::Node Node;
   163   typedef Graph::UEdge UEdge;
   159   typedef Graph::UEdge UEdge;
   164 
   160 
   165   Graph graph;
   161   Graph graph;
   166   Graph::NodeMap<dim2::Point<double> > coords(graph);
   162   Graph::NodeMap<Point<double> > coords(graph);
   167 
   163 
   168   UGraphReader<Graph>("partitions.lgf", graph).
   164   UGraphReader<Graph>("partitions.lgf", graph).
   169     readNodeMap("coordinates_x", xMap(coords)).
   165     readNodeMap("coordinates_x", xMap(coords)).
   170     readNodeMap("coordinates_y", yMap(coords)).
   166     readNodeMap("coordinates_y", yMap(coords)).
   171     run();
   167     run();
   175   Graph::NodeMap<bool> partMap(graph);
   171   Graph::NodeMap<bool> partMap(graph);
   176   bipartitePartitions(graph, partMap);
   172   bipartitePartitions(graph, partMap);
   177 
   173 
   178   graphToEps(graph, "bipartite_partitions.eps").undirected().
   174   graphToEps(graph, "bipartite_partitions.eps").undirected().
   179     coords(coords).scaleToA4().enableParallel().
   175     coords(coords).scaleToA4().enableParallel().
   180     parEdgeDist(20.0).edgeWidthScale(2.0).nodeScale(20.0).
       
   181     nodeColors(composeMap(functorMap(&color), partMap)).run();
   176     nodeColors(composeMap(functorMap(&color), partMap)).run();
   182   
   177   
   183   std::cout << "Result: bipartite_partitions.eps" << std::endl;
   178   std::cout << "Result: bipartite_partitions.eps" << std::endl;
   184 } 
   179 } 
   185 
   180