/usr/lib/python3/dist-packages/networkx/algorithms/approximation/tests/test_vertex_cover.py is in python3-networkx 1.8.1-0ubuntu3.
This file is owned by root:root, with mode 0o644.
The actual contents of the file can be viewed below.
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 | #!/usr/bin/env python
from nose.tools import *
import networkx as nx
from networkx.algorithms import approximation as a
class TestMWVC:
def test_min_vertex_cover(self):
# create a simple star graph
size = 50
sg = nx.star_graph(size)
cover = a.min_weighted_vertex_cover(sg)
assert_equals(2, len(cover))
for u, v in sg.edges_iter():
ok_((u in cover or v in cover), "Node node covered!")
wg = nx.Graph()
wg.add_node(0, weight=10)
wg.add_node(1, weight=1)
wg.add_node(2, weight=1)
wg.add_node(3, weight=1)
wg.add_node(4, weight=1)
wg.add_edge(0, 1)
wg.add_edge(0, 2)
wg.add_edge(0, 3)
wg.add_edge(0, 4)
wg.add_edge(1,2)
wg.add_edge(2,3)
wg.add_edge(3,4)
wg.add_edge(4,1)
cover = a.min_weighted_vertex_cover(wg, weight="weight")
csum = sum(wg.node[node]["weight"] for node in cover)
assert_equals(4, csum)
for u, v in wg.edges_iter():
ok_((u in cover or v in cover), "Node node covered!")
|