# source:orange/Orange/testing/regression/tests_20/reference_pathfinder.py@9952:986e9cd806f4

Revision 9952:986e9cd806f4, 1022 bytes checked in by Miha Stajdohar <miha.stajdohar@…>, 2 years ago (diff)

Tests moved and renamed from orange 20.

Line
1import orngNetwork
2from orangeom import Pathfinder
3from pylab import *
4
5def 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
24net = orngNetwork.Network.read('demo.net')
25
26# Compute a layout for plotting
27netOp = orngNetwork.NetworkOptimization(net)
28netOp.fruchtermanReingold(100, 1000)
29
30# Plot the original
31myPlot(net, 'Original network')
32
33# Choose some parameters
34r, q = 1, 6
35
36# Create a pathfinder instance
37pf = Pathfinder()
38
39# Simplify the network
40pf.simplify(r, q, net)
41
42# Plot the simplified network
43myPlot(net, 'Simplified network')
44show()
Note: See TracBrowser for help on using the repository browser.