第一题example:
>>> parse_network(‘net.dat’)
([0.4, 0.8, 0.6], [[0.0, 0.3, 0.25], [0.3, 0.0, 0.0], [0.25, 0.0, 0.0]])
>>> parse_network(‘net0.dat’)
([0.4, 0.3, 0.0, 0.6, 0.8, 0.1], [[0, 0.5, 0.1, 0.6, 0, 0], [0.5, 0, 0, 0, 0.2, 0], [0.1, 0, 0, 0, 0.25, 0], [0.6, 0, 0, 0, 0, 0], [0, 0.2, 0.25, 0, 0, 0.2], [0, 0, 0, 0, 0.2, 0]])
第二题example:
>>> nodes = [0.4, 0.8, 0.6, 0.4]
>>> links = [[0.0, 0.3, 0.25, 0.0], [0.3, 0.0, 0.95, 0.05], [0.25, 0.95, 0.0, 0.12], [0.0, 0.05, 0.12, 0.0]]
>>> outbreak(nodes, links, 1)
{0, 1, 2}
>>> outbreak(nodes, links, 0)
{0}
>>> nodes = [0.4, 0.3, 0.0, 0.6, 0.8, 0.1]
>>> links = [[0, 0.5, 0.1, 0.6, 0, 0], [0.5, 0, 0, 0, 0.2, 0], [0.1, 0, 0, 0, 0.25, 0], [0.6, 0, 0, 0, 0, 0], [0, 0.2, 0.25, 0, 0, 0.2], [0, 0, 0, 0, 0.2, 0]]
>>> outbreak(nodes, links, 4)
{2, 4, 5}
>>> outbreak(nodes, links, 0)
{0, 1, 2}
第三题example:
>>> links = [[0.0, 0.3, 0.25, 0.0], [0.3, 0.0, 0.95, 0.05], [0.25, 0.95, 0.0, 0.12], [0.0, 0.05, 0.12, 0.0]]
>>> find_central(links, 0.5)
2
>>> links = [[0, 0.5, 0.1, 0.6, 0, 0], [0.5, 0, 0, 0, 0.2, 0], [0.1, 0, 0, 0, 0.25, 0], [0.6, 0, 0, 0, 0, 0], [0, 0.2, 0.25, 0, 0, 0.2], [0, 0, 0, 0, 0.2, 0]]
>>> find_central(links, 0.5)
0
第四题example:
>>> nodes = [0.4, 0.8, 0.6, 0.4]
>>> links = [[0.0, 0.3, 0.25, 0.0], [0.3, 0.0, 0.95, 0.05], [0.25, 0.95, 0.0, 0.12], [0.0, 0.05, 0.12, 0.0]]
>>> find_central(links, 0.5)
2
>>> test_vaccinate(nodes, links, 0.5)
0.583333333333334
>>> nodes = [0.4, 0.3, 0.0, 0.6, 0.8, 0.1]
>>> links = [[0, 0.5, 0.1, 0.6, 0, 0], [0.5, 0, 0, 0, 0.2, 0], [0.1, 0, 0, 0, 0.25, 0], [0.6, 0, 0, 0, 0, 0], [0, 0.2, 0.25, 0, 0, 0.2], [0, 0, 0, 0, 0.2, 0]]
find_central(links, 0.5)
0
>>> test_vaccinate(nodes, links, 0.5)
0.7083333333333334