COIN-OR::LEMON - Graph Library

Ticket #311: 311-5-eb8f6284708a.patch

File 311-5-eb8f6284708a.patch, 3.4 KB (added by Peter Kovacs, 15 years ago)
  • lemon/hypercube_graph.h

    # HG changeset patch
    # User Peter Kovacs <kpeter@inf.elte.hu>
    # Date 1250787869 -7200
    # Node ID eb8f6284708adfe6ee61f7d457b73cf59499d750
    # Parent  e8953d05253425a6d7ab6a41c0dd0c7ecf5af5d2
    Add a resize() function to HypercubeGraph (#311)
    just like the similar functions in other static graph structures,
    and extend the test files to check these functions.
    
    diff --git a/lemon/hypercube_graph.h b/lemon/hypercube_graph.h
    a b  
    287287  /// Two nodes are connected in the graph if and only if their indices
    288288  /// differ only on one position in the binary form.
    289289  /// This class is completely static and it needs constant memory space.
    290   /// Thus you can neither add nor delete nodes or edges.
     290  /// Thus you can neither add nor delete nodes or edges, however
     291  /// the structure can be resized using resize().
    291292  ///
    292293  /// This type fully conforms to the \ref concepts::Graph "Graph concept".
    293294  /// Most of its member functions and nested classes are documented
     
    306307    /// Constructs a hypercube graph with \c dim dimensions.
    307308    HypercubeGraph(int dim) { construct(dim); }
    308309
     310    /// \brief Resizes the graph
     311    ///
     312    /// This function resizes the graph. It fully destroys and
     313    /// rebuilds the structure, therefore the maps of the graph will be
     314    /// reallocated automatically and the previous values will be lost.
     315    void resize(int dim) {
     316      Parent::notifier(Arc()).clear();
     317      Parent::notifier(Edge()).clear();
     318      Parent::notifier(Node()).clear();
     319      construct(dim);
     320      Parent::notifier(Node()).build();
     321      Parent::notifier(Edge()).build();
     322      Parent::notifier(Arc()).build();
     323    }
     324
    309325    /// \brief The number of dimensions.
    310326    ///
    311327    /// Gives back the number of dimensions.
  • test/digraph_test.cc

    diff --git a/test/digraph_test.cc b/test/digraph_test.cc
    a b  
    378378void checkFullDigraph(int num) {
    379379  typedef FullDigraph Digraph;
    380380  DIGRAPH_TYPEDEFS(Digraph);
     381
    381382  Digraph G(num);
     383  check(G.nodeNum() == num && G.arcNum() == num * num, "Wrong size");
     384
     385  G.resize(num);
     386  check(G.nodeNum() == num && G.arcNum() == num * num, "Wrong size");
    382387
    383388  checkGraphNodeList(G, num);
    384389  checkGraphArcList(G, num * num);
  • test/graph_test.cc

    diff --git a/test/graph_test.cc b/test/graph_test.cc
    a b  
    270270  GRAPH_TYPEDEFS(Graph);
    271271
    272272  Graph G(num);
     273  check(G.nodeNum() == num && G.edgeNum() == num * (num - 1) / 2,
     274        "Wrong size");
     275
     276  G.resize(num);
     277  check(G.nodeNum() == num && G.edgeNum() == num * (num - 1) / 2,
     278        "Wrong size");
     279
    273280  checkGraphNodeList(G, num);
    274281  checkGraphEdgeList(G, num * (num - 1) / 2);
    275282
     
    414421  check(G.width() == width, "Wrong column number");
    415422  check(G.height() == height, "Wrong row number");
    416423
     424  G.resize(width, height);
     425  check(G.width() == width, "Wrong column number");
     426  check(G.height() == height, "Wrong row number");
     427
    417428  for (int i = 0; i < width; ++i) {
    418429    for (int j = 0; j < height; ++j) {
    419430      check(G.col(G(i, j)) == i, "Wrong column");
     
    489500  GRAPH_TYPEDEFS(HypercubeGraph);
    490501
    491502  HypercubeGraph G(dim);
     503  check(G.dimension() == dim, "Wrong dimension");
     504
     505  G.resize(dim);
     506  check(G.dimension() == dim, "Wrong dimension");
     507 
    492508  checkGraphNodeList(G, 1 << dim);
    493509  checkGraphEdgeList(G, dim * (1 << (dim-1)));
    494510  checkGraphArcList(G, dim * (1 << dim));