1 | import orngNetwork |
---|

2 | from orangeom import Pathfinder |
---|

3 | from pylab import * |
---|

4 | |
---|

5 | def myPlot(net, titleTxt=''): |
---|

6 | """ |
---|

7 | Displays the given network. |
---|

8 | """ |
---|

9 | figure() |
---|

10 | title(titleTxt) |
---|

11 | # Plot the edges |
---|

12 | for u, v in net.getEdges(): |
---|

13 | x1, y1 = net.coors[0][u], net.coors[1][u] |
---|

14 | x2, y2 = net.coors[0][v], net.coors[1][v] |
---|

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

16 | # Plot the nodes |
---|

17 | for u in range(net.nVertices): |
---|

18 | x, y = net.coors[0][u], net.coors[1][u] |
---|

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

20 | # Label |
---|

21 | text(x, y + 100, net.items[u][1]) |
---|

22 | |
---|

23 | # Read a demo network from a file |
---|

24 | net = orngNetwork.Network.read('demo.net') |
---|

25 | |
---|

26 | # Compute a layout for plotting |
---|

27 | netOp = orngNetwork.NetworkOptimization(net) |
---|

28 | netOp.fruchtermanReingold(100, 1000) |
---|

29 | |
---|

30 | # Plot the original |
---|

31 | myPlot(net, 'Original network') |
---|

32 | |
---|

33 | # Choose some parameters |
---|

34 | r, q = 1, 6 |
---|

35 | |
---|

36 | # Create a pathfinder instance |
---|

37 | pf = Pathfinder() |
---|

38 | |
---|

39 | # Simplify the network |
---|

40 | pf.simplify(r, q, net) |
---|

41 | |
---|

42 | # Plot the simplified network |
---|

43 | myPlot(net, 'Simplified network') |
---|

44 | show() |
---|