1 | import orange |
---|

2 | from orngNetwork import Network |
---|

3 | from orngNetwork import NetworkOptimization |
---|

4 | from pylab import * |
---|

5 | |
---|

6 | |
---|

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

8 | network = NetworkOptimization() |
---|

9 | |
---|

10 | # read network from file |
---|

11 | net = Network.read("combination.net") |
---|

12 | |
---|

13 | components = net.getConnectedComponents() |
---|

14 | print "Connected components" |
---|

15 | print components |
---|

16 | print |
---|

17 | |
---|

18 | distribution = net.getDegreeDistribution() |
---|

19 | print "Degree distribution" |
---|

20 | print distribution |
---|

21 | print |
---|

22 | |
---|

23 | degrees = net.getDegrees() |
---|

24 | print "Degrees" |
---|

25 | print degrees |
---|

26 | print |
---|

27 | |
---|

28 | hubs = net.getHubs(3) |
---|

29 | print "Hubs" |
---|

30 | print hubs |
---|

31 | print |
---|

32 | |
---|

33 | path = net.getShortestPaths(0, 2) |
---|

34 | print "Shortest path" |
---|

35 | print path |
---|

36 | print |
---|

37 | |
---|

38 | distance = net.getDistance(0, 2) |
---|

39 | print "Distance" |
---|

40 | print distance |
---|

41 | print |
---|

42 | |
---|

43 | diameter = net.getDiameter() |
---|

44 | print "Diameter" |
---|

45 | print diameter |
---|

46 | print |
---|

47 | |
---|

48 | subnet = Network(net.getSubGraph([0, 1, 2, 3])) |
---|

49 | subNetOptimization = NetworkOptimization(subnet) |
---|

50 | subNetOptimization.fruchtermanReingold(100, 1000) |
---|

51 | |
---|

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

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

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

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

56 | plot([x1, x2], [y1, y2], 'b-') |
---|

57 | |
---|

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

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

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

61 | |
---|

62 | # plot vertices of subnetwork |
---|

63 | plot(x, y, 'ro') |
---|

64 | show() |
---|