COIN-OR::LEMON - Graph Library

Ticket #363: lemon_rev982_ece0de9a63f8.patch

File lemon_rev982_ece0de9a63f8.patch, 6.4 KB (added by gyorokp, 14 years ago)
  • lemon/planar_graph.h

    # HG changeset patch
    # User gyorokp
    # Date 1270898683 -7200
    # Node ID ece0de9a63f86df029e092cdcf0b8949606992bc
    # Parent  873b8d0104e73ab66cacb90ff7e6e2de6122eb81
    CommonFacesIt, CommonNodesIt fixes (#363)
    
    diff -r 873b8d0104e7 -r ece0de9a63f8 lemon/planar_graph.h
    a b  
    12841284  class CommonFacesIt : public Face {
    12851285      const Graph* _graph;
    12861286      const Node _n1, _n2;
    1287       Arc _i2;
    1288       std::set<Face> _f1;
     1287      std::set<Face> _f1, _f2;
     1288      typename std::set<Face>::const_iterator _fi2;
    12891289    public:
    12901290
    12911291      CommonFacesIt() {}
     
    12931293      CommonFacesIt(Invalid i) : Face(i) { }
    12941294
    12951295      explicit CommonFacesIt(const Graph& graph, Node n1, Node n2) : _graph(
    1296         &graph), _n1(n1), _n2(n2), _i2(), _f1(){
     1296        &graph), _n1(n1), _n2(n2), _f1(), _f2(){
    12971297        Arc _i1;
    12981298        _graph->firstOut(_i1,_n1);
    12991299        while (_i1 != INVALID) {
    13001300          _f1.insert(_graph->leftFace(_i1));
    13011301          _graph->nextOut(_i1);
    13021302        }
     1303        Arc _i2;
    13031304        _graph->firstOut(_i2,_n2);
    1304         _graph->firstOut(_i2,_n2);
    1305         while (_i2 != INVALID && _f1.count(_graph->leftFace(_i2)) == 0)
     1305        while (_i2 != INVALID) {
     1306          _f2.insert(_graph->leftFace(_i2));
    13061307          _graph->nextOut(_i2);
    1307         static_cast<Face&>(*this) = (_i2 != INVALID)?_graph->leftFace(_i2):
    1308           INVALID;
     1308        }
     1309
     1310        _fi2 = _f2.begin();
     1311        while (_fi2 != _f2.end() && _f1.count(*_fi2) == 0)
     1312          ++_fi2;
     1313        static_cast<Face&>(*this) = (_fi2 != _f2.end())?*_fi2:INVALID;
    13091314      }
    13101315
    13111316      CommonFacesIt& operator++() {
    1312         _graph->nextOut(_i2);
    1313         while (_i2 != INVALID && _f1.count(_graph->leftFace(_i2)) == 0)
    1314           _graph->nextOut(_i2);
    1315         static_cast<Face&>(*this) = (_i2 != INVALID)?_graph->leftFace(_i2):
    1316           INVALID;
     1317        ++_fi2;
     1318        while (_fi2 != _f2.end() && _f1.count(*_fi2) == 0)
     1319          ++_fi2;
     1320        static_cast<Face&>(*this) = (_fi2 != _f2.end())?*_fi2:INVALID;
    13171321        return *this;
    13181322      }
    13191323
     
    13251329  class CommonNodesIt : public Node {
    13261330      const Graph* _graph;
    13271331      const Face _f1, _f2;
    1328       Arc _i2;
    1329       std::set<Node> _ns;
     1332      std::set<Node> _ns1,_ns2;
     1333      typename std::set<Node>::const_iterator _ni2;
    13301334    public:
    13311335
    13321336      CommonNodesIt() {}
     
    13341338      CommonNodesIt(Invalid i) : Face(i) { }
    13351339
    13361340      explicit CommonNodesIt(const Graph& graph, Face f1, Face f2) : _graph(
    1337         &graph), _f1(f1), _f2(f2), _i2(), _ns(){
     1341        &graph), _f1(f1), _f2(f2), _ns1(), _ns2(){
    13381342        Arc _i1;
    13391343        _graph->firstCwF(_i1,_f1);
    13401344        while (_i1 != INVALID) {
    1341           _ns.insert(_graph->source(_i1));
     1345          _ns1.insert(_graph->source(_i1));
    13421346          _graph->nextCwF(_i1);
    13431347        }
     1348        Arc _i2;
     1349        _graph->firstCwF(_i2,_f2);
     1350        while (_i2 != INVALID) {
     1351          _ns2.insert(_graph->source(_i2));
     1352          _graph->nextCwF(_i2);
     1353        }
    13441354
    1345         _graph->firstCwF(_i2,_f2);
    1346         while (_i2 != INVALID && _ns.count(_graph->source(_i2)) == 0)
    1347           _graph->nextCwF(_i2);
    1348         static_cast<Node&>(*this) = (_i2 != INVALID)?_graph->source(_i2):
    1349           INVALID;
     1355        _ni2 = _ns2.begin();
     1356        while (_ni2 != _ns2.end() && _ns1.count(*_ni2) == 0)
     1357          ++_ni2;
     1358        static_cast<Node&>(*this) = (_ni2 != _ns2.end())?*_ni2:INVALID;
    13501359      }
    13511360
    13521361      CommonNodesIt& operator++() {
    1353         _graph->nextCwF(_i2);
    1354         while (_i2 != INVALID && _ns.count(_graph->source(_i2)) == 0)
    1355           _graph->nextCwF(_i2);
    1356         static_cast<Node&>(*this) = (_i2 != INVALID)?_graph->source(_i2):
    1357           INVALID;
     1362        ++_ni2;
     1363        while (_ni2 != _ns2.end() && _ns1.count(*_ni2) == 0)
     1364          ++_ni2;
     1365        static_cast<Node&>(*this) = (_ni2 != _ns2.end())?*_ni2:INVALID;
    13581366        return *this;
    13591367      }
    13601368
  • test/planar_graph_test.cc

    diff -r 873b8d0104e7 -r ece0de9a63f8 test/planar_graph_test.cc
    a b  
    228228    checkGraphBoundaryArcList(G, G.leftFace(G.direct(a2,false)), 3);
    229229    checkGraphBoundaryArcList(G, G.leftFace(G.direct(a3,true)), 4);
    230230
     231    checkGraphCommonFaceList(G, n0, n2, 2);
     232    checkGraphCommonFaceList(G, n0, n3, 2);
     233    checkGraphCommonFaceList(G, n2, n3, 1);
     234
     235    checkGraphCommonNodeList(G, G.leftFace(G.direct(a3,true)), G.leftFace(G.
     236            direct(a3,false)), 2);
     237    checkGraphCommonNodeList(G, G.leftFace(G.direct(a1,false)), G.leftFace(G.
     238            direct(a2,true)), 1);
     239
    231240}
    232241
    233242template <class Graph>
  • test/planar_graph_test.h

    diff -r 873b8d0104e7 -r ece0de9a63f8 test/planar_graph_test.h
    a b  
    141141  void checkGraphBoundaryArcList(const Graph &G, typename Graph::Face n, int
    142142    cnt)
    143143  {
    144 //    std::cout << G.id(n) << ' ';
    145 //    int alma = countBoundaryArcs(G,n);
    146 //    std::cout << alma << ':';
    147144    typename Graph::CwBoundaryArcIt e(G,n);
    148145    for(int i=0;i<cnt;i++) {
    149 //      std::cout << ',' << G.id(e);
    150146      check(e!=INVALID,"Wrong CwBoundaryArc list linking.");
    151147      check(n==G.w1(e) || n==G.w2(e),"Wrong CwBoundaryArc list linking.");
    152148      ++e;
    153149    }
    154 //    std::cout << std::endl;
    155150    check(e==INVALID,"Wrong BoundaryArc list linking.");
    156151    check(countBoundaryArcs(G,n)==cnt,"Wrong IncEdge number.");
    157152  }
     
    186181    check(2 * cnt == i, "Wrong iterator.");
    187182  }
    188183
     184  template<class Graph>
     185  void checkGraphCommonNodeList(const Graph &G, typename Graph::Face f1,
     186      typename Graph::Face f2, int cnt)
     187  {
     188    typename Graph::CommonNodesIt e(G,f1,f2);
     189    for(int i=0;i<cnt;i++) {
     190      check(e!=INVALID,"Wrong CommonNodeIt.");
     191      ++e;
     192    }
     193    check(e==INVALID,"Wrong CommonNodeIt.");
     194  }
     195
     196  template<class Graph>
     197  void checkGraphCommonFaceList(const Graph &G, typename Graph::Node n1,
     198      typename Graph::Node n2, int cnt)
     199  {
     200    typename Graph::CommonFacesIt e(G,n1,n2);
     201    for(int i=0;i<cnt;i++) {
     202      check(e!=INVALID,"Wrong CommonNodeIt.");
     203      ++e;
     204    }
     205    check(e==INVALID,"Wrong CommonNodeIt.");
     206  }
     207
    189208  template <typename Graph>
    190209  void checkArcDirections(const Graph& G) {
    191210    for (typename Graph::ArcIt a(G); a != INVALID; ++a) {