1 | import Orange.network |
---|

2 | |
---|

3 | from matplotlib import pyplot as plt |
---|

4 | |
---|

5 | # vertices are placed randomly in NetworkOptimization constructor |
---|

6 | network = Orange.network.NetworkOptimization() |
---|

7 | |
---|

8 | # read network from file |
---|

9 | net = Orange.network.Network.read("combination.net") |
---|

10 | |
---|

11 | components = net.get_connected_components() |
---|

12 | print "Connected components" |
---|

13 | print components |
---|

14 | print |
---|

15 | |
---|

16 | distribution = net.get_degree_distribution() |
---|

17 | print "Degree distribution" |
---|

18 | print distribution |
---|

19 | print |
---|

20 | |
---|

21 | degrees = net.get_degrees() |
---|

22 | print "Degrees" |
---|

23 | print degrees |
---|

24 | print |
---|

25 | |
---|

26 | hubs = net.get_hubs(3) |
---|

27 | print "Hubs" |
---|

28 | print hubs |
---|

29 | print |
---|

30 | |
---|

31 | path = net.get_shortest_paths(0, 2) |
---|

32 | print "Shortest path" |
---|

33 | print path |
---|

34 | print |
---|

35 | |
---|

36 | distance = net.get_distance(0, 2) |
---|

37 | print "Distance" |
---|

38 | print distance |
---|

39 | print |
---|

40 | |
---|

41 | diameter = net.get_diameter() |
---|

42 | print "Diameter" |
---|

43 | print diameter |
---|

44 | print |
---|

45 | |
---|

46 | subnet = Orange.network.Network(net.get_sub_graph([0, 1, 2, 3])) |
---|

47 | subNetOptimization = Orange.network.NetworkOptimization(subnet) |
---|

48 | subNetOptimization.fruchterman_reingold(100, 1000) |
---|

49 | |
---|

50 | # read all edges in subnetwork and plot a line |
---|

51 | for u, v in subnet.getEdges(): |
---|

52 | x1, y1 = subnet.coors[0][u], subnet.coors[1][u] |
---|

53 | x2, y2 = subnet.coors[0][v], subnet.coors[1][v] |
---|

54 | plt.plot([x1, x2], [y1, y2], 'b-') |
---|

55 | |
---|

56 | # read x and y coordinates to Python list |
---|

57 | x = [coordinate for coordinate in subnet.coors[0]] |
---|

58 | y = [coordinate for coordinate in subnet.coors[1]] |
---|

59 | |
---|

60 | # plot vertices of subnetwork |
---|

61 | plt.plot(x, y, 'ro') |
---|

62 | plt.savefig("network-graph-analysis.py.png") |
---|