Julia / Graphs.jl: creating a graph using a graph () and arguments

I am trying to get a subgraph from a graph in Julia using the Graphs.jl module. I have a graph and I store its vertices and edges for a list, and then my algorithm moves around this list and removes nodes and edges that are not part of the new subgraph. In this part, everything works correctly, after the whole algorithm, all that remains is an array of sub_vertices type: Graphs.ExVertex [] and an array of sub_edges type: Graphs.ExEdge {Graphs.ExVertex} [] .

At the end of the whole function, I want to create a subgraph, so I use:

sub_g = graph(sub_vertices, sub_edges, is_directed=false)

But I get Bounds () error . Any ideas? All I know is the problem in the region.

I tried to run:

sub_g = graph(sub_vertices, Graphs.ExEdge{Graphs.ExVertex}[], is_directed=false)

And it works fine. It creates a graph with the vertices specified by the sub_vertices array . The problem occurs when adding edges with sub_edges .

Additional Information: Vertices and edges are exact copies from the original graph. This means that attributes like index, label, ... are the same as in the original graph. I thought that maybe vertex indices would be a problem, but that’s not because when I run,

sub_g = graph(sub_vertices, Graphs.ExEdge{Graphs.ExVertex}[], is_directed=false)

It works fine. And after printing the vertices, they have indexes, for example, 1,3,5, but it looks fine. Therefore, I do not know why the edges give a boundary error.

+4
source share
1 answer

, . Graphs.jl, Julia.

, , sub_vertices. , sub_vertices [5,6,9], , - [1,2,3]. [5 = > 6, 6 = > 9, 9 = > 5], , , [ 1,2,3].

, , , :

  • , sub_edges.
  • , , sub_vertices.

Graft.jl , :

  julia> using Graft

  julia> g = completegraph(10)
         Graph(10 vertices, 90 edges, Symbol[] vertex properties, Symbol[] edge properties)

  julia> sg = subgraph(g, [5,6,9], [5=>6, 6=>9, 9=>5])
         Graph(3 vertices, 3 edges, Symbol[] vertex properties, Symbol[] edge properties)

  julia> vertices(sg)
         1:3

  julia> edges(sg)
         3-element Graft.EdgeIter:
            1=>2
            2=>3
            3=>1

, ,

  julia> g = completegraph(10)
         Graph(10 vertices, 90 edges, Symbol[] vertex properties, Symbol[] edge properties)

  julia> setlabel!(g, collect(1:10)) # Label the vertices

  julia> sg = subgraph(g, [5,6,9], [5=>6, 6=>9, 9=>5])
         Graph(3 vertices, 3 edges, Symbol[] vertex properties, Symbol[] edge properties)

  julia> encode(sg)
         3-element Array{Int64,1}:
            5
            6
            9

  julia> encode(sg, edges(sg))
         3-element Array{Pair{Int64,Int64},1}:
            5=>6
            6=>9
            9=>5
+1

All Articles