Combinatorial

Combinatorial API

The following example demonstrates the use of the combinatorial API:

julia> using Graft

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

julia> setlabel!(g, map(string, 1 : 10))

julia> # The number of vertices in the graph
       nv(g)
10

julia> # The number of edges in the graph
       ne(g)
90

julia> # The internally used vertex identifiers
       vertices(g)
1:10

julia> # Get an iterator overt all edges in the graph
       edges(g)
90-element Graft.EdgeIter:
 1=>2
 1=>3
 1=>4
 1=>5
 1=>6
 1=>7
 1=>8
 1=>9
 1=>10
 2=>1
 
 10=>1
 10=>2
 10=>3
 10=>4
 10=>5
 10=>6
 10=>7
 10=>8
 10=>9

julia> # Check if the input vertex identifier exists in the graph
       hasvertex(g, 11)
false

julia> # Check if the input edge exists in the graph
       hasedge(g, 1=>1)
false

julia> # Get a list containing the input vertex's out-neighbors
       fadj(g, 1)
9-element Array{Int64,1}:
  2
  3
  4
  5
  6
  7
  8
  9
 10

julia> # Get the out-neighbors of a labelled vertex
       g["1"]
9-element Array{String,1}:
 "2"
 "3"
 "4"
 "5"
 "6"
 "7"
 "8"
 "9"
 "10"

julia> # Get the input vertex's out-neighbors in a preallocated array
       adj = sizehint!(Int[], nv(g));

julia> fadj!(g, 1, adj)
9-element Array{Int64,1}:
  2
  3
  4
  5
  6
  7
  8
  9
 10

julia> # Count the number of out-neighbors the input vertex has
       outdegree(g, 1)
9

julia> # Count the number of in-neighbors the input vertex has
       indegree(g, 1)
9

Detailed documentation:

# Graft.nvMethod.

The number of vertices in the graph

source

# Graft.neMethod.

The number of edges in the graph

source

# Graft.fadjMethod.

Vertex v's out-neighbors in the graph

source

# Graft.fadj!Method.

Retrieve a list of vertices connect to vertex v.

This method copies the adjacencies onto the input array, and is comparitively faster, and causes no mallocs.

source

# Graft.outdegreeMethod.

Vertex v's outdegree in the graph

source

# Graft.indegreeMethod.

Vertex v's indegree in the graph

source