python - Adding nodes and edges to graph data structure dynamically in Matlab -


i create graphs in matlab follows:

g=sparse(5,5); g(2,3)=1; 

and on.

this works if have graph created in advance , given me figuratively have make adjacency matrix representing graph. have different kind of problem. have create graph scratch dynamically. have bunch of nodes, 500 nodes. have loop on these 500 nodes , if conditions satisfied put of nodes, 200 in graph structure. run loop on different pairs of nodes in pool of 200 nodes , if conditions satisfied, add edge.

i working in matlab , 1 method figure intialise adjacency matrix of size 500x500. , add edges ones pass criterion. undesirable. don't want include 500 points in graph structure @ all.

basically, want in matlab. in pseudo-codes in research papers, told:

add vertex v0 graph g. 

how can implement this?

and later pseudo-code tells

add edge (v0,v1) graph g. 

and lastly if there edge in graph (v0,v1) , told:

delete edge (v0,v1)  % not asking delete nodes. add node v. add edges (v0,v) , (v,v1) 

i want these steps efficiently. want able create graph dynamically. don't want create huge adjacency matrix , designate edges in it. want build graph step-by-step if needed. if can done in matlab please let me know. otherwise open python also.

have tried looking matlab's new-ish graph class? introduced in r2015b , has methods can use these steps efficiently. specifically, has addnode, addedge, rmedge, etc. can extract adjacency matrix graph object adjacency.

http://www.mathworks.com/help/matlab/graph-and-network-algorithms.html


Comments