COIN-OR::LEMON - Graph Library

Changeset 1693:269f0cbfbcc8 in lemon-0.x


Ignore:
Timestamp:
09/30/05 15:15:28 (14 years ago)
Author:
Balazs Dezso
Branch:
default
Phase:
public
Convert:
svn:c9d7d8f5-90d6-0310-b91f-818b3a526b0e/lemon/trunk@2219
Message:

Improving GridGraph? and HyperCubeGraph?

Files:
1 added
3 edited

Legend:

Unmodified
Added
Removed
  • demo/grid_graph_demo.cc

    r1681 r1693  
    4242    bfs.run(start, stop) << std::endl;
    4343
    44   GridGraph::NodeMap<xy<double> > coord(graph);
    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));
     44  FilteredGraph::EdgeMap<bool> path(filtered, false);
    5245 
    5346  for (GridGraph::Node node = stop;
    5447       node != start; node = bfs.predNode(node)) {
    55     color[bfs.pred(node)] = Color(1.0, 0.0, 0.0);
     48    path[bfs.pred(node)] = true;
    5649  }
    5750 
     
    5952    title("Grid graph").
    6053    copyright("(C) 2005 LEMON Project").
    61     coords(coord).
     54    coords(scaleMap(indexMap(graph), 10)).
    6255    enableParallel().
    63     nodeScale(.45).
     56    nodeScale(0.5).
    6457    drawArrows().
    65     edgeColors(color).
     58    edgeColors(composeMap(ColorSet(), path)).
    6659    run();
    6760 
  • lemon/Makefile.am

    r1677 r1693  
    3535        graph_utils.h \
    3636        graph_to_eps.h \
     37        hypercube_graph.h \
    3738        invalid.h \
    3839        iterable_maps.h \
  • lemon/grid_graph.h

    r1680 r1693  
    2828#include <lemon/bits/undir_graph_extender.h>
    2929
     30#include <lemon/xy.h>
     31
     32///\ingroup graphs
     33///\file
     34///\brief GridGraph class.
     35
    3036namespace lemon {
    3137
     38  /// \brief Base graph for GridGraph.
     39  ///
     40  /// Base graph for grid graph. It describes some member functions
     41  /// which can be used in the GridGraph.
     42  ///
     43  /// \warning Always use the GridGraph instead of this.
     44  /// \see GridGraph
    3245  class GridGraphBase {
    3346
     
    357370  ///
    358371  /// \author Balazs Dezso
     372  /// \see GridGraphBase
    359373  class GridGraph : public ExtendedGridGraphBase {
    360374  public:
    361    
     375
     376    /// \brief Map to get the indices of the nodes as xy<int>.
     377    ///
     378    /// Map to get the indices of the nodes as xy<int>.
     379    class IndexMap {
     380    public:
     381      typedef True NeedCopy;
     382      /// \brief The key type of the map
     383      typedef GridGraph::Node Key;
     384      /// \brief The value type of the map
     385      typedef xy<int> Value;
     386
     387      /// \brief Constructor
     388      ///
     389      /// Constructor
     390      IndexMap(const GridGraph& _graph) : graph(_graph) {}
     391
     392      /// \brief The subscript operator
     393      ///
     394      /// The subscript operator.
     395      Value operator[](Key key) const {
     396        return xy<int>(graph.row(key), graph.col(key));
     397      }
     398
     399    private:
     400      const GridGraph& graph;
     401    };
     402
     403    /// \brief Map to get the row of the nodes.
     404    ///
     405    /// Map to get the row of the nodes.
     406    class RowMap {
     407    public:
     408      typedef True NeedCopy;
     409      /// \brief The key type of the map
     410      typedef GridGraph::Node Key;
     411      /// \brief The value type of the map
     412      typedef int Value;
     413
     414      /// \brief Constructor
     415      ///
     416      /// Constructor
     417      RowMap(const GridGraph& _graph) : graph(_graph) {}
     418
     419      /// \brief The subscript operator
     420      ///
     421      /// The subscript operator.
     422      Value operator[](Key key) const {
     423        return graph.row(key);
     424      }
     425
     426    private:
     427      const GridGraph& graph;
     428    };
     429
     430    /// \brief Map to get the column of the nodes.
     431    ///
     432    /// Map to get the column of the nodes.
     433    class ColMap {
     434    public:
     435      typedef True NeedCopy;
     436      /// \brief The key type of the map
     437      typedef GridGraph::Node Key;
     438      /// \brief The value type of the map
     439      typedef int Value;
     440
     441      /// \brief Constructor
     442      ///
     443      /// Constructor
     444      ColMap(const GridGraph& _graph) : graph(_graph) {}
     445
     446      /// \brief The subscript operator
     447      ///
     448      /// The subscript operator.
     449      Value operator[](Key key) const {
     450        return graph.col(key);
     451      }
     452
     453    private:
     454      const GridGraph& graph;
     455    };
     456
    362457    GridGraph(int n, int m) { construct(n, m); }
    363458   
     
    399494   
    400495  };
     496
     497  /// \brief Index map of the grid graph
     498  ///
     499  /// Just returns an IndexMap for the grid graph.
     500  GridGraph::IndexMap indexMap(const GridGraph& graph) {
     501    return GridGraph::IndexMap(graph);
     502  }
     503
     504  /// \brief Row map of the grid graph
     505  ///
     506  /// Just returns an RowMap for the grid graph.
     507  GridGraph::RowMap rowMap(const GridGraph& graph) {
     508    return GridGraph::RowMap(graph);
     509  }
     510
     511  /// \brief Coloumn map of the grid graph
     512  ///
     513  /// Just returns an ColMap for the grid graph.
     514  GridGraph::ColMap colMap(const GridGraph& graph) {
     515    return GridGraph::ColMap(graph);
     516  }
    401517}
    402518#endif
Note: See TracChangeset for help on using the changeset viewer.