shortest path in r (total cost and which steps) ideally with Igraph - simple mistake -


i have table has in first column starting node, ending node, , cost move in direction. 1 directional, can't move backwards. these combinations. seems i'm making obvious mistake..

mygraph = structure(list(v1 = c(1l, 1l, 2l, 2l, 2l, 3l, 3l, 4l, 4l, 4l,  5l, 5l, 6l, 7l, 8l, 9l), v2 = c(3l, 4l, 3l, 4l, 5l, 7l, 6l, 6l,  8l, 9l, 7l, 8l, 10l, 10l, 10l, 10l), v3 = c(3l, 2l, 4l, 2l, 4l,  2l, 3l, 4l, 2l, 5l, 2l, 2l, 3l, 4l, 2l, 3l)), .names = c("v1",  "v2", "v3"), class = "data.frame", row.names = c(na, -16l))  names(mygraph)=c('start','end','cost')  library(igraph) mygraph = graph.data.frame(mygraph, directed=t) # think right? plot(mygraph) #looks wrong??? help=get.shortest.paths(mygraph,1,10)   #i'm doing wrong want see route , total cost of going node 1-10 

if change last term 'cost' in following line weight, generate right solution.

names(mygraph) <- c('start', 'end', 'weight') 

this happens because function get.shortest.paths() uses attribute weight (not cost) costs of edges.


Comments

Popular posts from this blog

asp.net mvc - SSO between MVCForum and Umbraco7 -

Python Tkinter keyboard using bind -

ubuntu - Selenium Node Not Connecting to Hub, Not Opening Port -