python - Networkx: find way according to .dot file attribute -
i'm working digraph defined in dot language using networkx. need achieve this:
x = networkx.read_dot('_t.dot') #loads dotfile def navigate_through_model(model, type): #model model, type -> string of desired 'comment' ..... return path if \__target\__== '\__main\__': print navigate_through_model(x, 'regression') # need return path, going through nodes comment == 'regression' (it can other attribute, comment question)
and i'm kind lost in :(
any appreciated.
ok found (after sleep) can use weight of edges achieve same result. solution easy.. set lowest weight 'regression' path , generate shortest path.
networkx(x, 'start', 'end', weight='weight')
in order have edit networkx/algorithms/shortest_paths/weighted.py
there kind of bug on row 342.
vw_dist = dist[v] + edgedata.get(weight, 1)
you have change to:
vw_dist = dist[v] + float(edgedata.get(weight, 1)) #if want use floating number or int use integers
Comments
Post a Comment