3
Dynamically draw shortest path in Watts-Stogatz small world graph using
7
__author__ = """Aric Hagberg (hagberg@lanl.gov)\n Katy Bold (kbold@princeton.edu"""
8
# Copyright (C) 2008 by
9
# Aric Hagberg <hagberg@lanl.gov>
10
# Dan Schult <dschult@colgate.edu>
11
# Pieter Swart <swart@lanl.gov>
12
# Distributed under the terms of the GNU Lesser General Public License
13
# http://www.gnu.org/copyleft/lesser.html
16
def vertex_callback(id):
21
s=nx.shortest_path(G,G.idnode[start],G.idnode[id])
23
epath=[(u,v,G.get_edge(u,v)) for u,v in e]
24
print >> sys.stderr, s
25
G.set_edge_attr(epath,style=wideyellow)
29
G.set_edge_attr(style=gray)
36
if __name__ == "__main__":
40
print "double click nodes to find shortest path"
41
G=nx.UbiGraph(nx.watts_strogatz_graph(50,4,0.1))
42
G.node_labels() # turn on node labels
43
G.set_edge_attr(color='#3f3f3f') # dark grey edges
44
gray=G.new_edge_style(color='#3f3f3f',width='2.0')
45
wideyellow=G.new_edge_style(color='#ffff00',width='6.0')
51
myPort = random.randint(20739,20999)
52
# Set up a callback for left double-clicks on vertices.
53
G.ubigraph.set_vertex_style_attribute(0, "callback_left_doubleclick",
54
"http://127.0.0.1:" + str(myPort) + "/vertex_callback")
56
# Now make an XMLRPC server to handle tha callbacks.
57
from SimpleXMLRPCServer import SimpleXMLRPCServer
59
server = SimpleXMLRPCServer(("localhost", myPort))
60
server.register_introspection_functions()
61
server.register_function(vertex_callback)
62
# Run the server's main loop
63
print "Listening for callbacks from ubigraph_server on port " + str(myPort)
64
server.serve_forever()