Hello,
I am trying to move away from the R package iGraph to LightGraphs.jl
but am having difficulty.
I have a food web where each species is a node and a link connects it to another species (node) - this is translated into a binary array. My end goal is to have an array with link distances (how many link are between two species). For example, the distance between species 1 and species 4 is 2.
In R the code is
library(igraph)
one.g.mat = matrix(c(0,0,0,0,1,0,0,0,1,0,0,0,0,1,0,0,0,0,0,1,0,0,0,0,0), nrow = 5, byrow = TRUE)
one.g = graph_from_adjacency_matrix(one.g.mat, mode = "undirected")
dists = shortest.paths(one.g)
#output - the distances between each species and the other species
# [,1] [,2] [,3] [,4] [,5]
#[1,] 0 3 3 2 1
#[2,] 3 0 2 1 2
#[3,] 3 2 0 1 2
#[4,] 2 1 1 0 1
#[5,] 1 2 2 1 0
In Julia I am struggling to do something similar. I assume I need to use a shortest path algorithm, but I am unable to get it to work.
using LightGraphs
one.g.mat= [0 0 0 0 1;
0 0 0 1 0;
0 0 0 1 0;
0 0 0 0 1;
0 0 0 0 0]
test_graph = DiGraph(one.g.mat)
a = adjacency_matrix(test_graph)
a_star(a, s, t[, distmx][, heuristic]) # syntax: unexpected ","
dijkstra_shortest_paths(a, srcs, distmx=weights(a)) # MethodError: no method matching weights(::SparseArrays.SparseMatrixCSC{Int64, Int64})
Can someone help me?