COIN-OR::LEMON - Graph Library

Ticket #439: 792b426a35f0.patch

File 792b426a35f0.patch, 2.2 KB (added by Balazs Dezso, 6 years ago)
  • lemon/connectivity.h

    # HG changeset patch
    # User Balazs Dezso <deba@google.com>
    # Date 1375995370 -7200
    # Node ID 792b426a35f09fd812e47cad01461e3f7aea6e1e
    # Parent  4000b7ef4e0104ecb1801bf6cf116ca5dc32c056
    Fix biNodeConnected() function
    
    diff -r 4000b7ef4e01 -r 792b426a35f0 lemon/connectivity.h
    a b  
    745745  /// \brief Check whether an undirected graph is bi-node-connected.
    746746  ///
    747747  /// This function checks whether the given undirected graph is
    748   /// bi-node-connected, i.e. any two edges are on same circle.
     748  /// bi-node-connected, i.e. a connected graph without articulation
     749  /// node.
    749750  ///
    750751  /// \return \c true if the graph bi-node-connected.
    751752  /// \note By definition, the empty graph is bi-node-connected.
     
    753754  /// \see countBiNodeConnectedComponents(), biNodeConnectedComponents()
    754755  template <typename Graph>
    755756  bool biNodeConnected(const Graph& graph) {
     757    bool hasNonIsolated = false, hasIsolated = false;
     758    for (typename Graph::NodeIt n(graph); n != INVALID; ++n) {
     759      if (typename Graph::OutArcIt(graph, n) == INVALID) {
     760        if (hasIsolated || hasNonIsolated) {
     761          return false;
     762        } else {
     763          hasIsolated = true;
     764        }
     765      } else {
     766        if (hasIsolated) {
     767          return false;
     768        } else {
     769          hasNonIsolated = true;
     770        }
     771      }
     772    }
    756773    return countBiNodeConnectedComponents(graph) <= 1;
    757774  }
    758775
  • test/connectivity_test.cc

    diff -r 4000b7ef4e01 -r 792b426a35f0 test/connectivity_test.cc
    a b  
    9999  }
    100100
    101101  {
     102    ListGraph g;
     103    ListGraph::NodeMap<bool> map(g);
     104
     105    ListGraph::Node n1 = g.addNode();
     106    ListGraph::Node n2 = g.addNode();
     107
     108    ListGraph::Edge e1 = g.addEdge(n1, n2);
     109    ::lemon::ignore_unused_variable_warning(e1);
     110    check(biNodeConnected(g), "Graph is bi-node-connected");
     111
     112    ListGraph::Node n3 = g.addNode();
     113    ::lemon::ignore_unused_variable_warning(n3);
     114    check(!biNodeConnected(g), "Graph is not bi-node-connected");
     115  }
     116
     117
     118  {
    102119    Digraph d;
    103120    Digraph::NodeMap<int> order(d);
    104121    Graph g(d);