How to fix? ArgumentError: row indices I[k] must satisfy 1 <= I[k] <= m

Hi,

I’ve already ask this here. But, perhaps asking here is better.

When I try to build a graph from the following arrays of sources, destinations, and weights, the last line returns an error ERROR: ArgumentError: column indices J[k] must satisfy 1 = J[k] = n.
However, running the documentation example works just fine. Does anyone could see any issues with these three arrays?

using SimpleWeightedGraphs
using Graphs

s = [0,1,1,2,2,30,30,3,3,3,13,12,12,11,11,10]
e = [1,2,30,3,30,12,10,4,5,13,12,11,14,10,22,9]
w = [30,4.61,4.41,4.6,3.5,4.44,9.91,5.83,4,4,3,4,2,3.5,2,6.6]

g = SimpleWeightedDiGraph(s, e, w)

# returns
# ERROR: ArgumentError: column indices J[k] must satisfy 1 <= J[k] <= n

However, the following from GitHub page runs:

sources = [1,2,1]
destinations = [2,3,3]
weights = [0.5, 0.8, 2.0]
g = SimpleWeightedGraph(sources, destinations, weights)

# returns
{3, 3} undirected simple Int64 graph with Float64 weights

Thanks.

Julia uses 1-based indexing by default. So try initializing with s = [...] .+ 1 and e = [...] .+ 1

1 Like

Thanks a lot @Dan

1 Like