python - Is it possible to add a new node to an existing edge using Networkx -


i trying implement game of sprouts using python , networkx library. idea of game start 2 vertices. player draws edge 1 vertex another. new node placed on newly created edge. rest of game's details aren't necessary placed link @ bottom further explain it. currently, first create node, add edge starting node new node. next, add edge new node terminating node. question is, there easier way of accomplishing this? instance, drawing edge first , placing new node on edge.

http://nrich.maths.org/2413

it seems can use add_path() function.

example:

>>> g = nx.graph() >>> g.add_nodes_from( [0,1] ) >>> g.nodes() [0, 1] # have 2 nodes, 0 edges. # user clicks 2 vertices, 0 , 1. # add 1 more node first. >>> g.add_node(2) # add new edges >>> g.add_path([0,2,1]) >>> g.nodes() [0, 1, 2] >>> g.edges() [(0, 2), (1, 2)] 

Comments

Popular posts from this blog

OpenCV OpenCL: Convert Mat to Bitmap in JNI Layer for Android -

android - org.xmlpull.v1.XmlPullParserException: expected: START_TAG {http://schemas.xmlsoap.org/soap/envelope/}Envelope -

python - How to remove the Xframe Options header in django? -