COIN-OR::LEMON - Graph Library

Ticket #363: lemon_rev975_c8e6952a00eb.patch

File lemon_rev975_c8e6952a00eb.patch, 5.1 KB (added by gyorokp, 9 years ago)
  • lemon/planar_graph.h

    # HG changeset patch
    # User gyorokp
    # Date 1269772785 -7200
    # Node ID c8e6952a00ebefcb7d775719f45101faebf81ea4
    # Parent  7ac85249925613d89547bccc26e977084be69e59
    Added tests for split(Node) and contract(Edge) (#363)
    
    diff -r 7ac852499256 -r c8e6952a00eb lemon/planar_graph.h
    a b  
    847847      }
    848848      int fr = arcs[a.id | 1].left_face;
    849849      if ((faces[fr].first_arc | 1) == a.id | 1) {
    850         Arc b = a;
     850        Arc b(a.id | 1);
    851851        turnRightF(b);
    852852        faces[fr].first_arc = b.id;
    853853      }
     
    17111711    /// its incident edges, they are joined to the other node.
    17121712    /// \c e will be deleted.
    17131713    ///
     1714    /// The deleted node is v(e) unless the degree of v(e) is higher than 1 and
     1715    /// the degree of u(e) is 1, in which case u(e) is deleted.
     1716    ///
    17141717    /// \note All edge and arc iterators whose base node is
    17151718    /// the deleted one are invalidated.
    17161719    /// Moreover all iterators referencing the removed node or
     
    17231726    void contract(Edge e) {
    17241727      Node n1 = u(e);
    17251728      Node n2 = v(e);
     1729      if (n1 == n2) return;
    17261730      Node nd;
    17271731      bool simple;
    17281732      inner_contract1(n1,n2,nd,simple);
  • test/planar_graph_test.cc

    diff -r 7ac852499256 -r c8e6952a00eb test/planar_graph_test.cc
    a b  
    131131}
    132132
    133133template <class Graph>
     134void checkGraphNodeSplit() {
     135  TEMPLATE_GRAPH_TYPEDEFS(Graph);
     136
     137    Graph G;
     138    Node n0 = G.addNode(),
     139         n1 = G.addNode(),
     140         n2 = G.addNode(),
     141         n3 = G.addNode(),
     142         n4 = G.addNode();
     143    Edge a0 = G.addEdge(n4,n3,INVALID,INVALID),
     144         a1 = G.addEdge(n4,n0,a0,INVALID),
     145         a2 = G.addEdge(n1,n4,INVALID,a1),
     146         a3 = G.addEdge(n4,n2,a2,INVALID),
     147         a4 = G.addEdge(n2,n3,a3,a0);
     148
     149    checkGraphNodeList(G, 5);
     150    checkGraphEdgeList(G, 5);
     151    checkGraphArcList(G, 10);
     152    checkGraphFaceList(G, 2);
     153
     154    checkGraphIncEdgeArcLists(G, n0, 1);
     155    checkGraphIncEdgeArcLists(G, n1, 1);
     156    checkGraphIncEdgeArcLists(G, n2, 2);
     157    checkGraphIncEdgeArcLists(G, n3, 2);
     158    checkGraphIncEdgeArcLists(G, n4, 4);
     159
     160    checkGraphBoundaryArcList(G, G.leftFace(G.direct(a0,false)), 3);
     161    checkGraphBoundaryArcList(G, G.leftFace(G.direct(a0,true)), 7);
     162
     163    Node n5 = G.split(n4,a3,a1,true);
     164
     165    checkGraphNodeList(G, 6);
     166    checkGraphEdgeList(G, 6);
     167    checkGraphArcList(G, 12);
     168    checkGraphFaceList(G, 2);
     169
     170    checkGraphIncEdgeArcLists(G, n0, 1);
     171    checkGraphIncEdgeArcLists(G, n1, 1);
     172    checkGraphIncEdgeArcLists(G, n2, 2);
     173    checkGraphIncEdgeArcLists(G, n3, 2);
     174    checkGraphIncEdgeArcLists(G, n4, 3);
     175    checkGraphIncEdgeArcLists(G, n5, 3);
     176
     177    checkGraphBoundaryArcList(G, G.leftFace(G.direct(a0,false)), 3);
     178    checkGraphBoundaryArcList(G, G.leftFace(G.direct(a0,true)), 9);
     179}
     180
     181template <class Graph>
     182void checkGraphContract() {
     183  TEMPLATE_GRAPH_TYPEDEFS(Graph);
     184
     185    Graph G;
     186    Node n0 = G.addNode(),
     187         n1 = G.addNode(),
     188         n2 = G.addNode(),
     189         n3 = G.addNode();
     190    Edge a0 = G.addEdge(n0,n1,INVALID,INVALID),
     191         a1 = G.addEdge(n0,n1,a0,a0),
     192         a2 = G.addEdge(n0,n1,a1,a0),
     193         a3 = G.addEdge(n0,n2,a1,INVALID),
     194         a4 = G.addEdge(n0,n3,a3,INVALID),
     195         a5 = G.addEdge(n2,n1,a3,a2),
     196         a6 = G.addEdge(n3,n1,a4,a2);
     197
     198    checkGraphNodeList(G, 4);
     199    checkGraphEdgeList(G, 7);
     200    checkGraphArcList(G, 14);
     201    checkGraphFaceList(G, 5);
     202
     203    checkGraphIncEdgeArcLists(G, n0, 5);
     204    checkGraphIncEdgeArcLists(G, n1, 5);
     205    checkGraphIncEdgeArcLists(G, n2, 2);
     206    checkGraphIncEdgeArcLists(G, n3, 2);
     207
     208    checkGraphBoundaryArcList(G, G.leftFace(G.direct(a0,false)), 2);
     209    checkGraphBoundaryArcList(G, G.leftFace(G.direct(a0,true)), 2);
     210    checkGraphBoundaryArcList(G, G.leftFace(G.direct(a1,true)), 3);
     211    checkGraphBoundaryArcList(G, G.leftFace(G.direct(a2,false)), 3);
     212    checkGraphBoundaryArcList(G, G.leftFace(G.direct(a3,true)), 4);
     213
     214    G.contract(a0);
     215
     216    checkGraphNodeList(G, 3);
     217    checkGraphEdgeList(G, 6);
     218    checkGraphArcList(G, 12);
     219    checkGraphFaceList(G, 5);
     220
     221    checkGraphIncEdgeArcLists(G, n0, 8);
     222    checkGraphIncEdgeArcLists(G, n2, 2);
     223    checkGraphIncEdgeArcLists(G, n3, 2);
     224
     225    checkGraphBoundaryArcList(G, G.leftFace(G.direct(a1,false)), 1);
     226    checkGraphBoundaryArcList(G, G.leftFace(G.direct(a2,true)), 1);
     227    checkGraphBoundaryArcList(G, G.leftFace(G.direct(a1,true)), 3);
     228    checkGraphBoundaryArcList(G, G.leftFace(G.direct(a2,false)), 3);
     229    checkGraphBoundaryArcList(G, G.leftFace(G.direct(a3,true)), 4);
     230
     231}
     232
     233template <class Graph>
    134234void checkGraphErase() {
    135235  TEMPLATE_GRAPH_TYPEDEFS(Graph);
    136236
     
    320420  { // Checking PlanarGraph
    321421    checkGraphBuild<PlanarGraph>();
    322422    checkGraphArcSplit<PlanarGraph>();
     423    checkGraphNodeSplit<PlanarGraph>();
     424    checkGraphContract<PlanarGraph>();
    323425    checkGraphErase<PlanarGraph>();
    324426    checkGraphSnapshot<PlanarGraph>();
    325427    checkGraphValidityErase<PlanarGraph>();