title: Why do NetworkX's approximations for vertex cover not include self-loop nodes?
body: <p>The definition of vertex cover according to <a href="https://networkx.org/documentation/stable/_modules/networkx/algorithms/approximation/vertex_cover.html" rel="nofollow noreferrer">networkx</a>:</p>
  <blockquote>
  <p>A vertex cover is a subset of nodes such that each edge in the graph is incident to at least one node in the subset.</p>
  </blockquote>
  <p>I tried the following code. However, the returned vertex cover set lacks the self-connected nodes. Why is that?</p>
  <pre><code>import networkx
  from networkx.algorithms.approximation import vertex_cover, min_weighted_dominating_set
  import numpy as np
  
  r=np.random.choice([0, 1], size=(1,5), p=[0.6, 0.4])
  a=r.T*r
  np.fill_diagonal(a, 1)
  
  import matplotlib.pyplot as plt
  plt.figure(figsize=(3, 3), dpi=100)
  
  G = networkx.from_numpy_array(a)
  networkx.draw(G,pos=networkx.random_layout(G),font_size=8, with_labels=True)
  plt.show()
  
  print(vertex_cover.min_weighted_vertex_cover(G))
  </code></pre>
  <p>will output:</p>
  <pre><code>{0}
  </code></pre>
  <p><a href="https://i.stack.imgur.com/fiNwE.png" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/fiNwE.png" alt="enter image description here" /></a></p>
  <p>As one can see from the <a href="https://networkx.org/documentation/stable/_modules/networkx/algorithms/approximation/vertex_cover.html" rel="nofollow noreferrer">link</a> to NetworkX's source code:</p>
  <pre><code>    for u, v in G.edges():
          min_cost = min(cost[u], cost[v])
          cost[u] -= min_cost
          cost[v] -= min_cost
      return {u for u, c in cost.items() if c == 0}
  </code></pre>
  <p>Because for a self-looped edges <code>u==v</code>, we will get <code>cost[u]!=0</code> for which the the condition <code>c==0</code> in <code>u for u, c in cost.items() if c == 0</code> does not apply.</p>