COIN-OR::LEMON - Graph Library

Ticket #363: lemon_rev974_7ac852499256.patch

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

    # HG changeset patch
    # User gyorokp
    # Date 1269765634 -7200
    # Node ID 7ac85249925613d89547bccc26e977084be69e59
    # Parent  4e27249fd00f82efa5a0d0c2380427e346fc3e4a
    Fixed a few bugs in erase(Edge) (#363)
    
    diff -r 4e27249fd00f -r 7ac852499256 lemon/planar_graph.h
    a b  
    623623        Arc arc(faces[fr].first_arc);
    624624        wall_paint(arc,fl,arc);
    625625        erase(Face(fr));
    626       } else if ((arcs[n].next_out > -1 || arcs[n].prev_out > -1) &&
     626      } else {
     627        comp_split = true;
     628        if ((arcs[n].next_out > -1 || arcs[n].prev_out > -1) &&
    627629                 (arcs[n | 1].next_out > -1 || arcs[n | 1].prev_out > -1)) {
    628         comp_split = true;
    629         Arc arc(n);
    630         Arc ed = arc;
    631         ed.id ^= 1;
    632         turnRightF(arc);
    633         Face f = addFace();
    634         wall_paint(arc,f.id,ed);
    635         faces[f.id].first_arc = arc.id;
    636         turnRightF(ed);
    637         faces[fr].first_arc = ed.id;
     630          Arc arc(n);
     631          Arc ed = arc;
     632          ed.id ^= 1;
     633          turnRightF(arc);
     634          Face f = addFace();
     635          wall_paint(arc,f.id,ed);
     636          faces[f.id].first_arc = arc.id;
     637          turnRightF(ed);
     638          faces[fr].first_arc = ed.id;
     639        }
    638640      }
    639641
    640642      if (arcs[n].next_out != -1) {
     
    665667
    666668      if (comp_split) component_relabel(Node(arcs[n | 1].target),
    667669        addComponent());
    668       if (nodes[arcs[n].target].first_out == -1)
     670      if (nodes[arcs[n].target].first_out == -1 && nodes[arcs[n | 1].target].
     671              first_out == -1) {
    669672        nodes[arcs[n].target].outer_face = addFace().id;
    670       if (nodes[arcs[n | 1].target].first_out == -1)
     673        nodes[arcs[n | 1].target].outer_face = fr;
     674      } else if (nodes[arcs[n].target].first_out == -1)
     675        nodes[arcs[n].target].outer_face = addFace().id;
     676      else if (nodes[arcs[n | 1].target].first_out == -1)
    671677        nodes[arcs[n | 1].target].outer_face = addFace().id;
    672678
    673679    }
     
    10831089
    10841090  };
    10851091
     1092  // Face counting:
     1093
     1094  namespace _core_bits {
     1095
     1096    template <typename Graph, typename Enable = void>
     1097    struct CountFacesSelector {
     1098      static int count(const Graph &g) {
     1099        return countItems<Graph, typename Graph::Face>(g);
     1100      }
     1101    };
     1102
     1103    template <typename Graph>
     1104    struct CountFacesSelector<
     1105      Graph, typename
     1106      enable_if<typename Graph::FaceNumTag, void>::type>
     1107    {
     1108      static int count(const Graph &g) {
     1109        return g.faceNum();
     1110      }
     1111    };
     1112  }
     1113
     1114  /// \brief Function to count the faces in the graph.
     1115  ///
     1116  /// This function counts the faces in the graph.
     1117  /// The complexity of the function is <em>O</em>(<em>n</em>), but for some
     1118  /// graph structures it is specialized to run in <em>O</em>(1).
     1119  ///
     1120  /// \note If the graph contains a \c faceNum() member function and a
     1121  /// \c FaceNumTag tag then this function calls directly the member
     1122  /// function to query the cardinality of the face set.
     1123  template <typename Graph>
     1124  inline int countFaces(const Graph& g) {
     1125    return _core_bits::CountFacesSelector<Graph>::count(g);
     1126  }
     1127
     1128  template <typename Graph, typename DegIt>
     1129  inline int countFaceDegree(const Graph& _g, const typename Graph::Face& _n) {
     1130    int num = 0;
     1131    for (DegIt it(_g, _n); it != INVALID; ++it) {
     1132      ++num;
     1133    }
     1134    return num;
     1135  }
     1136  /// \brief Function to count the number of the boundary arcs of face \c f.
     1137  ///
     1138  /// This function counts the number of the boundary arcs of face \c f
     1139  /// in the undirected graph \c g.
     1140  template <typename Graph>
     1141  inline int countBoundaryArcs(const Graph& g,  const typename Graph::Face& f) {
     1142    return countFaceDegree<Graph, typename Graph::CwBoundaryArcIt>(g, f);
     1143  }
     1144
     1145
    10861146  template <typename GR, typename Enable = void>
    10871147  struct FaceNotifierIndicator {
    10881148    typedef InvalidType Type;
     
    14741534
    14751535    typedef Parent::OutArcIt IncEdgeIt;
    14761536
    1477     /// \brief Add a new node to the graph.
    1478     ///
    1479     /// This function adds a new node to the graph. A new outer face is created
    1480     /// for the node.
    1481     /// \return The new node.
    1482     Node addNode() {
    1483       Node n = Parent::addNode();
    1484       notifier(Face()).add(outerFace(n));
    1485       return n;
    1486     }
    1487 
    14881537  protected:
    14891538    void edge_add_notify(Edge edge) {
    14901539      notifier(Edge()).add(edge);
     
    15031552    }
    15041553
    15051554  public:
     1555    /// \brief Add a new node to the graph.
     1556    ///
     1557    /// This function adds a new node to the graph. A new outer face is created
     1558    /// for the node.
     1559    /// \return The new node.
     1560    Node addNode() {
     1561      Node n = PlanarGraphBase::addNode();
     1562      notifier(Node()).add(n);
     1563      notifier(Face()).add(outerFace(n));
     1564      return n;
     1565    }
     1566
    15061567    /// \brief Add a new edge to the graph.
    15071568    ///
    15081569    /// This function adds a new edge to the graph between nodes