LightGraphs.jl/Graphs.jl only values from half the cartesian plane is needed

Hi, this is a continuation of finding link distances between species in a food web. It’s been a few months so I am starting a new topic. I can find distances between species, but when I want to randomly choose a species pair with a link distance of for example 3, LightGraphs gives me four options which are actually 2 options (because the matrix is diagonally mirrored).

The option of species 1 and species 3 is the same as species 3 and species 1. Is there a way to specify I only want pairings from half the matrix, or to state that (1,3) is the same as (3,1)?

Example code

using LightGraphs

foodWeb2 = [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(foodWeb2)
test_graph2 = SimpleGraph(test_graph) # LD is link_distance
test_graph2_results = floyd_warshall_shortest_paths(test_graph2)
harvesting_range = findall(x -> 3.0 <= x, test_graph2_results.dists) # gives 4 coordinates, which refer to two species pairings

Something along this way ?

dists = test_graph2_results.dists
harvesting_range = [(i,j) for i in 1:nv(test_graph2) for j in i+1:nv(test_graph2) if dists[i,j] >= 3]

Thank you very much! You are like a LightGraph superstar :dizzy:

Also, LightGraphs.jl is deprecated, you should now use Graphs.jl.
Don’t worry, these are exactly the same library, the code has just been moved from one repository to another. (see LightGraphs.jl Transition for more information).