diff --git a/dev/.documenter-siteinfo.json b/dev/.documenter-siteinfo.json index dcf56d87..bf5ccdd1 100644 --- a/dev/.documenter-siteinfo.json +++ b/dev/.documenter-siteinfo.json @@ -1 +1 @@ -{"documenter":{"julia_version":"1.10.5","generation_timestamp":"2024-09-28T11:44:55","documenter_version":"1.7.0"}} \ No newline at end of file +{"documenter":{"julia_version":"1.10.5","generation_timestamp":"2024-09-29T06:14:24","documenter_version":"1.7.0"}} \ No newline at end of file diff --git a/dev/advanced/errorhandling/index.html b/dev/advanced/errorhandling/index.html index 0439fd2a..c3316088 100644 --- a/dev/advanced/errorhandling/index.html +++ b/dev/advanced/errorhandling/index.html @@ -1,2 +1,2 @@ -Error handling · Graphs.jl

Error handling

In an ideal world, all software would work perfectly all the time. However, in the real world software encounters errors due to the outside world, bad input, bugs, or programmer error.

Types of errors

Sentinel values

It is the position of this project that error conditions that happen often, typically due to bad data, should be handled with sentinel values returned to indicate the failure condition. These are used for functions such as add_edge!(g, u, v). If you try to add an edge with negative vertex numbers, or vertices that exceed the number of vertices in the graph, then you will get a return value of false.

Errors / exceptions

For more severe failures such as bad arguments or failure to converge, we use exceptions. The primary distinction between Sentinel Values and Argument Errors has to do with the run time of the function being called. In a function that is expected to be a called in a tight loop such as add_edge!, we will use a sentinel value rather than an exception. This is because it is faster to do a simple if statement to handle the error than a full try/catch block. For functions that take longer to run, we use Exceptions. If you find an exception with an error message that isn't helpful for debugging, please file a bug report so that we can improve these messages.

  • ArgumentError: the inputs to this function are not valid
  • InexactError: some types are used that cannot express a computed quantity with the necessary precision
+Error handling · Graphs.jl

Error handling

In an ideal world, all software would work perfectly all the time. However, in the real world software encounters errors due to the outside world, bad input, bugs, or programmer error.

Types of errors

Sentinel values

It is the position of this project that error conditions that happen often, typically due to bad data, should be handled with sentinel values returned to indicate the failure condition. These are used for functions such as add_edge!(g, u, v). If you try to add an edge with negative vertex numbers, or vertices that exceed the number of vertices in the graph, then you will get a return value of false.

Errors / exceptions

For more severe failures such as bad arguments or failure to converge, we use exceptions. The primary distinction between Sentinel Values and Argument Errors has to do with the run time of the function being called. In a function that is expected to be a called in a tight loop such as add_edge!, we will use a sentinel value rather than an exception. This is because it is faster to do a simple if statement to handle the error than a full try/catch block. For functions that take longer to run, we use Exceptions. If you find an exception with an error message that isn't helpful for debugging, please file a bug report so that we can improve these messages.

  • ArgumentError: the inputs to this function are not valid
  • InexactError: some types are used that cannot express a computed quantity with the necessary precision
diff --git a/dev/advanced/experimental/index.html b/dev/advanced/experimental/index.html index 84c8dc48..adfb5b6c 100644 --- a/dev/advanced/experimental/index.html +++ b/dev/advanced/experimental/index.html @@ -1,5 +1,5 @@ -Experimental algorithms · Graphs.jl

Experimental algorithms

Graphs.Experimental is a module for graph algorithms that are newer or less stable. We can adopt algorithms before we finalize an interface for using them or if we feel that full support cannot be provided to the current implementation. You can expect new developments to land here before they make it into the main module. This enables the development to keep advancing without being risk-averse because of stability guarantees. You can think of this module as a 0.X semantic version space ; it is a place where you can play around with new algorithms, perspectives, and interfaces without fear of breaking critical code.

A Note To Users

Code in this module is unstable and subject to change. Do not use any code in this module in production environments without understanding the (large) risks involved. However, we welcome bug reports and issues via the normal channels..

Index

Full docs

Graphs.Experimental.all_induced_subgraphisomorphFunction
all_induced_subgraphisomorph(g1, g2, alg::IsomorphismAlgorithm=VF2(); vertex_relation=nothing, edge_relation=nothing)

Return all isomorphism from vertex induced subgraphs of g1 to g2. The isomorphisms are returned as an iterator of vectors of tuples, where the i-th vector is the i-th isomorphism and a tuple (u, v) in this vector means that u ∈ g1 is mapped to v ∈ g2.

Optional Arguments

  • alg: The algorithm that is used to find the induced subgraph isomorphism. Can be only VF2() at the moment.
  • vertex_relation: A binary function that takes a vertex from g1 and one from g2. An isomorphism only exists if this function returns true for all matched vertices.
  • edge_relation: A binary function that takes an edge from g1 and one from g2. An isomorphism only exists if this function returns true for all matched edges.

Examples

julia> all_induced_subgraphisomorph(path_graph(3), SimpleGraph(2)) |> collect
+Experimental algorithms · Graphs.jl

Experimental algorithms

Graphs.Experimental is a module for graph algorithms that are newer or less stable. We can adopt algorithms before we finalize an interface for using them or if we feel that full support cannot be provided to the current implementation. You can expect new developments to land here before they make it into the main module. This enables the development to keep advancing without being risk-averse because of stability guarantees. You can think of this module as a 0.X semantic version space ; it is a place where you can play around with new algorithms, perspectives, and interfaces without fear of breaking critical code.

A Note To Users

Code in this module is unstable and subject to change. Do not use any code in this module in production environments without understanding the (large) risks involved. However, we welcome bug reports and issues via the normal channels..

Index

Full docs

Graphs.Experimental.all_induced_subgraphisomorphFunction
all_induced_subgraphisomorph(g1, g2, alg::IsomorphismAlgorithm=VF2(); vertex_relation=nothing, edge_relation=nothing)

Return all isomorphism from vertex induced subgraphs of g1 to g2. The isomorphisms are returned as an iterator of vectors of tuples, where the i-th vector is the i-th isomorphism and a tuple (u, v) in this vector means that u ∈ g1 is mapped to v ∈ g2.

Optional Arguments

  • alg: The algorithm that is used to find the induced subgraph isomorphism. Can be only VF2() at the moment.
  • vertex_relation: A binary function that takes a vertex from g1 and one from g2. An isomorphism only exists if this function returns true for all matched vertices.
  • edge_relation: A binary function that takes an edge from g1 and one from g2. An isomorphism only exists if this function returns true for all matched edges.

Examples

julia> all_induced_subgraphisomorph(path_graph(3), SimpleGraph(2)) |> collect
 2-element Array{Array{Tuple{Int64,Int64},1},1}:
  [(1, 1), (3, 2)]
  [(3, 1), (1, 2)]
@@ -13,7 +13,7 @@
  [(2, 1), (3, 2)]
 julia> all_induced_subgraphisomorph(g1, g2, vertex_relation=color_rel) |> collect
 1-element Array{Array{Tuple{Int64,Int64},1},1}:
- [(1, 1), (2, 2)]

See also

all_subgraphisomorph, all_isomorph, has_induced_subgraphisomorph, count_induced_subgraphisomorph

source
Graphs.Experimental.all_isomorphFunction
all_isomorph(g1, g2, alg::IsomorphismAlgorithm=VF2(); vertex_relation=nothing, edge_relation=nothing)

Return all isomorphism from g1 to g2. The isomorphisms are returned as an iterator of vectors of tuples, where the i-th vector is the i-th isomorphism and a tuple (u, v) in this vector means that u ∈ g1 is mapped to v ∈ g2.

Optional Arguments

  • alg: The algorithm that is used to find the induced subgraph isomorphism. Can be only VF2() at the moment.
  • vertex_relation: A binary function that takes a vertex from g1 and one from g2. An isomorphism only exists if this function returns true for all matched vertices.
  • edge_relation: A binary function that takes an edge from g1 and one from g2. An isomorphism only exists if this function returns true for all matched edges.

Examples

julia> all_isomorph(star_graph(4), star_graph(4)) |> collect
+ [(1, 1), (2, 2)]

See also

all_subgraphisomorph, all_isomorph, has_induced_subgraphisomorph, count_induced_subgraphisomorph

source
Graphs.Experimental.all_isomorphFunction
all_isomorph(g1, g2, alg::IsomorphismAlgorithm=VF2(); vertex_relation=nothing, edge_relation=nothing)

Return all isomorphism from g1 to g2. The isomorphisms are returned as an iterator of vectors of tuples, where the i-th vector is the i-th isomorphism and a tuple (u, v) in this vector means that u ∈ g1 is mapped to v ∈ g2.

Optional Arguments

  • alg: The algorithm that is used to find the induced subgraph isomorphism. Can be only VF2() at the moment.
  • vertex_relation: A binary function that takes a vertex from g1 and one from g2. An isomorphism only exists if this function returns true for all matched vertices.
  • edge_relation: A binary function that takes an edge from g1 and one from g2. An isomorphism only exists if this function returns true for all matched edges.

Examples

julia> all_isomorph(star_graph(4), star_graph(4)) |> collect
 6-element Array{Array{Tuple{Int64,Int64},1},1}:
  [(1, 1), (2, 2), (3, 3), (4, 4)]
  [(1, 1), (2, 2), (4, 3), (3, 4)]
@@ -32,7 +32,7 @@
  [(3, 1), (1, 2), (2, 3)]
 julia> all_subgraphisomorph(g1, g2, vertex_relation=color_rel)
 1-element Array{Array{Tuple{Int64,Int64},1},1}:
- [(3, 1), (1, 2), (2, 3)]

See also

all_induced_subgraphisomorph, all_subgraphisomorph, has_isomorph, count_isomorph

source
Graphs.Experimental.all_subgraphisomorphFunction
all_subgraphisomorph(g1, g2, alg::IsomorphismAlgorithm=VF2(); vertex_relation=nothing, edge_relation=nothing)

Return all isomorphism from subgraphs of g1 to g2. The isomorphisms are returned as an iterator of vectors of tuples, where the i-th vector is the i-th isomorphism and a tuple (u, v) in this vector means that u ∈ g1 is mapped to v ∈ g2.

Optional Arguments

  • alg: The algorithm that is used to find the induced subgraph isomorphism. Can be only VF2() at the moment.
  • vertex_relation: A binary function that takes a vertex from g1 and one from g2. An isomorphism only exists if this function returns true for all matched vertices.
  • edge_relation: A binary function that takes an edge from g1 and one from g2. An isomorphism only exists if this function returns true for all matched edges.

Examples

julia> all_subgraphisomorph(path_graph(3), path_graph(2)) |> collect
+ [(3, 1), (1, 2), (2, 3)]

See also

all_induced_subgraphisomorph, all_subgraphisomorph, has_isomorph, count_isomorph

source
Graphs.Experimental.all_subgraphisomorphFunction
all_subgraphisomorph(g1, g2, alg::IsomorphismAlgorithm=VF2(); vertex_relation=nothing, edge_relation=nothing)

Return all isomorphism from subgraphs of g1 to g2. The isomorphisms are returned as an iterator of vectors of tuples, where the i-th vector is the i-th isomorphism and a tuple (u, v) in this vector means that u ∈ g1 is mapped to v ∈ g2.

Optional Arguments

  • alg: The algorithm that is used to find the induced subgraph isomorphism. Can be only VF2() at the moment.
  • vertex_relation: A binary function that takes a vertex from g1 and one from g2. An isomorphism only exists if this function returns true for all matched vertices.
  • edge_relation: A binary function that takes an edge from g1 and one from g2. An isomorphism only exists if this function returns true for all matched edges.

Examples

julia> all_subgraphisomorph(path_graph(3), path_graph(2)) |> collect
 4-element Array{Array{Tuple{Int64,Int64},1},1}:
  [(1, 1), (2, 2)]
  [(2, 1), (1, 2)]
@@ -48,13 +48,13 @@
  [(2, 1), (3, 2)]
 julia> all_subgraphisomorph(g1, g2, vertex_relation=color_rel)
 1-element Array{Array{Tuple{Int64,Int64},1},1}:
- [(2, 1), (3, 2)]

See also

all_induced_subgraphisomorph, all_isomorph, has_subgraphisomorph, count_subgraphisomorph

source
Graphs.Experimental.could_have_isomorphMethod
could_have_isomorph(g1, g2)

Run quick test to check if g1 andg2` could be isomorphic.

If the result is false, then g1 and g2 are definitely not isomorphic, but if the result is true this is not guaranteed.

Examples

julia> using Graphs
 
 julia> Graphs.Experimental.could_have_isomorph(path_graph(3), star_graph(4))
 false
 
 julia> Graphs.Experimental.could_have_isomorph(path_graph(3), star_graph(3))
-true
source
Graphs.Experimental.count_induced_subgraphisomorphFunction
count_induced_subgraphisomorph(g1, g2, alg::IsomorphismAlgorithm=VF2(); vertex_relation=nothing, edge_relation=nothing)

Return the number of vertex induced subgraphs of the graph g1 that are isomorphic to g2.

Optional Arguments

  • vertex_relation: A binary function that takes a vertex from g1 and one from g2. An isomorphism only exists if this function returns true for all matched vertices.
  • edge_relation: A binary function that takes an edge from g1 and one from g2. An isomorphism only exists if this function returns true for all matched edges.

Examples

julia> count_induced_subgraphisomorph(complete_graph(5), complete_graph(4))
+true
source
Graphs.Experimental.count_induced_subgraphisomorphFunction
count_induced_subgraphisomorph(g1, g2, alg::IsomorphismAlgorithm=VF2(); vertex_relation=nothing, edge_relation=nothing)

Return the number of vertex induced subgraphs of the graph g1 that are isomorphic to g2.

Optional Arguments

  • vertex_relation: A binary function that takes a vertex from g1 and one from g2. An isomorphism only exists if this function returns true for all matched vertices.
  • edge_relation: A binary function that takes an edge from g1 and one from g2. An isomorphism only exists if this function returns true for all matched edges.

Examples

julia> count_induced_subgraphisomorph(complete_graph(5), complete_graph(4))
 120
 julia> count_induced_subgraphisomorph(complete_graph(5), cycle_graph(4))
 0
@@ -65,7 +65,7 @@
 julia> count_induced_subgraphisomorph(g1, g2)
 2
 julia> count_induced_subgraphisomorph(g1, g2, vertex_relation=color_rel)
-1

See also

count_subgraphisomorph, count_isomorph, has_induced_subgraphisomorph, all_induced_subgraphisomorph

source
Graphs.Experimental.count_isomorphFunction
count_isomorph(g1, g2, alg::IsomorphismAlgorithm=VF2(); vertex_relation=nothing, edge_relation=nothing)

Return the number of isomorphism from graph g1 to g2.

Optional Arguments

  • alg: The algorithm that is used to find the induced subgraph isomorphism. Can be only VF2() at the moment.
  • vertex_relation: A binary function that takes a vertex from g1 and one from g2. An isomorphism only exists if this function returns true for all matched vertices.
  • edge_relation: A binary function that takes an edge from g1 and one from g2. An isomorphism only exists if this function returns true for all matched edges.

Examples

julia> count_isomorph(cycle_graph(5), cycle_graph(5))
+1

See also

count_subgraphisomorph, count_isomorph, has_induced_subgraphisomorph, all_induced_subgraphisomorph

source
Graphs.Experimental.count_isomorphFunction
count_isomorph(g1, g2, alg::IsomorphismAlgorithm=VF2(); vertex_relation=nothing, edge_relation=nothing)

Return the number of isomorphism from graph g1 to g2.

Optional Arguments

  • alg: The algorithm that is used to find the induced subgraph isomorphism. Can be only VF2() at the moment.
  • vertex_relation: A binary function that takes a vertex from g1 and one from g2. An isomorphism only exists if this function returns true for all matched vertices.
  • edge_relation: A binary function that takes an edge from g1 and one from g2. An isomorphism only exists if this function returns true for all matched edges.

Examples

julia> count_isomorph(cycle_graph(5), cycle_graph(5))
 10
 julia> count_isomorph(complete_graph(5), cycle_graph(5))
 0
@@ -76,7 +76,7 @@
 julia> count_isomorph(g1, g2)
 3
 julia> count_isomorph(g1, g2, vertex_relation=color_rel)
-0

See also

count_induced_subgraphisomorph, count_subgraphisomorph, has_isomorph, all_isomorph

source
Graphs.Experimental.count_subgraphisomorphFunction
count_subgraphisomorph(g1, g2, alg::IsomorphismAlgorithm=VF2(); vertex_relation=nothing, edge_relation=nothing)

Return the number of subgraphs of the graph g1 that are isomorphic to g2.

Optional Arguments

  • alg: The algorithm that is used to find the induced subgraph isomorphism. Can be only VF2() at the moment.
  • vertex_relation: A binary function that takes a vertex from g1 and one from g2. An isomorphism only exists if this function returns true for all matched vertices.
  • edge_relation: A binary function that takes an edge from g1 and one from g2. An isomorphism only exists if this function returns true for all matched edges.

Examples

julia> count_subgraphisomorph(complete_graph(5), complete_graph(4))
+0

See also

count_induced_subgraphisomorph, count_subgraphisomorph, has_isomorph, all_isomorph

source
Graphs.Experimental.count_subgraphisomorphFunction
count_subgraphisomorph(g1, g2, alg::IsomorphismAlgorithm=VF2(); vertex_relation=nothing, edge_relation=nothing)

Return the number of subgraphs of the graph g1 that are isomorphic to g2.

Optional Arguments

  • alg: The algorithm that is used to find the induced subgraph isomorphism. Can be only VF2() at the moment.
  • vertex_relation: A binary function that takes a vertex from g1 and one from g2. An isomorphism only exists if this function returns true for all matched vertices.
  • edge_relation: A binary function that takes an edge from g1 and one from g2. An isomorphism only exists if this function returns true for all matched edges.

Examples

julia> count_subgraphisomorph(complete_graph(5), complete_graph(4))
 120
 julia> count_subgraphisomorph(complete_graph(5), cycle_graph(4))
 120
@@ -87,7 +87,7 @@
 julia> count_subgraphisomorph(g1, g2)
 6
 julia> count_subgraphisomorph(g1, g2, vertex_relation=color_rel)
-2

See also

count_induced_subgraphisomorph, count_isomorph, has_subgraphisomorph, all_subgraphisomorph

source
Graphs.Experimental.has_induced_subgraphisomorphFunction
has_induced_subgraphisomorph(g1, g2, alg::IsomorphismAlgorithm=VF2(); vertex_relation=nothing, edge_relation=nothing)

Return true if the graph g1 contains a vertex induced subgraph that is isomorphic to g2.

Optional Arguments

  • alg: The algorithm that is used to find the induced subgraph isomorphism. Can be only VF2() at the moment.
  • vertex_relation: A binary function that takes a vertex from g1 and one from g2. An isomorphism only exists if this function returns true for all matched vertices.
  • edge_relation: A binary function that takes an edge from g1 and one from g2. An isomorphism only exists if this function returns true for all matched edges.

Examples

julia> has_induced_subgraphisomorph(complete_graph(5), complete_graph(4))
+2

See also

count_induced_subgraphisomorph, count_isomorph, has_subgraphisomorph, all_subgraphisomorph

source
Graphs.Experimental.has_induced_subgraphisomorphFunction
has_induced_subgraphisomorph(g1, g2, alg::IsomorphismAlgorithm=VF2(); vertex_relation=nothing, edge_relation=nothing)

Return true if the graph g1 contains a vertex induced subgraph that is isomorphic to g2.

Optional Arguments

  • alg: The algorithm that is used to find the induced subgraph isomorphism. Can be only VF2() at the moment.
  • vertex_relation: A binary function that takes a vertex from g1 and one from g2. An isomorphism only exists if this function returns true for all matched vertices.
  • edge_relation: A binary function that takes an edge from g1 and one from g2. An isomorphism only exists if this function returns true for all matched edges.

Examples

julia> has_induced_subgraphisomorph(complete_graph(5), complete_graph(4))
 true
 julia> has_induced_subgraphisomorph(complete_graph(5), cycle_graph(4))
 false
@@ -98,7 +98,7 @@
 julia> has_induced_subgraphisomorph(g1, g2)
 true
 julia> has_induced_subgraphisomorph(g1, g2, vertex_relation=color_rel)
-false

See also

has_subgraphisomorph, has_isomorph, count_induced_subgraphisomorph, all_induced_subgraphisomorph

source
Graphs.Experimental.has_isomorphFunction
has_isomorph(g1, g2, alg::IsomorphismAlgorithm=VF2(); vertex_relation=nothing, edge_relation=nothing)

Return true if the graph g1 is isomorphic to g2.

Optional Arguments

  • alg: The algorithm that is used to find the induced subgraph isomorphism. Can be only VF2() at the moment.
  • vertex_relation: A binary function that takes a vertex from g1 and one from g2. An isomorphism only exists if this function returns true for all matched vertices.
  • edge_relation: A binary function that takes an edge from g1 and one from g2. An isomorphism only exists if this function returns true for all matched edges.

Examples

julia> has_isomorph(complete_graph(3), cycle_graph(3))
+false

See also

has_subgraphisomorph, has_isomorph, count_induced_subgraphisomorph, all_induced_subgraphisomorph

source
Graphs.Experimental.has_isomorphFunction
has_isomorph(g1, g2, alg::IsomorphismAlgorithm=VF2(); vertex_relation=nothing, edge_relation=nothing)

Return true if the graph g1 is isomorphic to g2.

Optional Arguments

  • alg: The algorithm that is used to find the induced subgraph isomorphism. Can be only VF2() at the moment.
  • vertex_relation: A binary function that takes a vertex from g1 and one from g2. An isomorphism only exists if this function returns true for all matched vertices.
  • edge_relation: A binary function that takes an edge from g1 and one from g2. An isomorphism only exists if this function returns true for all matched edges.

Examples

julia> has_isomorph(complete_graph(3), cycle_graph(3))
 true
 julia> has_isomorph(complete_graph(4), cycle_graph(4))
 false
@@ -109,7 +109,7 @@
 julia> has_isomorph(g1, g2)
 true
 julia> has_isomorph(g1, g2, vertex_relation=color_rel)
-false

See also

has_induced_subgraphisomorph, has_subgraphisomorph, count_subgraphisomorph, all_subgraphisomorph

source
Graphs.Experimental.has_subgraphisomorphFunction
has_subgraphisomorph(g1, g2, alg::IsomorphismAlgorithm=VF2(); vertex_relation=nothing, edge_relation=nothing)

Return true if the graph g1 contains a subgraph that is isomorphic to g2.

Optional Arguments

  • alg: The algorithm that is used to find the induced subgraph isomorphism. Can be only VF2() at the moment.
  • vertex_relation: A binary function that takes a vertex from g1 and one from g2. An isomorphism only exists if this function returns true for all matched vertices.
  • edge_relation: A binary function that takes an edge from g1 and one from g2. An isomorphism only exists if this function returns true for all matched edges.

Examples

julia> has_subgraphisomorph(complete_graph(5), complete_graph(4))
+false

See also

has_induced_subgraphisomorph, has_subgraphisomorph, count_subgraphisomorph, all_subgraphisomorph

source
Graphs.Experimental.has_subgraphisomorphFunction
has_subgraphisomorph(g1, g2, alg::IsomorphismAlgorithm=VF2(); vertex_relation=nothing, edge_relation=nothing)

Return true if the graph g1 contains a subgraph that is isomorphic to g2.

Optional Arguments

  • alg: The algorithm that is used to find the induced subgraph isomorphism. Can be only VF2() at the moment.
  • vertex_relation: A binary function that takes a vertex from g1 and one from g2. An isomorphism only exists if this function returns true for all matched vertices.
  • edge_relation: A binary function that takes an edge from g1 and one from g2. An isomorphism only exists if this function returns true for all matched edges.

Examples

julia> has_subgraphisomorph(complete_graph(5), complete_graph(4))
 true
 julia> has_subgraphisomorph(complete_graph(5), cycle_graph(4))
 true
@@ -120,13 +120,13 @@
 julia> has_subgraphisomorph(g1, g2)
 true
 julia> has_subgraphisomorph(g1, g2, vertex_relation=color_rel)
-false

See also

has_induced_subgraphisomorph, has_isomorph, count_subgraphisomorph, all_subgraphisomorph

source
Graphs.Experimental.vf2Method
vf2(callback, g1, g2, problemtype; vertex_relation=nothing, edge_relation=nothing)

Iterate over all isomorphism between the graphs g1 (or subgraphs thereof) and g2. The problem that is solved depends on the value of problemtype:

  • IsomorphismProblem(): Only isomorphisms between the whole graph g1 and g2 are considered.
  • SubGraphIsomorphismProblem(): All isomorphism between subgraphs of g1 and g2 are considered.
  • InducedSubGraphIsomorphismProblem(): All isomorphism between vertex induced subgraphs of g1 and g2 are considered.

Upon finding an isomorphism, the function callback is called with a vector vmap as an argument. vmap is a vector where vmap[v] == u means that vertex v in g2 is mapped to vertex u in g1. If the algorithm should look for another isomorphism, then this function should return true.

Optional Arguments

  • vertex_relation: A binary function that takes a vertex from g1 and one from g2. An isomorphism only exists if this function returns true for all matched vertices.
  • edge_relation: A binary function that takes an edge from g1 and one from g2. An isomorphism only exists if this function returns true for all matched edges.

References

Luigi P. Cordella, Pasquale Foggia, Carlo Sansone, Mario Vento “A (Sub)Graph Isomorphism Algorithm for Matching Large Graphs”

source
Graphs.Experimental.Traversals.distancesMethod
distances(g, s, alg=BFS())
-distances(g, ss, alg=BFS())

Return a vector filled with the geodesic distances of vertices in g from vertex s / unique vertices ss using BFS traversal algorithm alg. For vertices in disconnected components the default distance is typemax(T).

source
Graphs.Experimental.vf2Method
vf2(callback, g1, g2, problemtype; vertex_relation=nothing, edge_relation=nothing)

Iterate over all isomorphism between the graphs g1 (or subgraphs thereof) and g2. The problem that is solved depends on the value of problemtype:

  • IsomorphismProblem(): Only isomorphisms between the whole graph g1 and g2 are considered.
  • SubGraphIsomorphismProblem(): All isomorphism between subgraphs of g1 and g2 are considered.
  • InducedSubGraphIsomorphismProblem(): All isomorphism between vertex induced subgraphs of g1 and g2 are considered.

Upon finding an isomorphism, the function callback is called with a vector vmap as an argument. vmap is a vector where vmap[v] == u means that vertex v in g2 is mapped to vertex u in g1. If the algorithm should look for another isomorphism, then this function should return true.

Optional Arguments

  • vertex_relation: A binary function that takes a vertex from g1 and one from g2. An isomorphism only exists if this function returns true for all matched vertices.
  • edge_relation: A binary function that takes an edge from g1 and one from g2. An isomorphism only exists if this function returns true for all matched edges.

References

Luigi P. Cordella, Pasquale Foggia, Carlo Sansone, Mario Vento “A (Sub)Graph Isomorphism Algorithm for Matching Large Graphs”

source
Graphs.Experimental.Traversals.distancesMethod
distances(g, s, alg=BFS())
+distances(g, ss, alg=BFS())

Return a vector filled with the geodesic distances of vertices in g from vertex s / unique vertices ss using BFS traversal algorithm alg. For vertices in disconnected components the default distance is typemax(T).

source
Graphs.Experimental.Traversals.traverse_graph!Method
traverse_graph!(g, s, alg, state, neighborfn=outneighbors)
 traverse_graph!(g, ss, alg, state, neighborfn=outneighbors)
 
-Traverse a graph `g` starting at vertex `s` / vertices `ss` using algorithm `alg`, maintaining state in [`AbstractTraversalState`](@ref) `state`. Next vertices to be visited are determined by `neighborfn` (default `outneighbors`). Return `true` if traversal finished; `false` if one of the visit functions caused an early termination.
source
Graphs.Experimental.Traversals.AbstractTraversalStateType
abstract type AbstractTraversalState

AbstractTraversalState is the abstract type used to hold mutable states for various traversal algorithms (see traverse_graph!).

When creating concrete types, you should override the following functions where relevant. These functions are listed in order of occurrence in the traversal:

Each of these functions should return a boolean. If the return value of the function is false, the traversal will return the state immediately. Otherwise, the traversal will continue.

For better performance, use the @inline directive and make your functions branch-free.

source
Graphs.Experimental.Traversals.parentsMethod
parents(g, s, alg, neighborfn=outneighbors)

Return a vector of parent vertices indexed by vertex using TraversalAlgorithm alg starting with vertex s. If neighborfn is specified, use the corresponding neighbor-generation function (inneighborsr and outneighbors are valid values).

Performance

This implementation is designed to perform well on large graphs. There are implementations which are marginally faster in practice for smaller graphs, but the performance improvements using this implementation on large graphs can be significant.

source
Graphs.Experimental.Traversals.traverse_graph!Method
traverse_graph!(g, s, alg, state, neighborfn=outneighbors)
-traverse_graph!(g, ss, alg, state, neighborfn=outneighbors)

Traverse a graph g from source vertex s / vertices ss keeping track of state. Return true if traversal finished normally; false if one of the visit functions returned false (see )

source
Graphs.Experimental.Traversals.treeFunction
tree(g, s, alg, neighborfn=outneighbors)

Return a directed acyclic graph based on traversal of the graph g starting with source vertex s using algorithm alg with neighbor function neighborfn.

source
Graphs.Experimental.ShortestPaths.AStarType
struct AStar <: ShortestPathAlgorithm

The structure used to configure and specify that shortest_paths should use the A* search algorithm. An optional heuristic function may be supplied. If missing, the heuristic is set to n -> 0.

Implementation Notes

AStar supports the following shortest-path functionality:

  • non-negative distance matrices / weights
  • single destination
source
Graphs.Experimental.ShortestPaths.BFSType
struct BFS <: ShortestPathAlgorithm

The structure used to configure and specify that shortest_paths should use the Breadth-First Search algorithm.

An optional sorting algorithm may be specified (default = no sorting). Sorting helps maintain cache locality and will improve performance on very large graphs; for normal use, sorting will incur a performance penalty.

BFS is the default algorithm used when a source is specified but no distance matrix is specified.

Implementation Notes

BFS supports the following shortest-path functionality:

  • (optional) multiple sources
  • all destinations
source
Graphs.Experimental.ShortestPaths.DijkstraType
struct Dijkstra <: ShortestPathAlgorithm

The structure used to configure and specify that shortest_paths should use Dijkstra's algorithm to compute shortest paths. Optional fields for this structure include

  • all_paths::Bool - set to true to calculate all (redundant, equivalent) paths to a given destination
  • track_vertices::Bool - set to true to keep a running list of visited vertices (used for specific centrality calculations; generally not needed).

Dijkstra is the default algorithm used when a distance matrix is specified.

Implementation Notes

Dijkstra supports the following shortest-path functionality:

  • non-negative distance matrices / weights
  • (optional) multiple sources
  • all destinations
  • redundant equivalent path tracking
  • vertex tracking

Performance

If using a sparse matrix for distmx in shortest_paths, you may achieve better performance by passing in a transpose of its sparse transpose. That is, assuming D is the sparse distance matrix:

D = transpose(sparse(transpose(D)))

Be aware that realizing the sparse transpose of D incurs a heavy one-time penalty, so this strategy should only be used when multiple calls to shortest_paths with the distance matrix are planned.

source
Graphs.Experimental.ShortestPaths.FloydWarshallType
struct FloydWarshall <: ShortestPathAlgorithm

The structure used to configure and specify that shortest_paths should use the Floyd-Warshall algorithm. No additional configuration parameters are specified or required.

FloydWarshall is the default all-pairs algorithm used when no source is specified.

Implementation Notes

FloydWarshall supports the following shortest-path functionality:

  • non-negative distance matrices / weights
  • all-pairs shortest paths

Performance

Space complexity is on the order of $\mathcal{O}(|V|^2)$.

source
Graphs.Experimental.ShortestPaths.JohnsonType
struct Johnson <: ShortestPathAlgorithm

The structure used to configure and specify that shortest_paths should use the Johnson algorithm. No additional configuration parameters are specified or required.

Implementation Notes

Johnson supports the following shortest-path functionality:

  • non-negative distance matrices / weights
  • all-pairs shortest paths

Performance

Complexity: O(|V|*|E|)

source
Graphs.Experimental.ShortestPaths.has_negative_weight_cycleFunction
has_negative_weight_cycle(g[, distmx=weights(g), alg=BellmanFord()])

Given a graph g, an optional distance matrix distmx, and an optional algorithm alg (one of BellmanFord or SPFA), return true if any cycle detected in the graph has a negative weight.

Examples

julia> using Graphs, Graphs.Experimental.ShortestPaths
+Traverse a graph `g` starting at vertex `s` / vertices `ss` using algorithm `alg`, maintaining state in [`AbstractTraversalState`](@ref) `state`. Next vertices to be visited are determined by `neighborfn` (default `outneighbors`). Return `true` if traversal finished; `false` if one of the visit functions caused an early termination.
source
Graphs.Experimental.Traversals.AbstractTraversalStateType
abstract type AbstractTraversalState

AbstractTraversalState is the abstract type used to hold mutable states for various traversal algorithms (see traverse_graph!).

When creating concrete types, you should override the following functions where relevant. These functions are listed in order of occurrence in the traversal:

Each of these functions should return a boolean. If the return value of the function is false, the traversal will return the state immediately. Otherwise, the traversal will continue.

For better performance, use the @inline directive and make your functions branch-free.

source
Graphs.Experimental.Traversals.parentsMethod
parents(g, s, alg, neighborfn=outneighbors)

Return a vector of parent vertices indexed by vertex using TraversalAlgorithm alg starting with vertex s. If neighborfn is specified, use the corresponding neighbor-generation function (inneighborsr and outneighbors are valid values).

Performance

This implementation is designed to perform well on large graphs. There are implementations which are marginally faster in practice for smaller graphs, but the performance improvements using this implementation on large graphs can be significant.

source
Graphs.Experimental.Traversals.traverse_graph!Method
traverse_graph!(g, s, alg, state, neighborfn=outneighbors)
+traverse_graph!(g, ss, alg, state, neighborfn=outneighbors)

Traverse a graph g from source vertex s / vertices ss keeping track of state. Return true if traversal finished normally; false if one of the visit functions returned false (see )

source
Graphs.Experimental.Traversals.treeFunction
tree(g, s, alg, neighborfn=outneighbors)

Return a directed acyclic graph based on traversal of the graph g starting with source vertex s using algorithm alg with neighbor function neighborfn.

source
Graphs.Experimental.ShortestPaths.AStarType
struct AStar <: ShortestPathAlgorithm

The structure used to configure and specify that shortest_paths should use the A* search algorithm. An optional heuristic function may be supplied. If missing, the heuristic is set to n -> 0.

Implementation Notes

AStar supports the following shortest-path functionality:

  • non-negative distance matrices / weights
  • single destination
source
Graphs.Experimental.ShortestPaths.BFSType
struct BFS <: ShortestPathAlgorithm

The structure used to configure and specify that shortest_paths should use the Breadth-First Search algorithm.

An optional sorting algorithm may be specified (default = no sorting). Sorting helps maintain cache locality and will improve performance on very large graphs; for normal use, sorting will incur a performance penalty.

BFS is the default algorithm used when a source is specified but no distance matrix is specified.

Implementation Notes

BFS supports the following shortest-path functionality:

  • (optional) multiple sources
  • all destinations
source
Graphs.Experimental.ShortestPaths.DijkstraType
struct Dijkstra <: ShortestPathAlgorithm

The structure used to configure and specify that shortest_paths should use Dijkstra's algorithm to compute shortest paths. Optional fields for this structure include

  • all_paths::Bool - set to true to calculate all (redundant, equivalent) paths to a given destination
  • track_vertices::Bool - set to true to keep a running list of visited vertices (used for specific centrality calculations; generally not needed).

Dijkstra is the default algorithm used when a distance matrix is specified.

Implementation Notes

Dijkstra supports the following shortest-path functionality:

  • non-negative distance matrices / weights
  • (optional) multiple sources
  • all destinations
  • redundant equivalent path tracking
  • vertex tracking

Performance

If using a sparse matrix for distmx in shortest_paths, you may achieve better performance by passing in a transpose of its sparse transpose. That is, assuming D is the sparse distance matrix:

D = transpose(sparse(transpose(D)))

Be aware that realizing the sparse transpose of D incurs a heavy one-time penalty, so this strategy should only be used when multiple calls to shortest_paths with the distance matrix are planned.

source
Graphs.Experimental.ShortestPaths.FloydWarshallType
struct FloydWarshall <: ShortestPathAlgorithm

The structure used to configure and specify that shortest_paths should use the Floyd-Warshall algorithm. No additional configuration parameters are specified or required.

FloydWarshall is the default all-pairs algorithm used when no source is specified.

Implementation Notes

FloydWarshall supports the following shortest-path functionality:

  • non-negative distance matrices / weights
  • all-pairs shortest paths

Performance

Space complexity is on the order of $\mathcal{O}(|V|^2)$.

source
Graphs.Experimental.ShortestPaths.JohnsonType
struct Johnson <: ShortestPathAlgorithm

The structure used to configure and specify that shortest_paths should use the Johnson algorithm. No additional configuration parameters are specified or required.

Implementation Notes

Johnson supports the following shortest-path functionality:

  • non-negative distance matrices / weights
  • all-pairs shortest paths

Performance

Complexity: O(|V|*|E|)

source
Graphs.Experimental.ShortestPaths.has_negative_weight_cycleFunction
has_negative_weight_cycle(g[, distmx=weights(g), alg=BellmanFord()])

Given a graph g, an optional distance matrix distmx, and an optional algorithm alg (one of BellmanFord or SPFA), return true if any cycle detected in the graph has a negative weight.

Examples

julia> using Graphs, Graphs.Experimental.ShortestPaths
 
 julia> g = complete_graph(3);
 
@@ -140,9 +140,9 @@
 julia> d = [1 1 -1 1; 1 1 -1 1; 1 1 1 1; 1 1 1 1];
 
 julia> has_negative_weight_cycle(g, d, SPFA())
-false
source
Graphs.Experimental.ShortestPaths.pathsMethod
paths(state[, v])
 paths(state[, vs])
-paths(state[, v, d]))

Given the output of a shortest_paths calculation of type ShortestPathResult, return a vector (indexed by vertex) of the paths between the source vertex used to compute the shortest path and a single destination vertex v, a vector of destination vertices vs, or the entire graph.

For multiple destination vertices, each path is represented by a vector of vertices on the path between the source and the destination. Nonexistent paths will be indicated by an empty vector. For single destinations, the path is represented by a single vector of vertices, and will be length 0 if the path does not exist.

For ShortestPathAlgorithms that compute all shortest paths for all pairs of vertices, paths(state) will return a vector (indexed by source vertex) of vectors (indexed by destination vertex) of paths. paths(state, v) will return a vector (indexed by destination vertex) of paths from source v to all other vertices. In addition, paths(state, v, d) will return a vector representing the path from vertex v to vertex d.

source
Graphs.Experimental.ShortestPaths.shortest_pathsMethod
shortest_paths(g, s, distmx, alg)
+paths(state[, v, d]))

Given the output of a shortest_paths calculation of type ShortestPathResult, return a vector (indexed by vertex) of the paths between the source vertex used to compute the shortest path and a single destination vertex v, a vector of destination vertices vs, or the entire graph.

For multiple destination vertices, each path is represented by a vector of vertices on the path between the source and the destination. Nonexistent paths will be indicated by an empty vector. For single destinations, the path is represented by a single vector of vertices, and will be length 0 if the path does not exist.

For ShortestPathAlgorithms that compute all shortest paths for all pairs of vertices, paths(state) will return a vector (indexed by source vertex) of vectors (indexed by destination vertex) of paths. paths(state, v) will return a vector (indexed by destination vertex) of paths from source v to all other vertices. In addition, paths(state, v, d) will return a vector representing the path from vertex v to vertex d.

source
Graphs.Experimental.ShortestPaths.shortest_pathsMethod
shortest_paths(g, s, distmx, alg)
 shortest_paths(g, s, t, alg)
 shortest_paths(g, s, alg)
 shortest_paths(g, s)
@@ -157,7 +157,7 @@
 s2 = shortest_paths(g, 1)                # `alg` defaults to `BFS`
 s3 = shortest_paths(g, 1, w)             # `alg` defaults to `Dijkstra`
 s4 = shortest_paths(g, 1, BellmanFord())
-s5 = shortest_paths(g, 1, w, DEsopoPape())
source
Graphs.Experimental.ShortestPaths.has_negative_weight_cycleMethod

Function which returns true if there is any negative weight cycle in the graph.

Examples

julia> using Graphs
 
 julia> g = complete_graph(3);
 
@@ -171,6 +171,6 @@
 julia> d = [1 1 -1 1; 1 1 -1 1; 1 1 1 1; 1 1 1 1];
 
 julia> has_negative_weight_cycle(g, d, SPFA());
-false
source
Graphs.Experimental.Parallel.gdistances!Method
gdistances!(g, sources, vert_level; queue_segment_size=20)
-gdistances!(g, source, vert_level; queue_segment_size=20)

Parallel implementation of Graphs.gdistances! with dynamic load balancing.

Optional Arguments

  • queue_segment_size = 20: It is the number of vertices a thread can claim from a queue

at a time. For graphs with uniform degree, a larger value of queue_segment_size could improve performance.

References

  • [Avoiding Locks and Atomic Instructions in Shared-Memory Parallel BFS Using Optimistic

Parallelization](https://www.computer.org/csdl/proceedings/ipdpsw/2013/4979/00/4979b628-abs.html).

source
Graphs.Experimental.Parallel.gdistancesMethod
gdistances(g, sources; queue_segment_size=20)
-gdistances(g, source; queue_segment_size=20)

Parallel implementation of Graphs.gdistances! with dynamic load balancing.

Optional Arguments

  • queue_segment_size = 20: It is the number of vertices a thread can claim from a queue at a time.

For denser graphs, a smaller value of queue_segment_size could improve performance.

References

  • [Avoiding Locks and Atomic Instructions in Shared-Memory Parallel BFS Using Optimistic

Parallelization](https://www.computer.org/csdl/proceedings/ipdpsw/2013/4979/00/4979b628-abs.html).

source
+false
source
Graphs.Experimental.Parallel.gdistances!Method
gdistances!(g, sources, vert_level; queue_segment_size=20)
+gdistances!(g, source, vert_level; queue_segment_size=20)

Parallel implementation of Graphs.gdistances! with dynamic load balancing.

Optional Arguments

  • queue_segment_size = 20: It is the number of vertices a thread can claim from a queue

at a time. For graphs with uniform degree, a larger value of queue_segment_size could improve performance.

References

  • [Avoiding Locks and Atomic Instructions in Shared-Memory Parallel BFS Using Optimistic

Parallelization](https://www.computer.org/csdl/proceedings/ipdpsw/2013/4979/00/4979b628-abs.html).

source
Graphs.Experimental.Parallel.gdistancesMethod
gdistances(g, sources; queue_segment_size=20)
+gdistances(g, source; queue_segment_size=20)

Parallel implementation of Graphs.gdistances! with dynamic load balancing.

Optional Arguments

  • queue_segment_size = 20: It is the number of vertices a thread can claim from a queue at a time.

For denser graphs, a smaller value of queue_segment_size could improve performance.

References

  • [Avoiding Locks and Atomic Instructions in Shared-Memory Parallel BFS Using Optimistic

Parallelization](https://www.computer.org/csdl/proceedings/ipdpsw/2013/4979/00/4979b628-abs.html).

source
diff --git a/dev/advanced/parallel/index.html b/dev/advanced/parallel/index.html index c5255c98..60aba6d4 100644 --- a/dev/advanced/parallel/index.html +++ b/dev/advanced/parallel/index.html @@ -9,4 +9,4 @@ Graphs.dijkstra_shortest_paths(g, [1,2]) Parallel.dijkstra_shortest_paths(g, [1,2]) # this doesn't -Parallel.dijkstra_shortest_paths(g,1)

Note that after importing or using Graphs.Parallel, you must fully qualify the version of the function you wish to use (using, e.g., Graphs.betweenness_centrality(g) for the sequential version and Parallel.betweenness_centrality(g) for the parallel version).

Available parallel algorithms

The following is a current list of parallel algorithms:

Also note that in some cases, the arguments for the parallel versions may differ from the serial (standard) versions. As an example, parallel Dijkstra shortest paths takes advantage of multiple processors to execute centrality from multiple source vertices. It is an error to pass a single source vertex into the parallel version of dijkstrashortestpaths.

Index

Full docs

Graphs.Parallel.distr_generate_reduceMethod
distr_generate_min_set(g, gen_func, comp, reps)

Distributed implementation of generate_reduce.

source
Graphs.Parallel.generate_reduceMethod
generate_reduce(g, gen_func, comp, reps; parallel=:threads)

Compute gen_func(g) reps times and return the instance best for which comp(best, v) is true where v is all the other instances of gen_func(g).

For example, comp(x, y) = length(x) < length(y) ? x : y then instance with the smallest length will be returned.

source
Graphs.Parallel.threaded_generate_reduceMethod
threaded_generate_reduce(g, gen_func, comp reps)

Multi-threaded implementation of generate_reduce.

source
Graphs.Parallel.dominating_setMethod
dominating_set(g, reps, MinimalDominatingSet(); parallel=:threads, rng=nothing, seed=nothing)

Perform Graphs.dominating_set(g, MinimalDominatingSet()) reps times in parallel and return the solution with the fewest vertices.

Optional Arguments

  • parallel=:threads: If parallel=:distributed then the multiprocessor implementation is

used. This implementation is more efficient if reps is large.

  • If seed >= 0, a random generator of each process/thread is seeded with this value.
source
Graphs.Parallel.independent_setMethod
independent_set(g, reps, MaximalIndependentSet(); parallel=:threads, rng=nothing, seed=nothing)

Perform Graphs.independent_set(g, MaximalIndependentSet()) reps times in parallel and return the solution with the most vertices.

Optional Arguments

  • parallel=:threads: If parallel=:distributed then the multiprocessor implementation is

used. This implementation is more efficient if reps is large.

source
Graphs.Parallel.MultipleDijkstraStateType
struct Parallel.MultipleDijkstraState{T, U}

An AbstractPathState designed for Parallel.dijkstrashortestpaths calculation.

source
Graphs.Parallel.dijkstra_shortest_pathsMethod
Parallel.dijkstra_shortest_paths(g, sources=vertices(g), distmx=weights(g))

Compute the shortest paths between all pairs of vertices in graph g by running [dijkstra_shortest_paths] for every vertex and using an optional list of source vertex sources and an optional distance matrix distmx. Return a Parallel.MultipleDijkstraState with relevant traversal information.

source
Graphs.Parallel.ThreadQueueType
ThreadQueue

A thread safe queue implementation for using as the queue for BFS.

source
Graphs.Parallel.bfs_tree!Method
bfs_tree!(g, src, parents)

Provide a parallel breadth-first traversal of the graph g starting with source vertex s, and return a parents array. The returned array is an Array of Atomic integers.

Implementation Notes

This function uses @threads for parallelism which depends on the JULIA_NUM_THREADS environment variable to decide the number of threads to use. Refer @threads documentation for more details.

source
Graphs.Parallel.vertex_coverMethod
vertex_cover(g, reps, RandomVertexCover(); parallel=:threads, rng=nothing, seed=nothing)

Perform Graphs.vertex_cover(g, RandomVertexCover()) reps times in parallel and return the solution with the fewest vertices.

Optional Arguements

  • parallel=:threads: If parallel=:distributed then the multiprocessor implementation is

used. This implementation is more efficient if reps is large.

source
+Parallel.dijkstra_shortest_paths(g,1)

Note that after importing or using Graphs.Parallel, you must fully qualify the version of the function you wish to use (using, e.g., Graphs.betweenness_centrality(g) for the sequential version and Parallel.betweenness_centrality(g) for the parallel version).

Available parallel algorithms

The following is a current list of parallel algorithms:

Also note that in some cases, the arguments for the parallel versions may differ from the serial (standard) versions. As an example, parallel Dijkstra shortest paths takes advantage of multiple processors to execute centrality from multiple source vertices. It is an error to pass a single source vertex into the parallel version of dijkstrashortestpaths.

Index

Full docs

Graphs.Parallel.distr_generate_reduceMethod
distr_generate_min_set(g, gen_func, comp, reps)

Distributed implementation of generate_reduce.

source
Graphs.Parallel.generate_reduceMethod
generate_reduce(g, gen_func, comp, reps; parallel=:threads)

Compute gen_func(g) reps times and return the instance best for which comp(best, v) is true where v is all the other instances of gen_func(g).

For example, comp(x, y) = length(x) < length(y) ? x : y then instance with the smallest length will be returned.

source
Graphs.Parallel.threaded_generate_reduceMethod
threaded_generate_reduce(g, gen_func, comp reps)

Multi-threaded implementation of generate_reduce.

source
Graphs.Parallel.dominating_setMethod
dominating_set(g, reps, MinimalDominatingSet(); parallel=:threads, rng=nothing, seed=nothing)

Perform Graphs.dominating_set(g, MinimalDominatingSet()) reps times in parallel and return the solution with the fewest vertices.

Optional Arguments

  • parallel=:threads: If parallel=:distributed then the multiprocessor implementation is

used. This implementation is more efficient if reps is large.

  • If seed >= 0, a random generator of each process/thread is seeded with this value.
source
Graphs.Parallel.independent_setMethod
independent_set(g, reps, MaximalIndependentSet(); parallel=:threads, rng=nothing, seed=nothing)

Perform Graphs.independent_set(g, MaximalIndependentSet()) reps times in parallel and return the solution with the most vertices.

Optional Arguments

  • parallel=:threads: If parallel=:distributed then the multiprocessor implementation is

used. This implementation is more efficient if reps is large.

source
Graphs.Parallel.MultipleDijkstraStateType
struct Parallel.MultipleDijkstraState{T, U}

An AbstractPathState designed for Parallel.dijkstrashortestpaths calculation.

source
Graphs.Parallel.dijkstra_shortest_pathsMethod
Parallel.dijkstra_shortest_paths(g, sources=vertices(g), distmx=weights(g))

Compute the shortest paths between all pairs of vertices in graph g by running [dijkstra_shortest_paths] for every vertex and using an optional list of source vertex sources and an optional distance matrix distmx. Return a Parallel.MultipleDijkstraState with relevant traversal information.

source
Graphs.Parallel.ThreadQueueType
ThreadQueue

A thread safe queue implementation for using as the queue for BFS.

source
Graphs.Parallel.bfs_tree!Method
bfs_tree!(g, src, parents)

Provide a parallel breadth-first traversal of the graph g starting with source vertex s, and return a parents array. The returned array is an Array of Atomic integers.

Implementation Notes

This function uses @threads for parallelism which depends on the JULIA_NUM_THREADS environment variable to decide the number of threads to use. Refer @threads documentation for more details.

source
Graphs.Parallel.vertex_coverMethod
vertex_cover(g, reps, RandomVertexCover(); parallel=:threads, rng=nothing, seed=nothing)

Perform Graphs.vertex_cover(g, RandomVertexCover()) reps times in parallel and return the solution with the fewest vertices.

Optional Arguements

  • parallel=:threads: If parallel=:distributed then the multiprocessor implementation is

used. This implementation is more efficient if reps is large.

source
diff --git a/dev/advanced/test/index.html b/dev/advanced/test/index.html index 1235021e..4ea887a5 100644 --- a/dev/advanced/test/index.html +++ b/dev/advanced/test/index.html @@ -1,2 +1,2 @@ -Test graphs · Graphs.jl

Test graphs

Graphs.Test is a module containing generic graph structures which make as few hypotheses as possible beyond the basic interface. It is not part of the public API and may break unexpectedly.

Index

Full docs

Graphs.TestModule
Graphs.Test

A module that provides utilities for testing functions that should work with any Graphs.AbstractGraph.

source
Graphs.Test.GenericDiGraphType
GenericDiGraph{T} <: Graphs.AbstractGraph{T}

A directed graph type that can be used to tests functions that relay on the Graphs.jl interface.

source
Graphs.Test.GenericEdgeType
GenericEdge <: Graphs.AbstractEdge

An edge type that can be used to tests functions that relay on the Graphs.jl interface.

source
Graphs.Test.GenericGraphType
GenericGraph{T} <: Graphs.AbstractGraph{T}

An undirected graph type that can be used to tests functions that relay on the Graphs.jl interface.

source
Graphs.Test.generic_graphMethod
generic_graph(g::Union{SimpleGraph, SimpleDiGraph})

Return either a GenericGraph or GenericDiGraph that wraps a copy of g.

source
+Test graphs · Graphs.jl

Test graphs

Graphs.Test is a module containing generic graph structures which make as few hypotheses as possible beyond the basic interface. It is not part of the public API and may break unexpectedly.

Index

Full docs

Graphs.TestModule
Graphs.Test

A module that provides utilities for testing functions that should work with any Graphs.AbstractGraph.

source
Graphs.Test.GenericDiGraphType
GenericDiGraph{T} <: Graphs.AbstractGraph{T}

A directed graph type that can be used to tests functions that relay on the Graphs.jl interface.

source
Graphs.Test.GenericEdgeType
GenericEdge <: Graphs.AbstractEdge

An edge type that can be used to tests functions that relay on the Graphs.jl interface.

source
Graphs.Test.GenericGraphType
GenericGraph{T} <: Graphs.AbstractGraph{T}

An undirected graph type that can be used to tests functions that relay on the Graphs.jl interface.

source
Graphs.Test.generic_graphMethod
generic_graph(g::Union{SimpleGraph, SimpleDiGraph})

Return either a GenericGraph or GenericDiGraph that wraps a copy of g.

source
diff --git a/dev/algorithms/biconnectivity/index.html b/dev/algorithms/biconnectivity/index.html index 21297c9a..53f87077 100644 --- a/dev/algorithms/biconnectivity/index.html +++ b/dev/algorithms/biconnectivity/index.html @@ -9,7 +9,7 @@ 3-element Vector{Int64}: 2 3 - 4source
Graphs.BiconnectionsType
Biconnections

A state type for depth-first search that finds the biconnected components.

source
Graphs.biconnected_componentsFunction
biconnected_components(g) -> Vector{Vector{Edge{eltype(g)}}}

Compute the biconnected components of an undirected graph gand return a vector of vectors containing each biconnected component.

Performance: Time complexity is $\mathcal{O}(|V|)$.

Examples

julia> using Graphs
+ 4
source
Graphs.BiconnectionsType
Biconnections

A state type for depth-first search that finds the biconnected components.

source
Graphs.biconnected_componentsFunction
biconnected_components(g) -> Vector{Vector{Edge{eltype(g)}}}

Compute the biconnected components of an undirected graph gand return a vector of vectors containing each biconnected component.

Performance: Time complexity is $\mathcal{O}(|V|)$.

Examples

julia> using Graphs
 
 julia> biconnected_components(star_graph(5))
 4-element Vector{Vector{Graphs.SimpleGraphs.SimpleEdge{Int64}}}:
@@ -20,7 +20,7 @@
 
 julia> biconnected_components(cycle_graph(5))
 1-element Vector{Vector{Graphs.SimpleGraphs.SimpleEdge{Int64}}}:
- [Edge 1 => 5, Edge 4 => 5, Edge 3 => 4, Edge 2 => 3, Edge 1 => 2]
source
Graphs.visit!Method
visit!(g, state, u, v)

Perform a DFS visit storing the depth and low-points of each vertex.

source
Graphs.bridgesFunction
bridges(g)

Compute the bridges of a connected graph g and return an array containing all bridges, i.e edges whose deletion increases the number of connected components of the graph.

Examples

julia> using Graphs
+ [Edge 1 => 5, Edge 4 => 5, Edge 3 => 4, Edge 2 => 3, Edge 1 => 2]
source
Graphs.visit!Method
visit!(g, state, u, v)

Perform a DFS visit storing the depth and low-points of each vertex.

source
Graphs.bridgesFunction
bridges(g)

Compute the bridges of a connected graph g and return an array containing all bridges, i.e edges whose deletion increases the number of connected components of the graph.

Examples

julia> using Graphs
 
 julia> bridges(star_graph(5))
 4-element Vector{Graphs.SimpleGraphs.SimpleEdge{Int64}}:
@@ -34,4 +34,4 @@
  Edge 4 => 5
  Edge 3 => 4
  Edge 2 => 3
- Edge 1 => 2
source
+ Edge 1 => 2source diff --git a/dev/algorithms/centrality/index.html b/dev/algorithms/centrality/index.html index 25dec87e..eb586fa0 100644 --- a/dev/algorithms/centrality/index.html +++ b/dev/algorithms/centrality/index.html @@ -13,7 +13,7 @@ 0.0 0.6666666666666666 0.6666666666666666 - 0.0source
Graphs.closeness_centralityFunction
closeness_centrality(g, distmx=weights(g); normalize=true)

Calculate the closeness centrality of the graph g. Return a vector representing the centrality calculated for each node in g.

Optional Arguments

  • normalize=true: If true, normalize the centrality value of each

node n by $\frac{|δ_n|}{|V|-1}$, where $δ_n$ is the set of vertices reachable from node n.

Examples

julia> using Graphs
+ 0.0
source
Graphs.closeness_centralityFunction
closeness_centrality(g, distmx=weights(g); normalize=true)

Calculate the closeness centrality of the graph g. Return a vector representing the centrality calculated for each node in g.

Optional Arguments

  • normalize=true: If true, normalize the centrality value of each

node n by $\frac{|δ_n|}{|V|-1}$, where $δ_n$ is the set of vertices reachable from node n.

Examples

julia> using Graphs
 
 julia> closeness_centrality(star_graph(5))
 5-element Vector{Float64}:
@@ -28,7 +28,7 @@
  0.5
  0.75
  0.75
- 0.5
source
Graphs.degree_centralityMethod
degree_centrality(g)
+ 0.5
source
Graphs.degree_centralityMethod
degree_centrality(g)
 indegree_centrality(g)
 outdegree_centrality(g)

Calculate the degree centrality of graph g. Return a vector representing the centrality calculated for each node in g.

Optional Arguments

  • normalize=true: If true, normalize each centrality measure by $\frac{1}{|V|-1}$.

Examples

julia> using Graphs
 
@@ -43,7 +43,7 @@
 3-element Vector{Float64}:
  0.5
  1.0
- 0.5
source
Graphs.eigenvector_centralityMethod
eigenvector_centrality(g)

Compute the eigenvector centrality for the graph g.

Eigenvector centrality computes the centrality for a node based on the centrality of its neighbors. The eigenvector centrality for node i is the $i^{th}$ element of $\mathbf{x}$ in the equation $\mathbf{Ax} = λ \mathbf{x}$ where $\mathbf{A}$ is the adjacency matrix of the graph g with eigenvalue λ.

By virtue of the Perron–Frobenius theorem, there is a unique and positive solution if λ is the largest eigenvalue associated with the eigenvector of the adjacency matrix $\mathbf{A}$.

References

  • Phillip Bonacich: Power and Centrality: A Family of Measures. American Journal of Sociology 92(5):1170–1182, 1986 http://www.leonidzhukov.net/hse/2014/socialnetworks/papers/Bonacich-Centrality.pdf
  • Mark E. J. Newman: Networks: An Introduction. Oxford University Press, USA, 2010, pp. 169.
source
Graphs.katz_centralityFunction
katz_centrality(g, α=0.3)

Calculate the Katz centrality of the graph g optionally parameterized by α. Return a vector representing the centrality calculated for each node in g.

source
Graphs.pagerankMethod
pagerank(g, α=0.85, n=100, ϵ=1.0e-6)

Calculate the PageRank of the graph g parameterized by damping factor α, number of iterations n, and convergence threshold ϵ. Return a vector representing the centrality calculated for each node in g, or an error if convergence is not reached within n iterations.

source
Graphs.radiality_centralityMethod
radiality_centrality(g)

Calculate the radiality centrality of a graph g across all vertices. Return a vector representing the centrality calculated for each node in g.

The radiality centrality $R_u$ of a vertex $u$ is defined as $R_u = \frac{D_g + 1 - \frac{\sum_{v∈V}d_{u,v}}{|V|-1}}{D_g}$

where $D_g$ is the diameter of the graph and $d_{u,v}$ is the length of the shortest path from $u$ to $v$.

References

  • Brandes, U.: A faster algorithm for betweenness centrality. J Math Sociol 25 (2001) 163-177

Examples

julia> using Graphs
+ 0.5
source
Graphs.eigenvector_centralityMethod
eigenvector_centrality(g)

Compute the eigenvector centrality for the graph g.

Eigenvector centrality computes the centrality for a node based on the centrality of its neighbors. The eigenvector centrality for node i is the $i^{th}$ element of $\mathbf{x}$ in the equation $\mathbf{Ax} = λ \mathbf{x}$ where $\mathbf{A}$ is the adjacency matrix of the graph g with eigenvalue λ.

By virtue of the Perron–Frobenius theorem, there is a unique and positive solution if λ is the largest eigenvalue associated with the eigenvector of the adjacency matrix $\mathbf{A}$.

References

  • Phillip Bonacich: Power and Centrality: A Family of Measures. American Journal of Sociology 92(5):1170–1182, 1986 http://www.leonidzhukov.net/hse/2014/socialnetworks/papers/Bonacich-Centrality.pdf
  • Mark E. J. Newman: Networks: An Introduction. Oxford University Press, USA, 2010, pp. 169.
source
Graphs.katz_centralityFunction
katz_centrality(g, α=0.3)

Calculate the Katz centrality of the graph g optionally parameterized by α. Return a vector representing the centrality calculated for each node in g.

source
Graphs.pagerankMethod
pagerank(g, α=0.85, n=100, ϵ=1.0e-6)

Calculate the PageRank of the graph g parameterized by damping factor α, number of iterations n, and convergence threshold ϵ. Return a vector representing the centrality calculated for each node in g, or an error if convergence is not reached within n iterations.

source
Graphs.radiality_centralityMethod
radiality_centrality(g)

Calculate the radiality centrality of a graph g across all vertices. Return a vector representing the centrality calculated for each node in g.

The radiality centrality $R_u$ of a vertex $u$ is defined as $R_u = \frac{D_g + 1 - \frac{\sum_{v∈V}d_{u,v}}{|V|-1}}{D_g}$

where $D_g$ is the diameter of the graph and $d_{u,v}$ is the length of the shortest path from $u$ to $v$.

References

  • Brandes, U.: A faster algorithm for betweenness centrality. J Math Sociol 25 (2001) 163-177

Examples

julia> using Graphs
 
 julia> radiality_centrality(star_graph(4))
 4-element Vector{Float64}:
@@ -56,7 +56,7 @@
 3-element Vector{Float64}:
  0.75
  1.0 
- 0.75
source
Graphs.stress_centralityFunction
stress_centrality(g[, vs])
+ 0.75
source
Graphs.stress_centralityFunction
stress_centrality(g[, vs])
 stress_centrality(g, k)

Calculate the stress centrality of a graph g across all vertices, a specified subset of vertices vs, or a random subset of k vertices. Return a vector representing the centrality calculated for each node in g.

The stress centrality of a vertex $n$ is defined as the number of shortest paths passing through $n$.

References

  • Barabási, A.L., Oltvai, Z.N.: Network biology: understanding the cell's functional organization. Nat Rev Genet 5 (2004) 101-113
  • Shimbel, A.: Structural parameters of communication networks. Bull Math Biophys 15 (1953) 501-507.

Examples

julia> using Graphs
 
 julia> stress_centrality(star_graph(3))
@@ -70,4 +70,4 @@
  2
  2
  2
- 2
source
+ 2source diff --git a/dev/algorithms/community/index.html b/dev/algorithms/community/index.html index 3671d0a9..46c5f484 100644 --- a/dev/algorithms/community/index.html +++ b/dev/algorithms/community/index.html @@ -2,7 +2,7 @@ Community structures · Graphs.jl

Community structures

Graphs.jl contains several algorithms to detect and analyze community structures.

Index

Full docs

Graphs.assortativityMethod
assortativity(g)

Return the assortativity coefficient of graph g, defined as the Pearson correlation of excess degree between the end vertices of all the edges of the graph.

The excess degree is equal to the degree of linked vertices minus one, i.e. discounting the edge that links the pair. In directed graphs, the paired values are the out-degree of source vertices and the in-degree of destination vertices.

Examples

julia> using Graphs
 
 julia> assortativity(star_graph(4))
--1.0
source
Graphs.clique_percolationFunction
clique_percolation(g, k=3)

Community detection using the clique percolation algorithm. Communities are potentially overlapping. Return a vector of vectors c such that c[i] is the set of vertices in community i. The parameter k defines the size of the clique to use in percolation.

References

Examples

julia> using Graphs
+-1.0
source
Graphs.clique_percolationFunction
clique_percolation(g, k=3)

Community detection using the clique percolation algorithm. Communities are potentially overlapping. Return a vector of vectors c such that c[i] is the set of vertices in community i. The parameter k defines the size of the clique to use in percolation.

References

Examples

julia> using Graphs
 
 julia> clique_percolation(clique_graph(3, 2))
 2-element Vector{BitSet}:
@@ -14,7 +14,7 @@
  BitSet([1, 2, 3, 4, 5, 6])
 
 julia> clique_percolation(clique_graph(3, 2), k=4)
-BitSet[]
source
Graphs.maximal_cliquesFunction
maximal_cliques(g)

Return a vector of vectors representing the node indices in each of the maximal cliques found in the undirected graph g.

julia> using Graphs
+BitSet[]
source
Graphs.maximal_cliquesFunction
maximal_cliques(g)

Return a vector of vectors representing the node indices in each of the maximal cliques found in the undirected graph g.

julia> using Graphs
 
 julia> g = SimpleGraph(3)
 {3, 0} undirected simple Int64 graph
@@ -28,14 +28,14 @@
 julia> maximal_cliques(g)
 2-element Vector{Vector{Int64}}:
  [2, 3]
- [2, 1]
source
Graphs.local_clusteringMethod
local_clustering(g, v)
-local_clustering(g, vs)

Return a tuple (a, b), where a is the number of triangles in the neighborhood of v and b is the maximum number of possible triangles. If a list of vertices vs is specified, return two vectors representing the number of triangles and the maximum number of possible triangles, respectively, for each node in the list.

This function is related to the local clustering coefficient r by $r=\frac{a}{b}$.

source
Graphs.local_clusteringMethod
local_clustering(g, v)
+local_clustering(g, vs)

Return a tuple (a, b), where a is the number of triangles in the neighborhood of v and b is the maximum number of possible triangles. If a list of vertices vs is specified, return two vectors representing the number of triangles and the maximum number of possible triangles, respectively, for each node in the list.

This function is related to the local clustering coefficient r by $r=\frac{a}{b}$.

source
Graphs.local_clustering_coefficientMethod
local_clustering_coefficient(g, v)
 local_clustering_coefficient(g, vs)

Return the local clustering coefficient for node v in graph g. If a list of vertices vs is specified, return a vector of coefficients for each node in the list.

Examples

julia> using Graphs
 
 julia> g = SimpleGraph(4);
@@ -50,7 +50,7 @@
 3-element Vector{Float64}:
  1.0
  1.0
- 0.0
source
Graphs.trianglesMethod
triangles(g[, v])
 triangles(g, vs)

Return the number of triangles in the neighborhood of node v in graph g. If a list of vertices vs is specified, return a vector of number of triangles for each node in the list. If no vertices are specified, return the number of triangles for each node in the graph.

Examples

julia> using Graphs
 
 julia> g = SimpleGraph(4);
@@ -66,7 +66,7 @@
  1
  1
  0
- 1
source
Graphs.core_periphery_degFunction
core_periphery_deg(g)

Compute the degree-based core-periphery for graph g. Return the vertex assignments (1 for core and 2 for periphery) for each node in g.

References: Lip)

Examples

julia> using Graphs
+ 1
source
Graphs.core_periphery_degFunction
core_periphery_deg(g)

Compute the degree-based core-periphery for graph g. Return the vertex assignments (1 for core and 2 for periphery) for each node in g.

References: Lip)

Examples

julia> using Graphs
 
 julia> core_periphery_deg(star_graph(5))
 5-element Vector{Int64}:
@@ -80,7 +80,7 @@
 3-element Vector{Int64}:
  2
  1
- 2
source
Graphs.label_propagationMethod
label_propagation(g, maxiter=1000; rng=nothing, seed=nothing)

Community detection using the label propagation algorithm. Return two vectors: the first is the label number assigned to each node, and the second is the convergence history for each node. Will return after maxiter iterations if convergence has not completed.

References

source
Graphs.vote!Method
vote!(rng, g, m, c, u)

Return the label with greatest frequency.

source
Graphs.modularityMethod
modularity(g, c, distmx=weights(g), γ=1.0)

Return a value representing Newman's modularity Q for the undirected and directed graph g given the partitioning vector c. This method also supports weighted graphs if the distance matrix is provided.

Modularity $Q$ for undirected graph:

\[Q = \frac{1}{2m} \sum_{c} \left( e_{c} - \gamma \frac{K_c^2}{2m} \right)\]

Modularity $Q$ for directed graph:

\[Q = \frac{1}{m} \sum_{c} \left( e_{c} - \gamma \frac{K_c^{in} K_c^{out}}{m} \right)\]

where:

  • $m$: total number of edges in the network
  • $e_c$: number of edges in community $c$
  • $K_c$: sum of the degrees of the nodes in community $c$ or the sum of the weighted degree of the nodes in community $c$ when the graph is weighted. $K_c^{in}$ sum of the in-degrees of the nodes in community $c$.

Optional Arguments

  • distmx=weights(g): distance matrix for weighted graphs
  • γ=1.0: where γ > 0 is a resolution parameter. When the modularity is used to find communities structure in networks (i.e with Louvain's method for community detection), higher resolutions lead to more communities, while lower resolutions lead to fewer communities. Where γ=1.0 it lead to the traditional definition of the modularity.

References

  • M. E. J. Newman and M. Girvan. "Finding and evaluating community structure in networks". Phys. Rev. E 69, 026113 (2004). (arXiv)
  • J. Reichardt and S. Bornholdt. "Statistical mechanics of community detection". Phys. Rev. E 74, 016110 (2006). (arXiv)
  • E. A. Leicht and M. E. J. Newman. "Community structure in directed networks". Physical Review Letter, 100:118703, (2008). (arXiv)

Examples

julia> using Graphs
+ 2
source
Graphs.label_propagationMethod
label_propagation(g, maxiter=1000; rng=nothing, seed=nothing)

Community detection using the label propagation algorithm. Return two vectors: the first is the label number assigned to each node, and the second is the convergence history for each node. Will return after maxiter iterations if convergence has not completed.

References

source
Graphs.vote!Method
vote!(rng, g, m, c, u)

Return the label with greatest frequency.

source
Graphs.modularityMethod
modularity(g, c, distmx=weights(g), γ=1.0)

Return a value representing Newman's modularity Q for the undirected and directed graph g given the partitioning vector c. This method also supports weighted graphs if the distance matrix is provided.

Modularity $Q$ for undirected graph:

\[Q = \frac{1}{2m} \sum_{c} \left( e_{c} - \gamma \frac{K_c^2}{2m} \right)\]

Modularity $Q$ for directed graph:

\[Q = \frac{1}{m} \sum_{c} \left( e_{c} - \gamma \frac{K_c^{in} K_c^{out}}{m} \right)\]

where:

  • $m$: total number of edges in the network
  • $e_c$: number of edges in community $c$
  • $K_c$: sum of the degrees of the nodes in community $c$ or the sum of the weighted degree of the nodes in community $c$ when the graph is weighted. $K_c^{in}$ sum of the in-degrees of the nodes in community $c$.

Optional Arguments

  • distmx=weights(g): distance matrix for weighted graphs
  • γ=1.0: where γ > 0 is a resolution parameter. When the modularity is used to find communities structure in networks (i.e with Louvain's method for community detection), higher resolutions lead to more communities, while lower resolutions lead to fewer communities. Where γ=1.0 it lead to the traditional definition of the modularity.

References

  • M. E. J. Newman and M. Girvan. "Finding and evaluating community structure in networks". Phys. Rev. E 69, 026113 (2004). (arXiv)
  • J. Reichardt and S. Bornholdt. "Statistical mechanics of community detection". Phys. Rev. E 74, 016110 (2006). (arXiv)
  • E. A. Leicht and M. E. J. Newman. "Community structure in directed networks". Physical Review Letter, 100:118703, (2008). (arXiv)

Examples

julia> using Graphs
 
 julia> barbell = blockdiag(complete_graph(3), complete_graph(3));
 
@@ -103,10 +103,10 @@
 julia> distmx[1, 4] = distmx[4, 1] = 5;  # additional edge has a weight of 5
 
 julia> round(modularity(barbell, [1, 1, 1, 2, 2, 2]; distmx), digits=6)
-0.045455
source
Graphs.rich_clubMethod
rich_club(g, k)

Return the non-normalised rich-club coefficient of graph g, with degree cut-off k.

julia> using Graphs
 
 julia> g = star_graph(5)
 {5, 4} undirected simple Int64 graph
 
 julia> rich_club(g, 1)
-0.4
source
+0.4source diff --git a/dev/algorithms/connectivity/index.html b/dev/algorithms/connectivity/index.html index 1f0c271d..bbb4028f 100644 --- a/dev/algorithms/connectivity/index.html +++ b/dev/algorithms/connectivity/index.html @@ -11,7 +11,7 @@ julia> attracting_components(g) 1-element Vector{Vector{Int64}}: - [4, 5]source
Graphs.componentsMethod
components(labels)

Given a vector of component labels, return a vector of vectors representing the vertices associated with a given component id.

source
Graphs.components_dictMethod
components_dict(labels)

Convert an array of labels to a map of component id to vertices, and return a map with each key corresponding to a given component id and each value containing the vertices associated with that component.

source
Graphs.condensationFunction
condensation(g[, scc])

Return the condensation graph of the strongly connected components scc in the directed graph g. If scc is missing, generate the strongly connected components first.

Examples

julia> using Graphs
+ [4, 5]
source
Graphs.componentsMethod
components(labels)

Given a vector of component labels, return a vector of vectors representing the vertices associated with a given component id.

source
Graphs.components_dictMethod
components_dict(labels)

Convert an array of labels to a map of component id to vertices, and return a map with each key corresponding to a given component id and each value containing the vertices associated with that component.

source
Graphs.condensationFunction
condensation(g[, scc])

Return the condensation graph of the strongly connected components scc in the directed graph g. If scc is missing, generate the strongly connected components first.

Examples

julia> using Graphs
 
 julia> g = SimpleDiGraph([0 1 0 0 0; 0 0 1 0 0; 1 0 0 1 0; 0 0 0 0 1; 0 0 0 1 0])
 {5, 6} directed simple Int64 graph
@@ -22,7 +22,7 @@
  [1, 2, 3]
 
 julia> foreach(println, edges(condensation(g)))
-Edge 2 => 1
source
Graphs.connected_components!Method
connected_components!(label, g)

Fill label with the id of the connected component in the undirected graph g to which it belongs. Return a vector representing the component assigned to each vertex. The component value is the smallest vertex ID in the component.

Performance

This algorithm is linear in the number of edges of the graph.

source
Graphs.connected_componentsMethod
connected_components(g)

Return the connected components of an undirected graph g as a vector of components, with each element a vector of vertices belonging to the component.

For directed graphs, see strongly_connected_components and weakly_connected_components.

Examples

julia> using Graphs
+Edge 2 => 1
source
Graphs.connected_components!Method
connected_components!(label, g)

Fill label with the id of the connected component in the undirected graph g to which it belongs. Return a vector representing the component assigned to each vertex. The component value is the smallest vertex ID in the component.

Performance

This algorithm is linear in the number of edges of the graph.

source
Graphs.connected_componentsMethod
connected_components(g)

Return the connected components of an undirected graph g as a vector of components, with each element a vector of vertices belonging to the component.

For directed graphs, see strongly_connected_components and weakly_connected_components.

Examples

julia> using Graphs
 
 julia> g = SimpleGraph([0 1 0; 1 0 1; 0 1 0]);
 
@@ -35,7 +35,7 @@
 julia> connected_components(g)
 2-element Vector{Vector{Int64}}:
  [1, 2, 3]
- [4, 5]
source
Graphs.is_connectedMethod
is_connected(g)

Return true if graph g is connected. For directed graphs, return true if graph g is weakly connected.

Examples

julia> using Graphs
+ [4, 5]
source
Graphs.is_connectedMethod
is_connected(g)

Return true if graph g is connected. For directed graphs, return true if graph g is weakly connected.

Examples

julia> using Graphs
 
 julia> g = SimpleGraph([0 1 0; 1 0 1; 0 1 0]);
 
@@ -50,12 +50,12 @@
 julia> g = SimpleDiGraph([0 1 0; 0 0 1; 1 0 0]);
 
 julia> is_connected(g)
-true
source
Graphs.is_strongly_connectedFunction
is_strongly_connected(g)

Return true if directed graph g is strongly connected.

Examples

julia> using Graphs
+true
source
Graphs.is_strongly_connectedFunction
is_strongly_connected(g)

Return true if directed graph g is strongly connected.

Examples

julia> using Graphs
 
 julia> g = SimpleDiGraph([0 1 0; 0 0 1; 1 0 0]);
 
 julia> is_strongly_connected(g)
-true
source
Graphs.is_weakly_connectedMethod
is_weakly_connected(g)

Return true if the graph g is weakly connected. If g is undirected, this function is equivalent to is_connected(g).

Examples

julia> using Graphs
+true
source
Graphs.is_weakly_connectedMethod
is_weakly_connected(g)

Return true if the graph g is weakly connected. If g is undirected, this function is equivalent to is_connected(g).

Examples

julia> using Graphs
 
 julia> g = SimpleDiGraph([0 1 0; 0 0 1; 1 0 0]);
 
@@ -71,7 +71,7 @@
 false
 
 julia> is_weakly_connected(g)
-true
source
Graphs.isdigraphicalMethod
isdigraphical(indegree_sequence, outdegree_sequence)

Check whether the given indegree sequence and outdegree sequence are digraphical, that is whether they can be the indegree and outdegree sequence of a simple digraph (i.e. a directed graph with no loops). This implies that indegree_sequence and outdegree_sequence are not independent, as their elements respectively represent the indegrees and outdegrees that the vertices shall have.

Implementation Notes

According to Fulkerson-Chen-Anstee theorem, a sequence $\{(a_1, b_1), ...,(a_n, b_n)\}$ (sorted in descending order of a) is graphic iff $\sum_{i = 1}^{n} a_i = \sum_{i = 1}^{n} b_i\}$ and the sequence obeys the property -

\[\sum_{i=1}^{r} a_i \leq \sum_{i=1}^n min(r-1,b_i) + \sum_{i=r+1}^n min(r,b_i)\]

for each integer 1 <= r <= n-1.

See also: isgraphical

source
Graphs.isgraphicalMethod
isgraphical(degs)

Return true if the degree sequence degs is graphical. A sequence of integers is called graphical, if there exists a graph where the degrees of its vertices form that same sequence.

Performance

Time complexity: $\mathcal{O}(|degs|*\log(|degs|))$.

Implementation Notes

According to Erdös-Gallai theorem, a degree sequence $\{d_1, ...,d_n\}$ (sorted in descending order) is graphic iff the sum of vertex degrees is even and the sequence obeys the property -

\[\sum_{i=1}^{r} d_i \leq r(r-1) + \sum_{i=r+1}^n min(r,d_i)\]

for each integer r <= n-1.

See also: isdigraphical

source
Graphs.neighborhoodMethod
neighborhood(g, v, d, distmx=weights(g))

Return a vector of each vertex in g at a geodesic distance less than or equal to d, where distances may be specified by distmx.

Optional Arguments

  • dir=:out: If g is directed, this argument specifies the edge direction

with respect to v of the edges to be considered. Possible values: :in or :out.

Examples

julia> using Graphs
+true
source
Graphs.isdigraphicalMethod
isdigraphical(indegree_sequence, outdegree_sequence)

Check whether the given indegree sequence and outdegree sequence are digraphical, that is whether they can be the indegree and outdegree sequence of a simple digraph (i.e. a directed graph with no loops). This implies that indegree_sequence and outdegree_sequence are not independent, as their elements respectively represent the indegrees and outdegrees that the vertices shall have.

Implementation Notes

According to Fulkerson-Chen-Anstee theorem, a sequence $\{(a_1, b_1), ...,(a_n, b_n)\}$ (sorted in descending order of a) is graphic iff $\sum_{i = 1}^{n} a_i = \sum_{i = 1}^{n} b_i\}$ and the sequence obeys the property -

\[\sum_{i=1}^{r} a_i \leq \sum_{i=1}^n min(r-1,b_i) + \sum_{i=r+1}^n min(r,b_i)\]

for each integer 1 <= r <= n-1.

See also: isgraphical

source
Graphs.isgraphicalMethod
isgraphical(degs)

Return true if the degree sequence degs is graphical. A sequence of integers is called graphical, if there exists a graph where the degrees of its vertices form that same sequence.

Performance

Time complexity: $\mathcal{O}(|degs|*\log(|degs|))$.

Implementation Notes

According to Erdös-Gallai theorem, a degree sequence $\{d_1, ...,d_n\}$ (sorted in descending order) is graphic iff the sum of vertex degrees is even and the sequence obeys the property -

\[\sum_{i=1}^{r} d_i \leq r(r-1) + \sum_{i=r+1}^n min(r,d_i)\]

for each integer r <= n-1.

See also: isdigraphical

source
Graphs.neighborhoodMethod
neighborhood(g, v, d, distmx=weights(g))

Return a vector of each vertex in g at a geodesic distance less than or equal to d, where distances may be specified by distmx.

Optional Arguments

  • dir=:out: If g is directed, this argument specifies the edge direction

with respect to v of the edges to be considered. Possible values: :in or :out.

Examples

julia> using Graphs
 
 julia> g = SimpleDiGraph([0 1 0 0 0; 0 0 1 0 0; 1 0 0 1 0; 0 0 0 0 1; 0 0 0 1 0]);
 
@@ -94,7 +94,7 @@
  2
  3
  4
- 5
source
Graphs.neighborhood_distsMethod
neighborhood_dists(g, v, d, distmx=weights(g))

Return a a vector of tuples representing each vertex which is at a geodesic distance less than or equal to d, along with its distance from v. Non-negative distances may be specified by distmx.

Optional Arguments

  • dir=:out: If g is directed, this argument specifies the edge direction

with respect to v of the edges to be considered. Possible values: :in or :out.

Examples

julia> using Graphs
+ 5
source
Graphs.neighborhood_distsMethod
neighborhood_dists(g, v, d, distmx=weights(g))

Return a a vector of tuples representing each vertex which is at a geodesic distance less than or equal to d, along with its distance from v. Non-negative distances may be specified by distmx.

Optional Arguments

  • dir=:out: If g is directed, this argument specifies the edge direction

with respect to v of the edges to be considered. Possible values: :in or :out.

Examples

julia> using Graphs
 
 julia> g = SimpleDiGraph([0 1 0 0 0; 0 0 1 0 0; 1 0 0 1 0; 0 0 0 0 1; 0 0 0 1 0]);
 
@@ -124,12 +124,12 @@
  (3, 1)
  (5, 1)
  (2, 2)
- (1, 3)
source
Graphs.periodFunction
period(g)

Return the (common) period for all vertices in a strongly connected directed graph. Will throw an error if the graph is not strongly connected.

Examples

julia> using Graphs
+ (1, 3)
source
Graphs.periodFunction
period(g)

Return the (common) period for all vertices in a strongly connected directed graph. Will throw an error if the graph is not strongly connected.

Examples

julia> using Graphs
 
 julia> g = SimpleDiGraph([0 1 0; 0 0 1; 1 0 0]);
 
 julia> period(g)
-3
source
Graphs.strongly_connected_componentsMethod
strongly_connected_components(g)

Compute the strongly connected components of a directed graph g.

Return an array of arrays, each of which is the entire connected component.

Implementation Notes

The order of the components is not part of the API contract.

Examples

julia> using Graphs
+3
source
Graphs.strongly_connected_componentsMethod
strongly_connected_components(g)

Compute the strongly connected components of a directed graph g.

Return an array of arrays, each of which is the entire connected component.

Implementation Notes

The order of the components is not part of the API contract.

Examples

julia> using Graphs
 
 julia> g = SimpleDiGraph([0 1 0; 1 0 1; 0 0 0]);
 
@@ -151,7 +151,7 @@
  [8, 9]
  [5, 6, 7]
  [1, 2, 3, 4]
- [10, 11]
source
Graphs.strongly_connected_components_kosarajuFunction
strongly_connected_components_kosaraju(g)

Compute the strongly connected components of a directed graph g using Kosaraju's Algorithm. (https://en.wikipedia.org/wiki/Kosaraju%27s_algorithm).

Return an array of arrays, each of which is the entire connected component.

Performance

Time Complexity : O(|E|+|V|) Space Complexity : O(|V|) {Excluding the memory required for storing graph}

|V| = Number of vertices |E| = Number of edges

Examples

julia> using Graphs
+ [10, 11]
source
Graphs.strongly_connected_components_kosarajuFunction
strongly_connected_components_kosaraju(g)

Compute the strongly connected components of a directed graph g using Kosaraju's Algorithm. (https://en.wikipedia.org/wiki/Kosaraju%27s_algorithm).

Return an array of arrays, each of which is the entire connected component.

Performance

Time Complexity : O(|E|+|V|) Space Complexity : O(|V|) {Excluding the memory required for storing graph}

|V| = Number of vertices |E| = Number of edges

Examples

julia> using Graphs
 
 julia> g=SimpleDiGraph(3)
 {3, 0} directed simple Int64 graph
@@ -194,7 +194,7 @@
  [2, 3, 4, 1]
  [6, 7, 5]
  [9, 8]
-
source
Graphs.strongly_connected_components_tarjanFunction
strongly_connected_components_tarjan(g)

Compute the strongly connected components of a directed graph g using Tarjan's algorithm.

Return an array of arrays, each of which is the entire connected component.

Implementation Notes

The returned components will be ordered reverse topologically.

Examples

julia> using Graphs
+
source
Graphs.strongly_connected_components_tarjanFunction
strongly_connected_components_tarjan(g)

Compute the strongly connected components of a directed graph g using Tarjan's algorithm.

Return an array of arrays, each of which is the entire connected component.

Implementation Notes

The returned components will be ordered reverse topologically.

Examples

julia> using Graphs
 
 julia> g = SimpleDiGraph([0 1 0; 1 0 1; 0 0 0]);
 
@@ -216,10 +216,10 @@
  [8, 9]
  [5, 6, 7]
  [1, 2, 3, 4]
- [10, 11]
source
Graphs.weakly_connected_componentsMethod
weakly_connected_components(g)

Return the weakly connected components of the graph g. This is equivalent to the connected components of the undirected equivalent of g. For undirected graphs this is equivalent to the connected_components of g.

Examples

julia> using Graphs
+ [10, 11]
source
Graphs.weakly_connected_componentsMethod
weakly_connected_components(g)

Return the weakly connected components of the graph g. This is equivalent to the connected components of the undirected equivalent of g. For undirected graphs this is equivalent to the connected_components of g.

Examples

julia> using Graphs
 
 julia> g = SimpleDiGraph([0 1 0; 1 0 1; 0 0 0]);
 
 julia> weakly_connected_components(g)
 1-element Vector{Vector{Int64}}:
- [1, 2, 3]
source
+ [1, 2, 3]source diff --git a/dev/algorithms/cut/index.html b/dev/algorithms/cut/index.html index 04dcab72..823b6245 100644 --- a/dev/algorithms/cut/index.html +++ b/dev/algorithms/cut/index.html @@ -1,2 +1,2 @@ -Cuts · Graphs.jl

Cuts

Graphs.jl implements several algorithms for graph cuts.

Index

Full docs

Graphs.karger_cut_costMethod
karger_cut_cost(g, cut)

Find the number of crossing edges in a cut of graph g where the cut is represented by the integer array, cut.

source
Graphs.karger_cut_edgesMethod
karger_cut_edges(g, cut)

Find the crossing edges in a cut of graph g where the cut is represented by the integer array, cut.

source
Graphs.karger_min_cutMethod
karger_min_cut(g)

Perform Karger Minimum Cut to find the minimum cut of graph g with some probability of success. A cut is a partition of vertices(g) into two non-empty sets. The size of a cut is the number of edges crossing the two non-empty sets.

Implementation Notes

The cut is represented by an integer array. If cut[v] == 1 then v is in the first non-empty set. If cut[v] == 2 then v is in the second non-empty set. cut[1] = 1.

If |V| < 2 then cut[v] = 0 for all v.

Performance

Runtime: O(|E|) Memory: O(|E|)

source
Graphs.normalized_cutMethod
normalized_cut(g, thres, distmx=weights(g), [num_cuts=10]);

Perform recursive two-way normalized graph-cut on a graph, partitioning the vertices into disjoint sets. Return a vector that contains the set index for each vertex.

It is important to identify a good threshold for your application. A bisection search over the range (0,1) will help determine a good value of thres.

Keyword Arguments

  • thres: Subgraphs aren't split if best normalized cut is above this threshold
  • num_cuts: Number of cuts performed to determine optimal cut

References

"Normalized Cuts and Image Segmentation" - Jianbo Shi and Jitendra Malik

source
+Cuts · Graphs.jl

Cuts

Graphs.jl implements several algorithms for graph cuts.

Index

Full docs

Graphs.karger_cut_costMethod
karger_cut_cost(g, cut)

Find the number of crossing edges in a cut of graph g where the cut is represented by the integer array, cut.

source
Graphs.karger_cut_edgesMethod
karger_cut_edges(g, cut)

Find the crossing edges in a cut of graph g where the cut is represented by the integer array, cut.

source
Graphs.karger_min_cutMethod
karger_min_cut(g)

Perform Karger Minimum Cut to find the minimum cut of graph g with some probability of success. A cut is a partition of vertices(g) into two non-empty sets. The size of a cut is the number of edges crossing the two non-empty sets.

Implementation Notes

The cut is represented by an integer array. If cut[v] == 1 then v is in the first non-empty set. If cut[v] == 2 then v is in the second non-empty set. cut[1] = 1.

If |V| < 2 then cut[v] = 0 for all v.

Performance

Runtime: O(|E|) Memory: O(|E|)

source
Graphs.normalized_cutMethod
normalized_cut(g, thres, distmx=weights(g), [num_cuts=10]);

Perform recursive two-way normalized graph-cut on a graph, partitioning the vertices into disjoint sets. Return a vector that contains the set index for each vertex.

It is important to identify a good threshold for your application. A bisection search over the range (0,1) will help determine a good value of thres.

Keyword Arguments

  • thres: Subgraphs aren't split if best normalized cut is above this threshold
  • num_cuts: Number of cuts performed to determine optimal cut

References

"Normalized Cuts and Image Segmentation" - Jianbo Shi and Jitendra Malik

source
diff --git a/dev/algorithms/cycles/index.html b/dev/algorithms/cycles/index.html index 1ba996d6..e3eaa86b 100644 --- a/dev/algorithms/cycles/index.html +++ b/dev/algorithms/cycles/index.html @@ -1,5 +1,5 @@ -Cycles · Graphs.jl

Cycles

Graphs.jl contains numerous algorithms related to cycles.

Index

Full docs

Graphs.cycle_basisFunction
cycle_basis(g, root=nothing)

Return a list of cycles which form a basis for cycles of the undirected graph g, optionally starting at node root.

A basis for cycles of a network is a minimal collection of cycles such that any cycle in the network can be written as a sum of cycles in the basis. Here summation of cycles is defined as "exclusive or" of the edges. Cycle bases are useful, e.g. when deriving equations for electric circuits using Kirchhoff's Laws.

Examples

julia> using Graphs
+Cycles · Graphs.jl

Cycles

Graphs.jl contains numerous algorithms related to cycles.

Index

Full docs

Graphs.cycle_basisFunction
cycle_basis(g, root=nothing)

Return a list of cycles which form a basis for cycles of the undirected graph g, optionally starting at node root.

A basis for cycles of a network is a minimal collection of cycles such that any cycle in the network can be written as a sum of cycles in the basis. Here summation of cycles is defined as "exclusive or" of the edges. Cycle bases are useful, e.g. when deriving equations for electric circuits using Kirchhoff's Laws.

Examples

julia> using Graphs
 
 julia> elist = [(1,2),(2,3),(2,4),(3,4),(4,1),(1,5)];
 
@@ -8,7 +8,7 @@
 julia> cycle_basis(g)
 2-element Vector{Vector{Int64}}:
  [2, 4, 1]
- [2, 3, 4]

References

  • Paton, K. An algorithm for finding a fundamental set of cycles of a graph. Comm. ACM 12, 9 (Sept 1969), 514-518. [https://dl.acm.org/citation.cfm?id=363232]
source
Graphs.simplecycles_hawick_jamesFunction
simplecycles_hawick_james(g)

Find circuits (including self-loops) in g using the algorithm of Hawick & James.

References

  • Hawick & James, "Enumerating Circuits and Loops in Graphs with Self-Arcs and Multiple-Arcs", 2008
source
Graphs.unblock!Method
unblock!(v, blocked, B)

Unblock the value v from the blocked list and remove from B.

source
Graphs.DenseGraphICT_BFGT_NType
struct DenseGraphICT_BFGT_N

Implements the "Naive" (Algorithm N) Bender-Fineman-Gilbert-Tarjan one-way line search incremental cycle detector for dense graphs from BFGT15 (Section 3).

References

BFGT15: Michael A. Bender, Jeremy T. Fineman, Seth Gilbert, and Robert E. Tarjan. 2015 A New Approach to Incremental Cycle Detection and Related Problems. ACM Trans. Algorithms 12, 2, Article 14 (December 2015), 22 pages. DOI: http://dx.doi.org/10.1145/2756553

source
Graphs.IncrementalCycleTrackerType
abstract type IncrementalCycleTracker

The supertype for incremental cycle detection problems. The abstract type constructor IncrementalCycleTracker(G) may be used to automatically select a specific incremental cycle detection algorithm. See add_edge_checked! for a usage example.

source
Graphs.TransactionalVectorType
struct TransactionalVector

A vector with one checkpoint that may be reverted to by calling revert!. The setpoint itself is set by calling commit!.

source
Graphs.add_edge_checked!Function
add_edge_checked!([f!,], ict::IncrementalCycleTracker, v, w)

Using the incremental cycle tracker, ict, check whether adding the edge v=>w would introduce a cycle in the underlying graph. If so, return false and leave the ict intact. If not, update the underlying graph and return true.

Optional f! Argument

By default the add_edge! function is used to update the underlying graph. However, for more complicated graphs, users may wish to manually specify the graph update operation. This may be accomplished by passing the optional f! callback argument. This callback is called on the underlying graph when no cycle is detected and is required to modify the underlying graph in order to effectuate the proposed edge addition.

Batched edge additions

Optionally, either v or w (depending on the in_out_reverse flag) may be a collection of vertices representing a batched addition of vertices sharing a common source or target more efficiently than individual updates.

Example

julia> using Graphs
+ [2, 3, 4]

References

  • Paton, K. An algorithm for finding a fundamental set of cycles of a graph. Comm. ACM 12, 9 (Sept 1969), 514-518. [https://dl.acm.org/citation.cfm?id=363232]
source
Graphs.simplecycles_hawick_jamesFunction
simplecycles_hawick_james(g)

Find circuits (including self-loops) in g using the algorithm of Hawick & James.

References

  • Hawick & James, "Enumerating Circuits and Loops in Graphs with Self-Arcs and Multiple-Arcs", 2008
source
Graphs.unblock!Method
unblock!(v, blocked, B)

Unblock the value v from the blocked list and remove from B.

source
Graphs.DenseGraphICT_BFGT_NType
struct DenseGraphICT_BFGT_N

Implements the "Naive" (Algorithm N) Bender-Fineman-Gilbert-Tarjan one-way line search incremental cycle detector for dense graphs from BFGT15 (Section 3).

References

BFGT15: Michael A. Bender, Jeremy T. Fineman, Seth Gilbert, and Robert E. Tarjan. 2015 A New Approach to Incremental Cycle Detection and Related Problems. ACM Trans. Algorithms 12, 2, Article 14 (December 2015), 22 pages. DOI: http://dx.doi.org/10.1145/2756553

source
Graphs.IncrementalCycleTrackerType
abstract type IncrementalCycleTracker

The supertype for incremental cycle detection problems. The abstract type constructor IncrementalCycleTracker(G) may be used to automatically select a specific incremental cycle detection algorithm. See add_edge_checked! for a usage example.

source
Graphs.TransactionalVectorType
struct TransactionalVector

A vector with one checkpoint that may be reverted to by calling revert!. The setpoint itself is set by calling commit!.

source
Graphs.add_edge_checked!Function
add_edge_checked!([f!,], ict::IncrementalCycleTracker, v, w)

Using the incremental cycle tracker, ict, check whether adding the edge v=>w would introduce a cycle in the underlying graph. If so, return false and leave the ict intact. If not, update the underlying graph and return true.

Optional f! Argument

By default the add_edge! function is used to update the underlying graph. However, for more complicated graphs, users may wish to manually specify the graph update operation. This may be accomplished by passing the optional f! callback argument. This callback is called on the underlying graph when no cycle is detected and is required to modify the underlying graph in order to effectuate the proposed edge addition.

Batched edge additions

Optionally, either v or w (depending on the in_out_reverse flag) may be a collection of vertices representing a batched addition of vertices sharing a common source or target more efficiently than individual updates.

Example

julia> using Graphs
 
 julia> G = SimpleDiGraph(3)
 {3, 0} directed simple Int64 graph
@@ -37,16 +37,16 @@
 julia> collect(edges(G))
 2-element Vector{Graphs.SimpleGraphs.SimpleEdge{Int64}}:
  Edge 1 => 2
- Edge 2 => 3
source
Graphs.JohnsonVisitorType
type JohnsonVisitor{T<:Integer} <: Visitor{T}
     stack::Vector{T}
     blocked::BitVector
     blockedmap::Vector{Set{T}}
 end
 
 JohnsonVisitor(dg::::IsDirected)
-

Composite type that regroups the information needed for Johnson's algorithm.

stack is the stack of visited vertices. blocked is a boolean for each vertex that tells whether it is blocked or not. blockedmap tells which vertices to unblock if the key vertex is unblocked.

JohnsonVisitor may also be constructed directly from the directed graph.

source
Graphs.circuitFunction
circuit{T<:Integer}(v::T, dg::::IsDirected, vis::JohnsonVisitor{T},
-allcycles::Vector{Vector{T}}, vmap::Vector{T}, startnode::T = v)

Return one step of the recursive version of simple cycle detection, using a DFS algorithm.

  • v: the vertex considered in this iteration of the DFS
  • dg: the digraph from which cycles are computed
  • visitor: Informations needed for the cycle computation, contains:
    • stack: the stack of parent vertices
    • blocked: tells whether a vertex has already been explored or not
    • blockedmap: mapping of the blocking / unblocking consequences
  • allcycles: output containing the cycles already detected
  • vmap: vector map containing the link from the old to the new nodes of the directed graph
  • startnode = v: optional argument giving the starting node. In the first iteration,

the same as v, otherwise it should be passed.

Implementation Notes

Implements Johnson's CIRCUIT function. This is a recursive version. Modifies the vector of cycles, when needed.

References

source
Graphs.circuit_iterFunction
circuit_iter{T<:Integer}(v::T, dg::::IsDirected, vis::JohnsonVisitor{T},
-vmap::Vector{T}, cycle::Channel, startnode::T = v)

Execute one step of the recursive version of simple cycle detection, using a DFS algorithm. Return true if a circuit has been found in the current exploration.

Arguments

  • v: the vertex considered in this iteration of the DFS
  • dg: the digraph from which cycles are computed
  • visitor: information needed for the cycle computation, contains:
    • stack: the stack of parent vertices
    • blocked: tells whether a vertex has already been explored or not
    • blockedmap: mapping of the blocking / unblocking consequences
  • vmap: vector map containing the link from the old to the new nodes of the directed graph
  • cycle: storage of the channel
  • startnode = v: optional argument giving the starting node. In the first iteration,

the same as v, otherwise it should be passed.

Implementation Notes

Implements the CIRCUIT function from Johnson's algorithm, recursive and iterative version. Produces a cycle when needed. Can be used only inside a Channel.

References

source
Graphs.itercyclesFunction
itercycles(dg::::IsDirected, cycle::Channel)

Compute all cycles of the given directed graph, using Johnson's algorithm.

Implementation Notes

Iterative version of the algorithm, using Channels to stop the exploration after a given number of cycles.

References

source
Graphs.maxsimplecyclesFunction
maxsimplecycles(dg::::IsDirected, byscc::Bool = true)

Compute the theoretical maximum number of cycles in the directed graph dg.

The computation can be performed assuming the graph is complete or taking into account the decomposition in strongly connected components (byscc parameter).

Performance

A more efficient version is possible.

References

source
Graphs.maxsimplecyclesMethod
maxsimplecycles(n::Integer)

Compute the theoretical maximum number of cycles in a directed graph of n vertices, assuming there are no self-loops.

References

source
Graphs.ncycles_n_iMethod
ncycles_n_i(n::Integer, i::Integer)

Compute the theoretical maximum number of cycles of size i in a directed graph of n vertices.

source
Graphs.simplecyclesFunction
simplecycles(dg::::IsDirected)

Compute and return all cycles of the given directed graph using Johnson's algorithm.

Performance

The number of cycles grows more than exponentially with the number of vertices, you might want to use the algorithm with a ceiling – simplecycles_iter – on large directed graphs (slightly slower). If you want to have an idea of the possible number of cycles, look at function maxsimplecycles(dg::DiGraph, byscc::Bool = true). If you only need short cycles of a limited length, simplecycles_limited_length can be more efficient.

References

Examples

julia> using Graphs
+

Composite type that regroups the information needed for Johnson's algorithm.

stack is the stack of visited vertices. blocked is a boolean for each vertex that tells whether it is blocked or not. blockedmap tells which vertices to unblock if the key vertex is unblocked.

JohnsonVisitor may also be constructed directly from the directed graph.

source
Graphs.circuitFunction
circuit{T<:Integer}(v::T, dg::::IsDirected, vis::JohnsonVisitor{T},
+allcycles::Vector{Vector{T}}, vmap::Vector{T}, startnode::T = v)

Return one step of the recursive version of simple cycle detection, using a DFS algorithm.

  • v: the vertex considered in this iteration of the DFS
  • dg: the digraph from which cycles are computed
  • visitor: Informations needed for the cycle computation, contains:
    • stack: the stack of parent vertices
    • blocked: tells whether a vertex has already been explored or not
    • blockedmap: mapping of the blocking / unblocking consequences
  • allcycles: output containing the cycles already detected
  • vmap: vector map containing the link from the old to the new nodes of the directed graph
  • startnode = v: optional argument giving the starting node. In the first iteration,

the same as v, otherwise it should be passed.

Implementation Notes

Implements Johnson's CIRCUIT function. This is a recursive version. Modifies the vector of cycles, when needed.

References

source
Graphs.circuit_iterFunction
circuit_iter{T<:Integer}(v::T, dg::::IsDirected, vis::JohnsonVisitor{T},
+vmap::Vector{T}, cycle::Channel, startnode::T = v)

Execute one step of the recursive version of simple cycle detection, using a DFS algorithm. Return true if a circuit has been found in the current exploration.

Arguments

  • v: the vertex considered in this iteration of the DFS
  • dg: the digraph from which cycles are computed
  • visitor: information needed for the cycle computation, contains:
    • stack: the stack of parent vertices
    • blocked: tells whether a vertex has already been explored or not
    • blockedmap: mapping of the blocking / unblocking consequences
  • vmap: vector map containing the link from the old to the new nodes of the directed graph
  • cycle: storage of the channel
  • startnode = v: optional argument giving the starting node. In the first iteration,

the same as v, otherwise it should be passed.

Implementation Notes

Implements the CIRCUIT function from Johnson's algorithm, recursive and iterative version. Produces a cycle when needed. Can be used only inside a Channel.

References

source
Graphs.itercyclesFunction
itercycles(dg::::IsDirected, cycle::Channel)

Compute all cycles of the given directed graph, using Johnson's algorithm.

Implementation Notes

Iterative version of the algorithm, using Channels to stop the exploration after a given number of cycles.

References

source
Graphs.maxsimplecyclesFunction
maxsimplecycles(dg::::IsDirected, byscc::Bool = true)

Compute the theoretical maximum number of cycles in the directed graph dg.

The computation can be performed assuming the graph is complete or taking into account the decomposition in strongly connected components (byscc parameter).

Performance

A more efficient version is possible.

References

source
Graphs.maxsimplecyclesMethod
maxsimplecycles(n::Integer)

Compute the theoretical maximum number of cycles in a directed graph of n vertices, assuming there are no self-loops.

References

source
Graphs.ncycles_n_iMethod
ncycles_n_i(n::Integer, i::Integer)

Compute the theoretical maximum number of cycles of size i in a directed graph of n vertices.

source
Graphs.simplecyclesFunction
simplecycles(dg::::IsDirected)

Compute and return all cycles of the given directed graph using Johnson's algorithm.

Performance

The number of cycles grows more than exponentially with the number of vertices, you might want to use the algorithm with a ceiling – simplecycles_iter – on large directed graphs (slightly slower). If you want to have an idea of the possible number of cycles, look at function maxsimplecycles(dg::DiGraph, byscc::Bool = true). If you only need short cycles of a limited length, simplecycles_limited_length can be more efficient.

References

Examples

julia> using Graphs
 
 julia> simplecycles(complete_digraph(3))
 5-element Vector{Vector{Int64}}:
@@ -54,13 +54,13 @@
  [1, 2, 3]
  [1, 3]
  [1, 3, 2]
- [2, 3]
source
Graphs.simplecycles_iterFunction
simplecycles_iter(dg::DiGraph, ceiling = 10^6)

Search all cycles of the given directed graph, using Johnson's algorithm, up to the ceiling (to avoid memory overload).

Implementation Notes

If the graph is small, the ceiling will not be reached and simplecycles(dg::DiGraph) is more efficient. It avoids the overhead of the counting and testing if the ceiling is reached. It returns all the cycles of the directed graph if the ceiling is not reached, a subset of them otherwise.

To get an idea of the possible number of cycles, use function `maxsimplecycles(dg::DiGraph, byscc::Bool = true) on the directed graph.

References

source
Graphs.simplecyclescountFunction
simplecyclescount(dg::DiGraph, ceiling = 10^6)

Count the number of cycles in a directed graph, using Johnson's algorithm. Return the minimum of the ceiling and the number of cycles.

Implementation Notes

The ceiling is here to avoid memory overload if there are a lot of cycles in the graph. Default value is 10^6, but it can be higher or lower. You can use the function maxsimplecycles(dg::DiGraph, byscc::Bool = true) to get an idea of the theoretical maximum number or cycles.

References

Examples

julia> using Graphs
+ [2, 3]
source
Graphs.simplecycles_iterFunction
simplecycles_iter(dg::DiGraph, ceiling = 10^6)

Search all cycles of the given directed graph, using Johnson's algorithm, up to the ceiling (to avoid memory overload).

Implementation Notes

If the graph is small, the ceiling will not be reached and simplecycles(dg::DiGraph) is more efficient. It avoids the overhead of the counting and testing if the ceiling is reached. It returns all the cycles of the directed graph if the ceiling is not reached, a subset of them otherwise.

To get an idea of the possible number of cycles, use function `maxsimplecycles(dg::DiGraph, byscc::Bool = true) on the directed graph.

References

source
Graphs.simplecyclescountFunction
simplecyclescount(dg::DiGraph, ceiling = 10^6)

Count the number of cycles in a directed graph, using Johnson's algorithm. Return the minimum of the ceiling and the number of cycles.

Implementation Notes

The ceiling is here to avoid memory overload if there are a lot of cycles in the graph. Default value is 10^6, but it can be higher or lower. You can use the function maxsimplecycles(dg::DiGraph, byscc::Bool = true) to get an idea of the theoretical maximum number or cycles.

References

Examples

julia> using Graphs
 
 julia> simplecyclescount(complete_digraph(6))
-409
source
Graphs.simplecycleslengthFunction
simplecycleslength(dg::DiGraph, ceiling = 10^6)

Search all cycles of the given directed graph, using Johnson's algorithm, and return a tuple representing the cycle length and the number of cycles.

Implementation Notes

To get an idea of the possible number of cycles, using function maxsimplecycles(dg::DiGraph, byscc::Bool = true) on the directed graph.

If the ceiling is reached (ncycles = ceiling), the output is only a subset of the cycles lengths.

References

Examples

julia> using Graphs
+409
source
Graphs.simplecycleslengthFunction
simplecycleslength(dg::DiGraph, ceiling = 10^6)

Search all cycles of the given directed graph, using Johnson's algorithm, and return a tuple representing the cycle length and the number of cycles.

Implementation Notes

To get an idea of the possible number of cycles, using function maxsimplecycles(dg::DiGraph, byscc::Bool = true) on the directed graph.

If the ceiling is reached (ncycles = ceiling), the output is only a subset of the cycles lengths.

References

Examples

julia> using Graphs
 
 julia> simplecycleslength(complete_digraph(16))
 ([0, 1, 1, 1, 1, 1, 2, 10, 73, 511, 3066, 15329, 61313, 183939, 367876, 367876], 1000000)
 
 julia> simplecycleslength(wheel_digraph(16))
-([0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 1, 0], 1)
source
Graphs.unblock!Method
unblock!{T<:Integer}(v::T, blocked::BitVector, B::Vector{Set{T}})

Unblock the vertices recursively.

v is the vertex to unblock, blocked tells whether a vertex is blocked or not and B is the map that tells if the unblocking of one vertex should unblock other vertices.

source
Graphs.simplecycles_limited_lengthMethod
simplecycles_limited_length(g, n, ceiling=10^6)

Compute and return at most ceiling cycles of length at most n of the given graph. Both directed and undirected graphs are supported.

Performance

The number of cycles grows very fast with the number of vertices and the allowed length of the cycles. This function is intended for finding short cycles. If you want to find cycles of any length in a directed graph, simplecycles or simplecycles_iter may be more efficient.

source
+([0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 1, 0], 1)
source
Graphs.unblock!Method
unblock!{T<:Integer}(v::T, blocked::BitVector, B::Vector{Set{T}})

Unblock the vertices recursively.

v is the vertex to unblock, blocked tells whether a vertex is blocked or not and B is the map that tells if the unblocking of one vertex should unblock other vertices.

source
Graphs.simplecycles_limited_lengthMethod
simplecycles_limited_length(g, n, ceiling=10^6)

Compute and return at most ceiling cycles of length at most n of the given graph. Both directed and undirected graphs are supported.

Performance

The number of cycles grows very fast with the number of vertices and the allowed length of the cycles. This function is intended for finding short cycles. If you want to find cycles of any length in a directed graph, simplecycles or simplecycles_iter may be more efficient.

source
diff --git a/dev/algorithms/degeneracy/index.html b/dev/algorithms/degeneracy/index.html index 1e7833b6..dc2a2d94 100644 --- a/dev/algorithms/degeneracy/index.html +++ b/dev/algorithms/degeneracy/index.html @@ -14,7 +14,7 @@ 2 2 2 - 0source
Graphs.k_coreFunction
k_core(g[, k]; corenum=core_number(g))

Return a vector of vertices in the k-core of graph g. If k is not specified, return the core with the largest degree.

A k-core is a maximal subgraph that contains vertices of degree k or more.

Implementation Notes

Not implemented for graphs with self loops.

References

  • An O(m) Algorithm for Cores Decomposition of Networks, Vladimir Batagelj and Matjaz Zaversnik, 2003. http://arxiv.org/abs/cs.DS/0310049

Examples

julia> using Graphs
+ 0
source
Graphs.k_coreFunction
k_core(g[, k]; corenum=core_number(g))

Return a vector of vertices in the k-core of graph g. If k is not specified, return the core with the largest degree.

A k-core is a maximal subgraph that contains vertices of degree k or more.

Implementation Notes

Not implemented for graphs with self loops.

References

  • An O(m) Algorithm for Cores Decomposition of Networks, Vladimir Batagelj and Matjaz Zaversnik, 2003. http://arxiv.org/abs/cs.DS/0310049

Examples

julia> using Graphs
 
 julia> g = path_graph(5);
 
@@ -35,7 +35,7 @@
  2
  3
  4
- 5
source
Graphs.k_coronaMethod
k_corona(g, k; corenum=core_number(g))

Return a vector of vertices in the k-corona of g.

The k-corona is the subgraph of vertices in the k-core which have exactly k neighbors in the k-core.

Implementation Notes

Not implemented for graphs with parallel edges or self loops.

References

  • k-core (bootstrap) percolation on complex networks: Critical phenomena and nonlocal effects, A. V. Goltsev, S. N. Dorogovtsev, and J. F. F. Mendes, Phys. Rev. E 73, 056101 (2006) http://link.aps.org/doi/10.1103/PhysRevE.73.056101

Examples

julia> using Graphs
+ 5
source
Graphs.k_coronaMethod
k_corona(g, k; corenum=core_number(g))

Return a vector of vertices in the k-corona of g.

The k-corona is the subgraph of vertices in the k-core which have exactly k neighbors in the k-core.

Implementation Notes

Not implemented for graphs with parallel edges or self loops.

References

  • k-core (bootstrap) percolation on complex networks: Critical phenomena and nonlocal effects, A. V. Goltsev, S. N. Dorogovtsev, and J. F. F. Mendes, Phys. Rev. E 73, 056101 (2006) http://link.aps.org/doi/10.1103/PhysRevE.73.056101

Examples

julia> using Graphs
 
 julia> g = path_graph(5);
 
@@ -59,7 +59,7 @@
  5
 
 julia> k_corona(g, 3)
-Int64[]
source
Graphs.k_crustFunction
k_crust(g[, k]; corenum=core_number(g))

Return a vector of vertices in the k-crust of g. If k is not specified, return the crust of the core with the largest degree.

The k-crust is the graph g with the k-core removed.

Implementation Notes

This definition of k-crust is different than the definition in References. The k-crust in References is equivalent to the k+1 crust of this algorithm.

Not implemented for graphs with self loops.

References

  • A model of Internet topology using k-shell decomposition Shai Carmi, Shlomo Havlin, Scott Kirkpatrick, Yuval Shavitt, and Eran Shir, PNAS July 3, 2007 vol. 104 no. 27 11150-11154 http://www.pnas.org/content/104/27/11150.full

Examples

julia> using Graphs
+Int64[]
source
Graphs.k_crustFunction
k_crust(g[, k]; corenum=core_number(g))

Return a vector of vertices in the k-crust of g. If k is not specified, return the crust of the core with the largest degree.

The k-crust is the graph g with the k-core removed.

Implementation Notes

This definition of k-crust is different than the definition in References. The k-crust in References is equivalent to the k+1 crust of this algorithm.

Not implemented for graphs with self loops.

References

  • A model of Internet topology using k-shell decomposition Shai Carmi, Shlomo Havlin, Scott Kirkpatrick, Yuval Shavitt, and Eran Shir, PNAS July 3, 2007 vol. 104 no. 27 11150-11154 http://www.pnas.org/content/104/27/11150.full

Examples

julia> using Graphs
 
 julia> g = path_graph(5);
 
@@ -83,7 +83,7 @@
  3
  4
  5
- 6
source
Graphs.k_shellFunction
k_shell(g[, k]; corenum=core_number(g))

Return a vector of vertices in the k-shell of g. If k is not specified, return the shell of the core with the largest degree.

The k-shell is the subgraph of vertices in the k-core but not in the (k+1)-core. This is similar to k_corona but in that case only neighbors in the k-core are considered.

Implementation Notes

Not implemented for graphs with parallel edges or self loops.

References

  • A model of Internet topology using k-shell decomposition Shai Carmi, Shlomo Havlin, Scott Kirkpatrick, Yuval Shavitt, and Eran Shir, PNAS July 3, 2007 vol. 104 no. 27 11150-11154 http://www.pnas.org/content/104/27/11150.full

Examples

julia> using Graphs
+ 6
source
Graphs.k_shellFunction
k_shell(g[, k]; corenum=core_number(g))

Return a vector of vertices in the k-shell of g. If k is not specified, return the shell of the core with the largest degree.

The k-shell is the subgraph of vertices in the k-core but not in the (k+1)-core. This is similar to k_corona but in that case only neighbors in the k-core are considered.

Implementation Notes

Not implemented for graphs with parallel edges or self loops.

References

  • A model of Internet topology using k-shell decomposition Shai Carmi, Shlomo Havlin, Scott Kirkpatrick, Yuval Shavitt, and Eran Shir, PNAS July 3, 2007 vol. 104 no. 27 11150-11154 http://www.pnas.org/content/104/27/11150.full

Examples

julia> using Graphs
 
 julia> g = path_graph(5);
 
@@ -104,4 +104,4 @@
  2
  3
  4
- 5
source
+ 5source diff --git a/dev/algorithms/digraph/index.html b/dev/algorithms/digraph/index.html index f46c12cf..9d4f7758 100644 --- a/dev/algorithms/digraph/index.html +++ b/dev/algorithms/digraph/index.html @@ -9,7 +9,7 @@ 13 julia> ne(transitiveclosure(barbell)) -21source
Graphs.transitiveclosure!Function
transitiveclosure!(g, selflooped=false)

Compute the transitive closure of a directed graph, using DFS. If selflooped is true, add self loops to the graph.

Performance

Time complexity is $\mathcal{O}(|E||V|)$.

Implementation Notes

This version of the function modifies the original graph.

source
Graphs.transitivereductionFunction
transitivereduction(g; selflooped=false)

Compute the transitive reduction of a directed graph. If the graph contains cycles, each strongly connected component is replaced by a directed cycle and the transitive reduction is calculated on the condensation graph connecting the components. If selflooped is true, self loops on strongly connected components of size one will be preserved.

Performance

Time complexity is $\mathcal{O}(|V||E|)$.

Examples

julia> using Graphs
+21
source
Graphs.transitiveclosure!Function
transitiveclosure!(g, selflooped=false)

Compute the transitive closure of a directed graph, using DFS. If selflooped is true, add self loops to the graph.

Performance

Time complexity is $\mathcal{O}(|E||V|)$.

Implementation Notes

This version of the function modifies the original graph.

source
Graphs.transitivereductionFunction
transitivereduction(g; selflooped=false)

Compute the transitive reduction of a directed graph. If the graph contains cycles, each strongly connected component is replaced by a directed cycle and the transitive reduction is calculated on the condensation graph connecting the components. If selflooped is true, self loops on strongly connected components of size one will be preserved.

Performance

Time complexity is $\mathcal{O}(|V||E|)$.

Examples

julia> using Graphs
 
 julia> barbell = blockdiag(complete_digraph(3), complete_digraph(3));
 
@@ -39,4 +39,4 @@
  Edge 3 => 1
  Edge 4 => 5
  Edge 5 => 6
- Edge 6 => 4
source
+ Edge 6 => 4source diff --git a/dev/algorithms/distance/index.html b/dev/algorithms/distance/index.html index bd1b272d..a3e92636 100644 --- a/dev/algorithms/distance/index.html +++ b/dev/algorithms/distance/index.html @@ -1,5 +1,5 @@ -Distance · Graphs.jl

Distance

Graphs.jl includes several distance measurements.

Index

Full docs

Graphs.DefaultDistanceType
DefaultDistance

An array-like structure that provides distance values of 1 for any src, dst combination.

source
Graphs.centerMethod
center(eccentricities)
+Distance · Graphs.jl

Distance

Graphs.jl includes several distance measurements.

Index

Full docs

Graphs.DefaultDistanceType
DefaultDistance

An array-like structure that provides distance values of 1 for any src, dst combination.

source
Graphs.centerMethod
center(eccentricities)
 center(g, distmx=weights(g))

Given a graph and optional distance matrix, or a vector of precomputed eccentricities, return the set of all vertices whose eccentricity is equal to the graph's radius (that is, the set of vertices with the smallest eccentricity).

Examples

julia> using Graphs
 
 julia> center(star_graph(5))
@@ -8,14 +8,14 @@
 
 julia> center(path_graph(5))
 1-element Vector{Int64}:
- 3
source
Graphs.diameterMethod
diameter(eccentricities)
 diameter(g, distmx=weights(g))

Given a graph and optional distance matrix, or a vector of precomputed eccentricities, return the maximum eccentricity of the graph.

Examples

julia> using Graphs
 
 julia> diameter(star_graph(5))
 2
 
 julia> diameter(path_graph(5))
-4
source
Graphs.eccentricityMethod
eccentricity(g[, v][, distmx])
 eccentricity(g[, vs][, distmx])

Return the eccentricity[ies] of a vertex / vertex list v or a set of vertices vs defaulting to the entire graph. An optional matrix of edge distances may be supplied; if missing, edge distances default to 1.

The eccentricity of a vertex is the maximum shortest-path distance between it and all other vertices in the graph.

The output is either a single float (when a single vertex is provided) or a vector of floats corresponding to the vertex vector. If no vertex vector is provided, the vector returned corresponds to each vertex in the graph.

Performance

Because this function must calculate shortest paths for all vertices supplied in the argument list, it may take a long time.

Implementation Notes

The eccentricity vector returned by eccentricity() may be used as input for the rest of the distance measures below. If an eccentricity vector is provided, it will be used. Otherwise, an eccentricity vector will be calculated for each call to the function. It may therefore be more efficient to calculate, store, and pass the eccentricities if multiple distance measures are desired.

An infinite path length is represented by the typemax of the distance matrix.

Examples

julia> using Graphs
 
 julia> g = SimpleGraph([0 1 0; 1 0 1; 0 1 0]);
@@ -31,7 +31,7 @@
 julia> eccentricity(g, [1; 2], [0 2 0; 0.5 0 0.5; 0 2 0])
 2-element Vector{Float64}:
  2.5
- 0.5
source
Graphs.peripheryMethod
periphery(eccentricities)
 periphery(g, distmx=weights(g))

Given a graph and optional distance matrix, or a vector of precomputed eccentricities, return the set of all vertices whose eccentricity is equal to the graph's diameter (that is, the set of vertices with the largest eccentricity).

Examples

julia> using Graphs
 
 julia> periphery(star_graph(5))
@@ -44,11 +44,11 @@
 julia> periphery(path_graph(5))
 2-element Vector{Int64}:
  1
- 5
source
Graphs.radiusMethod
radius(eccentricities)
 radius(g, distmx=weights(g))

Given a graph and optional distance matrix, or a vector of precomputed eccentricities, return the minimum eccentricity of the graph.

Examples

julia> using Graphs
 
 julia> radius(star_graph(5))
 1
 
 julia> radius(path_graph(5))
-2
source
+2
source
diff --git a/dev/algorithms/dominatingset/index.html b/dev/algorithms/dominatingset/index.html index f4352ad4..39fb7f97 100644 --- a/dev/algorithms/dominatingset/index.html +++ b/dev/algorithms/dominatingset/index.html @@ -1,2 +1,2 @@ -Dominating sets · Graphs.jl

Dominating sets

Graphs.jl implements functions for dominating sets.

Index

Full docs

Graphs.dominating_setMethod
dominating_set(g, DegreeDominatingSet())

Obtain a dominating set using a greedy heuristic.

Implementation Notes

A vertex is said to be dominated if it is in the dominating set or adjacent to a vertex in the dominating set. Initialise the dominating set to an empty set and iteratively choose the vertex that would dominate the most undominated vertices.

Performance

Runtime: $\mathcal{O}((|V|+|E|)*log(|V|))$ Memory: $\mathcal{O}(|V|)$ Approximation Factor: ln(maximum(degree(g)))+2

source
Graphs.update_dominated!Method
update_dominated!(degree_queue, v, dominated, in_dom_set)

Check if a vertex is already dominated. If not, make it dominated and update degree_queue by decreasing the priority of the vertices adjacent to v by 1.

source
Graphs.dominating_setMethod
dominating_set(g, MinimalDominatingSet(); rng=nothing, seed=nothing)

Find a set of vertices that constitutes a dominating set (all vertices in g are either adjacent to a vertex in the set or is a vertex in the set) and it is not possible to delete a vertex from the set without sacrificing the dominating property.

Implementation Notes

Initially, every vertex is in the dominating set. In some random order, we check if the removal of a vertex from the set will destroy the dominating property. If no, the vertex is removed from the dominating set.

Performance

Runtime: $\mathcal{O}(|V|+|E|)$ Memory: $\mathcal{O}(|V|)$

Optional Arguments

  • rng=nothing: set the Random Number Generator.
  • If seed >= 0, a random generator is seeded with this value.
source
+Dominating sets · Graphs.jl

Dominating sets

Graphs.jl implements functions for dominating sets.

Index

Full docs

Graphs.dominating_setMethod
dominating_set(g, DegreeDominatingSet())

Obtain a dominating set using a greedy heuristic.

Implementation Notes

A vertex is said to be dominated if it is in the dominating set or adjacent to a vertex in the dominating set. Initialise the dominating set to an empty set and iteratively choose the vertex that would dominate the most undominated vertices.

Performance

Runtime: $\mathcal{O}((|V|+|E|)*log(|V|))$ Memory: $\mathcal{O}(|V|)$ Approximation Factor: ln(maximum(degree(g)))+2

source
Graphs.update_dominated!Method
update_dominated!(degree_queue, v, dominated, in_dom_set)

Check if a vertex is already dominated. If not, make it dominated and update degree_queue by decreasing the priority of the vertices adjacent to v by 1.

source
Graphs.dominating_setMethod
dominating_set(g, MinimalDominatingSet(); rng=nothing, seed=nothing)

Find a set of vertices that constitutes a dominating set (all vertices in g are either adjacent to a vertex in the set or is a vertex in the set) and it is not possible to delete a vertex from the set without sacrificing the dominating property.

Implementation Notes

Initially, every vertex is in the dominating set. In some random order, we check if the removal of a vertex from the set will destroy the dominating property. If no, the vertex is removed from the dominating set.

Performance

Runtime: $\mathcal{O}(|V|+|E|)$ Memory: $\mathcal{O}(|V|)$

Optional Arguments

  • rng=nothing: set the Random Number Generator.
  • If seed >= 0, a random generator is seeded with this value.
source
diff --git a/dev/algorithms/editdist/index.html b/dev/algorithms/editdist/index.html index 4ce4910a..78285cd9 100644 --- a/dev/algorithms/editdist/index.html +++ b/dev/algorithms/editdist/index.html @@ -1,9 +1,9 @@ -Edit distance · Graphs.jl

Edit distance

Graphs.jl allows computation of the graph edit distance.

Index

Full docs

Graphs.BoundedMinkowskiCostMethod
BoundedMinkowskiCost(μ₁, μ₂)

Return value similar to MinkowskiCost, but ensure costs smaller than 2τ.

Optional Arguments

p=1: the p value for p-norm calculation. τ=1: value specifying half of the upper limit of the Minkowski cost.

source
Graphs.MinkowskiCostMethod
MinkowskiCost(μ₁, μ₂; p::Real=1)

For labels μ₁ on the vertices of graph G₁ and labels μ₂ on the vertices of graph G₂, compute the p-norm cost of substituting vertex u ∈ G₁ by vertex v ∈ G₂.

Optional Arguments

p=1: the p value for p-norm calculation.

source
Graphs.edit_distanceMethod
edit_distance(G₁::AbstractGraph, G₂::AbstractGraph)

Compute the edit distance between graphs G₁ and G₂. Return the minimum edit cost and edit path to transform graph G₁ into graph G₂. An edit path consists of a sequence of pairs of vertices(u,v) ∈ [0,|G₁|] × [0,|G₂|]` representing vertex operations:

  • $(0,v)$: insertion of vertex $v ∈ G₂$
  • $(u,0)$: deletion of vertex $u ∈ G₁$
  • $(u>0,v>0)$: substitution of vertex $u ∈ G₁$ by vertex $v ∈ G₂$

Optional Arguments

  • vertex_insert_cost::Function=v->0.
  • vertex_delete_cost::Function=u->0.
  • vertex_subst_cost::Function=(u, v)->0.
  • edge_insert_cost::Function=e->1.
  • edge_delete_cost::Function=e->1.
  • edge_subst_cost::Function=(e1, e2)->0.

The algorithm will always try to match two edges if it can, so if it is preferrable to delete two edges rather than match these, it should be reflected in the edge_subst_cost function.

By default, the algorithm uses constant operation costs. The user can provide classical Minkowski costs computed from vertex labels μ₁ (for G₁) and μ₂ (for G₂) in order to further guide the search, for example:

edit_distance(G₁, G₂, subst_cost=MinkowskiCost(μ₁, μ₂))
  • heuristic::Function=DefaultEditHeuristic: a custom heuristic provided to the A*

search in case the default heuristic is not satisfactory.

Performance

  • Given two graphs $|G₁| < |G₂|$, edit_distance(G₁, G₂) is faster to

compute than edit_distance(G₂, G₁). Consider swapping the arguments if involved costs are equivalent.

  • The use of a heuristic can improve performance considerably.
  • Exploit vertex attributes when designing operation costs.

References

  • RIESEN, K., 2015. Structural Pattern Recognition with Graph Edit Distance: Approximation Algorithms and Applications. (Chapter 2)

Author

  • Júlio Hoffimann Mendes (juliohm@stanford.edu)

Examples

julia> using Graphs
+Edit distance · Graphs.jl

Edit distance

Graphs.jl allows computation of the graph edit distance.

Index

Full docs

Graphs.BoundedMinkowskiCostMethod
BoundedMinkowskiCost(μ₁, μ₂)

Return value similar to MinkowskiCost, but ensure costs smaller than 2τ.

Optional Arguments

p=1: the p value for p-norm calculation. τ=1: value specifying half of the upper limit of the Minkowski cost.

source
Graphs.MinkowskiCostMethod
MinkowskiCost(μ₁, μ₂; p::Real=1)

For labels μ₁ on the vertices of graph G₁ and labels μ₂ on the vertices of graph G₂, compute the p-norm cost of substituting vertex u ∈ G₁ by vertex v ∈ G₂.

Optional Arguments

p=1: the p value for p-norm calculation.

source
Graphs.edit_distanceMethod
edit_distance(G₁::AbstractGraph, G₂::AbstractGraph)

Compute the edit distance between graphs G₁ and G₂. Return the minimum edit cost and edit path to transform graph G₁ into graph G₂. An edit path consists of a sequence of pairs of vertices(u,v) ∈ [0,|G₁|] × [0,|G₂|]` representing vertex operations:

  • $(0,v)$: insertion of vertex $v ∈ G₂$
  • $(u,0)$: deletion of vertex $u ∈ G₁$
  • $(u>0,v>0)$: substitution of vertex $u ∈ G₁$ by vertex $v ∈ G₂$

Optional Arguments

  • vertex_insert_cost::Function=v->0.
  • vertex_delete_cost::Function=u->0.
  • vertex_subst_cost::Function=(u, v)->0.
  • edge_insert_cost::Function=e->1.
  • edge_delete_cost::Function=e->1.
  • edge_subst_cost::Function=(e1, e2)->0.

The algorithm will always try to match two edges if it can, so if it is preferrable to delete two edges rather than match these, it should be reflected in the edge_subst_cost function.

By default, the algorithm uses constant operation costs. The user can provide classical Minkowski costs computed from vertex labels μ₁ (for G₁) and μ₂ (for G₂) in order to further guide the search, for example:

edit_distance(G₁, G₂, subst_cost=MinkowskiCost(μ₁, μ₂))
  • heuristic::Function=DefaultEditHeuristic: a custom heuristic provided to the A*

search in case the default heuristic is not satisfactory.

Performance

  • Given two graphs $|G₁| < |G₂|$, edit_distance(G₁, G₂) is faster to

compute than edit_distance(G₂, G₁). Consider swapping the arguments if involved costs are equivalent.

  • The use of a heuristic can improve performance considerably.
  • Exploit vertex attributes when designing operation costs.

References

  • RIESEN, K., 2015. Structural Pattern Recognition with Graph Edit Distance: Approximation Algorithms and Applications. (Chapter 2)

Author

  • Júlio Hoffimann Mendes (juliohm@stanford.edu)

Examples

julia> using Graphs
 
 julia> g1 = SimpleDiGraph([0 1 0 0 0; 0 0 1 0 0; 1 0 0 1 0; 0 0 0 0 1; 0 0 0 1 0]);
 
 julia> g2 = SimpleDiGraph([0 1 0; 0 0 1; 1 0 0]);
 
 julia> edit_distance(g1, g2)
-(3.0, Tuple[(1, 3), (2, 1), (3, 2), (4, 0), (5, 0)])
source
+(3.0, Tuple[(1, 3), (2, 1), (3, 2), (4, 0), (5, 0)])
source
diff --git a/dev/algorithms/independentset/index.html b/dev/algorithms/independentset/index.html index 2b445dee..80c4a5c6 100644 --- a/dev/algorithms/independentset/index.html +++ b/dev/algorithms/independentset/index.html @@ -1,2 +1,2 @@ -Independent sets · Graphs.jl

Independent sets

Graphs.jl contains functions related to independent sets.

Index

Full docs

Graphs.independent_setMethod
independent_set(g, DegreeIndependentSet())

Obtain an independent set of g using a greedy heuristic based on the degree of the vertices.

Implementation Notes

A vertex is said to be valid if it is not in the independent set or adjacent to any vertex in the independent set. Initilalise the independent set to an empty set and iteratively choose the vertex that is adjacent to the fewest valid vertices in the independent set until all vertices are invalid.

Performance

Runtime: O((|V|+|E|)*log(|V|)) Memory: O(|V|)

source
Graphs.independent_setMethod
independent_set(g, MaximalIndependentSet(); rng=nothing, seed=nothing)

Find a random set of vertices that are independent (no two vertices are adjacent to each other) and it is not possible to insert a vertex into the set without sacrificing the independence property.

Implementation Notes

Performs Approximate Maximum Independent Set once. Returns a vector of vertices representing the vertices in the independent set.

Performance

Runtime: O(|V|+|E|) Memory: O(|V|) Approximation Factor: maximum(degree(g))+1

Optional Arguments

  • rng=nothing: set the Random Number Generator.
  • If seed >= 0, a random generator is seeded with this value.
source
+Independent sets · Graphs.jl

Independent sets

Graphs.jl contains functions related to independent sets.

Index

Full docs

Graphs.independent_setMethod
independent_set(g, DegreeIndependentSet())

Obtain an independent set of g using a greedy heuristic based on the degree of the vertices.

Implementation Notes

A vertex is said to be valid if it is not in the independent set or adjacent to any vertex in the independent set. Initilalise the independent set to an empty set and iteratively choose the vertex that is adjacent to the fewest valid vertices in the independent set until all vertices are invalid.

Performance

Runtime: O((|V|+|E|)*log(|V|)) Memory: O(|V|)

source
Graphs.independent_setMethod
independent_set(g, MaximalIndependentSet(); rng=nothing, seed=nothing)

Find a random set of vertices that are independent (no two vertices are adjacent to each other) and it is not possible to insert a vertex into the set without sacrificing the independence property.

Implementation Notes

Performs Approximate Maximum Independent Set once. Returns a vector of vertices representing the vertices in the independent set.

Performance

Runtime: O(|V|+|E|) Memory: O(|V|) Approximation Factor: maximum(degree(g))+1

Optional Arguments

  • rng=nothing: set the Random Number Generator.
  • If seed >= 0, a random generator is seeded with this value.
source
diff --git a/dev/algorithms/iterators/index.html b/dev/algorithms/iterators/index.html index f42ce8b2..632d45c5 100644 --- a/dev/algorithms/iterators/index.html +++ b/dev/algorithms/iterators/index.html @@ -1,5 +1,5 @@ -Iterators · Graphs.jl

Iterators

Graphs.jl includes various routines for iterating through graphs.

Index

Full docs

Graphs.BFSIteratorType
BFSIterator(graph, source; depth_limit=nothing, neighbors_type=outneighbors)

BFSIterator is used to iterate through graph vertices using a breadth-first search. A source node(s) must be supplied as an Int or an array-like type that can be indexed if supplying multiple sources. It is also possible to specify a depth_limit which will stop the search once all nodes at that depth are visited and a neighbors_type which specifies what kind of neighbors of a node should be considered when exploring the graph.

Examples

julia> g = smallgraph(:house)
+Iterators · Graphs.jl

Iterators

Graphs.jl includes various routines for iterating through graphs.

Index

Full docs

Graphs.BFSIteratorType
BFSIterator(graph, source; depth_limit=nothing, neighbors_type=outneighbors)

BFSIterator is used to iterate through graph vertices using a breadth-first search. A source node(s) must be supplied as an Int or an array-like type that can be indexed if supplying multiple sources. It is also possible to specify a depth_limit which will stop the search once all nodes at that depth are visited and a neighbors_type which specifies what kind of neighbors of a node should be considered when exploring the graph.

Examples

julia> g = smallgraph(:house)
 {5, 6} undirected simple Int64 graph
 
 julia> for node in BFSIterator(g,3)
@@ -9,7 +9,7 @@
 1
 4
 5
-2
source
Graphs.DFSIteratorType
DFSIterator

DFSIterator is used to iterate through graph vertices using a depth-first search. A source node(s) is optionally supplied as an Int or an array-like type that can be indexed if supplying multiple sources.

Examples

julia> g = smallgraph(:house)
+2
source
Graphs.DFSIteratorType
DFSIterator

DFSIterator is used to iterate through graph vertices using a depth-first search. A source node(s) is optionally supplied as an Int or an array-like type that can be indexed if supplying multiple sources.

Examples

julia> g = smallgraph(:house)
 {5, 6} undirected simple Int64 graph
 
 julia> for node in DFSIterator(g, 3)
@@ -19,4 +19,4 @@
 2
 4
 3
-5
source

The following names are internals, not part of the public API:

Graphs.BFSVertexIteratorStateType
BFSVertexIteratorState

BFSVertexIteratorState is a struct to hold the current state of iteration in BFS which is needed for the Base.iterate() function. We use two vectors, one for the current level nodes and one from the next level nodes to visit the graph. Since new levels can contains repetitions of already visited nodes, we also keep track of that in a BitVector so as to skip those nodes.

source
Base.iterateMethod
Base.iterate(t::BFSIterator, state::VertexIteratorState)

Iterator to visit vertices in a graph using breadth-first search.

source
Base.iterateMethod
Base.iterate(t::BFSIterator)

First iteration to visit vertices in a graph using breadth-first search.

source
Graphs.DFSVertexIteratorStateType
DFSVertexIteratorState

DFSVertexIteratorState is a struct to hold the current state of iteration in DFS which is needed for the Base.iterate() function. A queue is used to keep track of the vertices which will be visited during DFS. Since the queue can contains repetitions of already visited nodes, we also keep track of that in a BitVector so that to skip those nodes.

source
Base.iterateMethod
Base.iterate(t::DFSIterator, state::VertexIteratorState)

Iterator to visit vertices in a graph using depth-first search.

source
Base.iterateMethod
Base.iterate(t::DFSIterator)

First iteration to visit vertices in a graph using depth-first search.

source
+5
source

The following names are internals, not part of the public API:

Graphs.BFSVertexIteratorStateType
BFSVertexIteratorState

BFSVertexIteratorState is a struct to hold the current state of iteration in BFS which is needed for the Base.iterate() function. We use two vectors, one for the current level nodes and one from the next level nodes to visit the graph. Since new levels can contains repetitions of already visited nodes, we also keep track of that in a BitVector so as to skip those nodes.

source
Base.iterateMethod
Base.iterate(t::BFSIterator, state::VertexIteratorState)

Iterator to visit vertices in a graph using breadth-first search.

source
Base.iterateMethod
Base.iterate(t::BFSIterator)

First iteration to visit vertices in a graph using breadth-first search.

source
Graphs.DFSVertexIteratorStateType
DFSVertexIteratorState

DFSVertexIteratorState is a struct to hold the current state of iteration in DFS which is needed for the Base.iterate() function. A queue is used to keep track of the vertices which will be visited during DFS. Since the queue can contains repetitions of already visited nodes, we also keep track of that in a BitVector so that to skip those nodes.

source
Base.iterateMethod
Base.iterate(t::DFSIterator, state::VertexIteratorState)

Iterator to visit vertices in a graph using depth-first search.

source
Base.iterateMethod
Base.iterate(t::DFSIterator)

First iteration to visit vertices in a graph using depth-first search.

source
diff --git a/dev/algorithms/linalg/index.html b/dev/algorithms/linalg/index.html index ae0231a2..731c99e9 100644 --- a/dev/algorithms/linalg/index.html +++ b/dev/algorithms/linalg/index.html @@ -1,2 +1,2 @@ -Linear algebra · Graphs.jl

Linear algebra

Graphs.jl provides numerous matrix operations on both directed and undirected graphs, as part of the LinAlg submodule.

Index

Full docs

Graphs.LinAlgModule
LinAlg

A package for using the type system to check types of graph matrices.

source
Graphs.LinAlg.AdjacencyType
Adjacency{T}

The core Adjacency matrix structure. Keeps the vertex degrees around. Subtypes are used to represent the different normalizations of the adjacency matrix. Laplacian and its subtypes are used for the different Laplacian matrices.

Adjacency(lapl::Laplacian) provides a generic function for getting the adjacency matrix of a Laplacian matrix. If your subtype of Laplacian does not provide a field A for the Adjacency instance, then attach another method to this function to provide an Adjacency{T} representation of the Laplacian. The Adjacency matrix here is the final subtype that corresponds to this type of Laplacian.

source
Graphs.LinAlg.NoopType
Noop

A type that represents no action.

Implementation Notes

  • The purpose of Noop is to help write more general code for the

different scaled GraphMatrix types.

source
Graphs.LinAlg.NormalizedAdjacencyType
NormalizedAdjacency{T}

The normalized adjacency matrix is $\hat{A} = D^{-1/2} A D^{-1/2}$. If A is symmetric, then the normalized adjacency is also symmetric with real eigenvalues bounded by [-1, 1].

source
Graphs.LinAlg.NormalizedLaplacianType
NormalizedLaplacian{T}

The normalized Laplacian is $\hat{L} = I - D^{-1/2} A D^{-1/2}$. If A is symmetric, then the normalized Laplacian is also symmetric with positive eigenvalues bounded by 2.

source
Graphs.LinAlg.symmetrizeFunction
symmetrize(A::SparseMatrix, which=:or)

Return a symmetric version of graph (represented by sparse matrix A) as a sparse matrix. which may be one of :triu, :tril, :sum, or :or. Use :sum for weighted graphs.

source
Graphs.LinAlg.NonbacktrackingType
Nonbacktracking{G}

A compact representation of the nonbacktracking operator.

The Nonbacktracking operator can be used for community detection. This representation is compact in that it uses only ne(g) additional storage and provides an implicit representation of the matrix B_g defined below.

Given two arcs $A_{i j}` and `A_{k l}` in `g`, the non-backtraking matrix$B`` is defined as

$B_{A_{i j}, A_{k l}} = δ_{j k} * (1 - δ_{i l})$

This type is in the style of GraphMatrices.jl and supports the necessary operations for computed eigenvectors and conducting linear solves.

Additionally the contract!(vertexspace, nbt, edgespace) method takes vectors represented in the domain of $B$ and represents them in the domain of the adjacency matrix of g.

source
Graphs.LinAlg.contract!Method
contract!(vertexspace, nbt, edgespace)

The mutating version of contract(nbt, edgespace). Modifies vertexspace.

source
Graphs.LinAlg.non_backtracking_matrixMethod
non_backtracking_matrix(g)

Return a non-backtracking matrix B and an edgemap storing the oriented edges' positions in B.

Given two arcs $A_{i j}` and `A_{k l}` in `g`, the non-backtracking matrix$B`` is defined as

$B_{A_{i j}, A_{k l}} = δ_{j k} * (1 - δ_{i l})$

source
Graphs.LinAlg.adjacency_matrixFunction
adjacency_matrix(g[, T=Int; dir=:out])

Return a sparse adjacency matrix for a graph, indexed by [u, v] vertices. Non-zero values indicate an edge from u to v. Users may override the default data type (Int) and specify an optional direction.

Optional Arguments

dir=:out: :in, :out, or :both are currently supported.

Implementation Notes

This function is optimized for speed and directly manipulates CSC sparse matrix fields.

source
Graphs.LinAlg.adjacency_spectrumFunction
adjacency_spectrum(g[, T=Int; dir=:unspec])

Return the eigenvalues of the adjacency matrix for a graph g, indexed by vertex. Default values for T are the same as those in adjacency_matrix.

Optional Arguments

dir=:unspec: Options for dir are the same as those in laplacian_matrix.

Performance

Converts the matrix to dense with $nv^2$ memory usage.

Implementation Notes

Use eigvals(Matrix(adjacency_matrix(g, args...))) to compute some of the eigenvalues/eigenvectors.

source
Graphs.LinAlg.incidence_matrixFunction
incidence_matrix(g[, T=Int; oriented=false])

Return a sparse node-arc incidence matrix for a graph, indexed by [v, i], where i is in 1:ne(g), indexing an edge e. For directed graphs, a value of -1 indicates that src(e) == v, while a value of 1 indicates that dst(e) == v. Otherwise, the value is 0. For undirected graphs, both entries are 1 by default (this behavior can be overridden by the oriented optional argument).

If oriented (default false) is true, for an undirected graph g, the matrix will contain arbitrary non-zero values representing connectivity between v and i.

source
Graphs.LinAlg.laplacian_matrixMethod
laplacian_matrix(g[, T=Int; dir=:unspec])

Return a sparse Laplacian matrix for a graph g, indexed by [u, v] vertices. T defaults to Int for both graph types.

Optional Arguments

dir=:unspec: :unspec, :both, :in, and :out are currently supported. For undirected graphs, dir defaults to :out; for directed graphs, dir defaults to :both.

source
Graphs.LinAlg.laplacian_spectrumFunction
laplacian_spectrum(g[, T=Int; dir=:unspec])

Return the eigenvalues of the Laplacian matrix for a graph g, indexed by vertex. Default values for T are the same as those in laplacian_matrix.

Optional Arguments

dir=:unspec: Options for dir are the same as those in laplacian_matrix.

Performance

Converts the matrix to dense with $nv^2$ memory usage.

Implementation Notes

Use eigvals(Matrix(laplacian_matrix(g, args...))) to compute some of the eigenvalues/eigenvectors.

source
Graphs.LinAlg.spectral_distanceFunction
spectral_distance(G₁, G₂ [, k])

Compute the spectral distance between undirected n-vertex graphs G₁ and G₂ using the top k greatest eigenvalues. If k is omitted, uses full spectrum.

References

  • JOVANOVIC, I.; STANIC, Z., 2014. Spectral Distances of Graphs Based on their Different Matrix Representations
source
+Linear algebra · Graphs.jl

Linear algebra

Graphs.jl provides numerous matrix operations on both directed and undirected graphs, as part of the LinAlg submodule.

Index

Full docs

Graphs.LinAlgModule
LinAlg

A package for using the type system to check types of graph matrices.

source
Graphs.LinAlg.AdjacencyType
Adjacency{T}

The core Adjacency matrix structure. Keeps the vertex degrees around. Subtypes are used to represent the different normalizations of the adjacency matrix. Laplacian and its subtypes are used for the different Laplacian matrices.

Adjacency(lapl::Laplacian) provides a generic function for getting the adjacency matrix of a Laplacian matrix. If your subtype of Laplacian does not provide a field A for the Adjacency instance, then attach another method to this function to provide an Adjacency{T} representation of the Laplacian. The Adjacency matrix here is the final subtype that corresponds to this type of Laplacian.

source
Graphs.LinAlg.NoopType
Noop

A type that represents no action.

Implementation Notes

  • The purpose of Noop is to help write more general code for the

different scaled GraphMatrix types.

source
Graphs.LinAlg.NormalizedAdjacencyType
NormalizedAdjacency{T}

The normalized adjacency matrix is $\hat{A} = D^{-1/2} A D^{-1/2}$. If A is symmetric, then the normalized adjacency is also symmetric with real eigenvalues bounded by [-1, 1].

source
Graphs.LinAlg.NormalizedLaplacianType
NormalizedLaplacian{T}

The normalized Laplacian is $\hat{L} = I - D^{-1/2} A D^{-1/2}$. If A is symmetric, then the normalized Laplacian is also symmetric with positive eigenvalues bounded by 2.

source
Graphs.LinAlg.symmetrizeFunction
symmetrize(A::SparseMatrix, which=:or)

Return a symmetric version of graph (represented by sparse matrix A) as a sparse matrix. which may be one of :triu, :tril, :sum, or :or. Use :sum for weighted graphs.

source
Graphs.LinAlg.NonbacktrackingType
Nonbacktracking{G}

A compact representation of the nonbacktracking operator.

The Nonbacktracking operator can be used for community detection. This representation is compact in that it uses only ne(g) additional storage and provides an implicit representation of the matrix B_g defined below.

Given two arcs $A_{i j}` and `A_{k l}` in `g`, the non-backtraking matrix$B`` is defined as

$B_{A_{i j}, A_{k l}} = δ_{j k} * (1 - δ_{i l})$

This type is in the style of GraphMatrices.jl and supports the necessary operations for computed eigenvectors and conducting linear solves.

Additionally the contract!(vertexspace, nbt, edgespace) method takes vectors represented in the domain of $B$ and represents them in the domain of the adjacency matrix of g.

source
Graphs.LinAlg.contract!Method
contract!(vertexspace, nbt, edgespace)

The mutating version of contract(nbt, edgespace). Modifies vertexspace.

source
Graphs.LinAlg.non_backtracking_matrixMethod
non_backtracking_matrix(g)

Return a non-backtracking matrix B and an edgemap storing the oriented edges' positions in B.

Given two arcs $A_{i j}` and `A_{k l}` in `g`, the non-backtracking matrix$B`` is defined as

$B_{A_{i j}, A_{k l}} = δ_{j k} * (1 - δ_{i l})$

source
Graphs.LinAlg.adjacency_matrixFunction
adjacency_matrix(g[, T=Int; dir=:out])

Return a sparse adjacency matrix for a graph, indexed by [u, v] vertices. Non-zero values indicate an edge from u to v. Users may override the default data type (Int) and specify an optional direction.

Optional Arguments

dir=:out: :in, :out, or :both are currently supported.

Implementation Notes

This function is optimized for speed and directly manipulates CSC sparse matrix fields.

source
Graphs.LinAlg.adjacency_spectrumFunction
adjacency_spectrum(g[, T=Int; dir=:unspec])

Return the eigenvalues of the adjacency matrix for a graph g, indexed by vertex. Default values for T are the same as those in adjacency_matrix.

Optional Arguments

dir=:unspec: Options for dir are the same as those in laplacian_matrix.

Performance

Converts the matrix to dense with $nv^2$ memory usage.

Implementation Notes

Use eigvals(Matrix(adjacency_matrix(g, args...))) to compute some of the eigenvalues/eigenvectors.

source
Graphs.LinAlg.incidence_matrixFunction
incidence_matrix(g[, T=Int; oriented=false])

Return a sparse node-arc incidence matrix for a graph, indexed by [v, i], where i is in 1:ne(g), indexing an edge e. For directed graphs, a value of -1 indicates that src(e) == v, while a value of 1 indicates that dst(e) == v. Otherwise, the value is 0. For undirected graphs, both entries are 1 by default (this behavior can be overridden by the oriented optional argument).

If oriented (default false) is true, for an undirected graph g, the matrix will contain arbitrary non-zero values representing connectivity between v and i.

source
Graphs.LinAlg.laplacian_matrixMethod
laplacian_matrix(g[, T=Int; dir=:unspec])

Return a sparse Laplacian matrix for a graph g, indexed by [u, v] vertices. T defaults to Int for both graph types.

Optional Arguments

dir=:unspec: :unspec, :both, :in, and :out are currently supported. For undirected graphs, dir defaults to :out; for directed graphs, dir defaults to :both.

source
Graphs.LinAlg.laplacian_spectrumFunction
laplacian_spectrum(g[, T=Int; dir=:unspec])

Return the eigenvalues of the Laplacian matrix for a graph g, indexed by vertex. Default values for T are the same as those in laplacian_matrix.

Optional Arguments

dir=:unspec: Options for dir are the same as those in laplacian_matrix.

Performance

Converts the matrix to dense with $nv^2$ memory usage.

Implementation Notes

Use eigvals(Matrix(laplacian_matrix(g, args...))) to compute some of the eigenvalues/eigenvectors.

source
Graphs.LinAlg.spectral_distanceFunction
spectral_distance(G₁, G₂ [, k])

Compute the spectral distance between undirected n-vertex graphs G₁ and G₂ using the top k greatest eigenvalues. If k is omitted, uses full spectrum.

References

  • JOVANOVIC, I.; STANIC, Z., 2014. Spectral Distances of Graphs Based on their Different Matrix Representations
source
diff --git a/dev/algorithms/shortestpaths/index.html b/dev/algorithms/shortestpaths/index.html index 71e916f8..e6b35466 100644 --- a/dev/algorithms/shortestpaths/index.html +++ b/dev/algorithms/shortestpaths/index.html @@ -1,6 +1,6 @@ -Shortest paths · Graphs.jl

Shortest paths

Graphs.jl includes standard algorithms for shortest paths and longest paths.

Index

Full docs

Graphs.a_starMethod
a_star(g, s, t[, distmx][, heuristic][, edgetype_to_return])

Compute a shortest path using the A* search algorithm.

Return a vector of edges.

Arguments

  • g::AbstractGraph: the graph
  • s::Integer: the source vertex
  • t::Integer: the target vertex
  • distmx::AbstractMatrix: an optional (possibly sparse) n × n matrix of edge weights. It is set to weights(g) by default (which itself falls back on Graphs.DefaultDistance).
  • heuristic: an optional function mapping each vertex to a lower estimate of the remaining distance from v to t. It is set to v -> 0 by default (which corresponds to Dijkstra's algorithm). Note that the heuristic values should have the same type as the edge weights!
  • edgetype_to_return::Type{E}: the type E<:AbstractEdge of the edges in the return vector. It is set to edgetype(g) by default. Note that the two-argument constructor E(u, v) must be defined, even for weighted edges: if it isn't, consider using E = Graphs.SimpleEdge.
Warning

Since a two-argument edge constructor E(u, v) is used to construct the path, metadata associated with the edge (like its weight) will be lost in the result. You might need to code a post-processing step yourself.

source
Graphs.BellmanFordStateType
BellmanFordState{T, U}

An AbstractPathState designed for Bellman-Ford shortest-paths calculations.

Fields

  • parents::Vector{U}: parents[v] is the predecessor of vertex v on the shortest path from the source to v
  • dists::Vector{T}: dists[v] is the length of the shortest path from the source to v
source
Graphs.enumerate_pathsMethod
enumerate_paths(state[, vs])

Given a path state state of type AbstractPathState, return a vector (indexed by vertex) of the paths between the source vertex used to compute the path state and a single destination vertex, a list of destination vertices, or the entire graph. For multiple destination vertices, each path is represented by a vector of vertices on the path between the source and the destination. Nonexistent paths will be indicated by an empty vector. For single destinations, the path is represented by a single vector of vertices, and will be length 0 if the path does not exist.

Implementation Notes

For Floyd-Warshall path states, please note that the output is a bit different, since this algorithm calculates all shortest paths for all pairs of vertices: enumerate_paths(state) will return a vector (indexed by source vertex) of vectors (indexed by destination vertex) of paths. enumerate_paths(state, v) will return a vector (indexed by destination vertex) of paths from source v to all other vertices. In addition, enumerate_paths(state, v, d) will return a vector representing the path from vertex v to vertex d.

source
Graphs.DEsopoPapeStateType
struct DEposoPapeState{T, U}

An AbstractPathState designed for D`Esopo-Pape shortest-path calculations.

Fields

  • parents::Vector{U}: parents[v] is the predecessor of vertex v on the shortest path from the source to v
  • dists::Vector{T}: dists[v] is the length of the shortest path from the source to v
source
Graphs.desopo_pape_shortest_pathsMethod
desopo_pape_shortest_paths(g, src, distmx=weights(g))

Compute shortest paths between a source src and all other nodes in graph g using the D'Esopo-Pape algorithm. Return a Graphs.DEsopoPapeState with relevant traversal information (try querying state.parents or state.dists).

Examples

julia> using Graphs
+Shortest paths · Graphs.jl

Shortest paths

Graphs.jl includes standard algorithms for shortest paths and longest paths.

Index

Full docs

Graphs.a_starMethod
a_star(g, s, t[, distmx][, heuristic][, edgetype_to_return])

Compute a shortest path using the A* search algorithm.

Return a vector of edges.

Arguments

  • g::AbstractGraph: the graph
  • s::Integer: the source vertex
  • t::Integer: the target vertex
  • distmx::AbstractMatrix: an optional (possibly sparse) n × n matrix of edge weights. It is set to weights(g) by default (which itself falls back on Graphs.DefaultDistance).
  • heuristic: an optional function mapping each vertex to a lower estimate of the remaining distance from v to t. It is set to v -> 0 by default (which corresponds to Dijkstra's algorithm). Note that the heuristic values should have the same type as the edge weights!
  • edgetype_to_return::Type{E}: the type E<:AbstractEdge of the edges in the return vector. It is set to edgetype(g) by default. Note that the two-argument constructor E(u, v) must be defined, even for weighted edges: if it isn't, consider using E = Graphs.SimpleEdge.
Warning

Since a two-argument edge constructor E(u, v) is used to construct the path, metadata associated with the edge (like its weight) will be lost in the result. You might need to code a post-processing step yourself.

source
Graphs.BellmanFordStateType
BellmanFordState{T, U}

An AbstractPathState designed for Bellman-Ford shortest-paths calculations.

Fields

  • parents::Vector{U}: parents[v] is the predecessor of vertex v on the shortest path from the source to v
  • dists::Vector{T}: dists[v] is the length of the shortest path from the source to v
source
Graphs.enumerate_pathsMethod
enumerate_paths(state[, vs])

Given a path state state of type AbstractPathState, return a vector (indexed by vertex) of the paths between the source vertex used to compute the path state and a single destination vertex, a list of destination vertices, or the entire graph. For multiple destination vertices, each path is represented by a vector of vertices on the path between the source and the destination. Nonexistent paths will be indicated by an empty vector. For single destinations, the path is represented by a single vector of vertices, and will be length 0 if the path does not exist.

Implementation Notes

For Floyd-Warshall path states, please note that the output is a bit different, since this algorithm calculates all shortest paths for all pairs of vertices: enumerate_paths(state) will return a vector (indexed by source vertex) of vectors (indexed by destination vertex) of paths. enumerate_paths(state, v) will return a vector (indexed by destination vertex) of paths from source v to all other vertices. In addition, enumerate_paths(state, v, d) will return a vector representing the path from vertex v to vertex d.

source
Graphs.DEsopoPapeStateType
struct DEposoPapeState{T, U}

An AbstractPathState designed for D`Esopo-Pape shortest-path calculations.

Fields

  • parents::Vector{U}: parents[v] is the predecessor of vertex v on the shortest path from the source to v
  • dists::Vector{T}: dists[v] is the length of the shortest path from the source to v
source
Graphs.desopo_pape_shortest_pathsMethod
desopo_pape_shortest_paths(g, src, distmx=weights(g))

Compute shortest paths between a source src and all other nodes in graph g using the D'Esopo-Pape algorithm. Return a Graphs.DEsopoPapeState with relevant traversal information (try querying state.parents or state.dists).

Examples

julia> using Graphs
 
 julia> ds = desopo_pape_shortest_paths(cycle_graph(5), 2);
 
@@ -20,7 +20,7 @@
  0
  1
  2
- 3
source
Graphs.DijkstraStateType
struct DijkstraState{T, U}

An AbstractPathState designed for Dijkstra shortest-paths calculations.

Fields

  • parents::Vector{U}
  • dists::Vector{T}
  • predecessors::Vector{Vector{U}}: a vector, indexed by vertex, of all the predecessors discovered during shortest-path calculations. This keeps track of all parents when there are multiple shortest paths available from the source.
  • pathcounts::Vector{Float64}: a vector, indexed by vertex, of the number of shortest paths from the source to that vertex. The path count of a source vertex is always 1.0. The path count of an unreached vertex is always 0.0.
  • closest_vertices::Vector{U}: a vector of all vertices in the graph ordered from closest to farthest.
source
Graphs.dijkstra_shortest_pathsMethod
dijkstra_shortest_paths(g, srcs, distmx=weights(g));

Perform Dijkstra's algorithm on a graph, computing shortest distances between srcs and all other vertices. Return a Graphs.DijkstraState that contains various traversal information (try querying state.parents or state.dists).

Optional Arguments

  • allpaths=false: If true, state.pathcounts holds a vector, indexed by vertex, of the number of shortest paths from the source to that vertex. The path count of a source vertex is always 1.0. The path count of an unreached vertex is always 0.0.
  • trackvertices=false: If true, state.closest_vertices holds a vector of all vertices in the graph ordered from closest to farthest.
  • maxdist (default: typemax(T)) specifies the maximum path distance beyond which all path distances are assumed to be infinite (that is, they do not exist).

Performance

If using a sparse matrix for distmx, you may achieve better performance by passing in a transpose of its sparse transpose. That is, assuming D is the sparse distance matrix:

D = transpose(sparse(transpose(D)))

Be aware that realizing the sparse transpose of D incurs a heavy one-time penalty, so this strategy should only be used when multiple calls to dijkstra_shortest_paths with the distance matrix are planned.

Examples

julia> using Graphs
+ 3
source
Graphs.DijkstraStateType
struct DijkstraState{T, U}

An AbstractPathState designed for Dijkstra shortest-paths calculations.

Fields

  • parents::Vector{U}
  • dists::Vector{T}
  • predecessors::Vector{Vector{U}}: a vector, indexed by vertex, of all the predecessors discovered during shortest-path calculations. This keeps track of all parents when there are multiple shortest paths available from the source.
  • pathcounts::Vector{Float64}: a vector, indexed by vertex, of the number of shortest paths from the source to that vertex. The path count of a source vertex is always 1.0. The path count of an unreached vertex is always 0.0.
  • closest_vertices::Vector{U}: a vector of all vertices in the graph ordered from closest to farthest.
source
Graphs.dijkstra_shortest_pathsMethod
dijkstra_shortest_paths(g, srcs, distmx=weights(g));

Perform Dijkstra's algorithm on a graph, computing shortest distances between srcs and all other vertices. Return a Graphs.DijkstraState that contains various traversal information (try querying state.parents or state.dists).

Optional Arguments

  • allpaths=false: If true, state.pathcounts holds a vector, indexed by vertex, of the number of shortest paths from the source to that vertex. The path count of a source vertex is always 1.0. The path count of an unreached vertex is always 0.0.
  • trackvertices=false: If true, state.closest_vertices holds a vector of all vertices in the graph ordered from closest to farthest.
  • maxdist (default: typemax(T)) specifies the maximum path distance beyond which all path distances are assumed to be infinite (that is, they do not exist).

Performance

If using a sparse matrix for distmx, you may achieve better performance by passing in a transpose of its sparse transpose. That is, assuming D is the sparse distance matrix:

D = transpose(sparse(transpose(D)))

Be aware that realizing the sparse transpose of D incurs a heavy one-time penalty, so this strategy should only be used when multiple calls to dijkstra_shortest_paths with the distance matrix are planned.

Examples

julia> using Graphs
 
 julia> ds = dijkstra_shortest_paths(cycle_graph(5), 2);
 
@@ -40,7 +40,7 @@
  0
  1
  2
- 3
source
Graphs.FloydWarshallStateType
struct FloydWarshallState{T, U}

An AbstractPathState designed for Floyd-Warshall shortest-paths calculations.

Fields

  • dists::Matrix{T}: dists[u, v] is the length of the shortest path from u to v
  • parents::Matrix{U}: parents[u, v] is the predecessor of vertex v on the shortest path from u to v
source
Graphs.JohnsonStateType
struct JohnsonState{T, U}

An AbstractPathState designed for Johnson shortest-paths calculations.

Fields

  • dists::Matrix{T}: dists[u, v] is the length of the shortest path from u to v
  • parents::Matrix{U}: parents[u, v] is the predecessor of vertex v on the shortest path from u to v
source
Graphs.johnson_shortest_pathsMethod
johnson_shortest_paths(g, distmx=weights(g))

Use the Johnson algorithm to compute the shortest paths between all pairs of vertices in graph g using an optional distance matrix distmx.

Return a Graphs.JohnsonState with relevant traversal information (try querying state.parents or state.dists).

Performance

Complexity: O(|V|*|E|)

source
Graphs.dag_longest_pathFunction
dag_longest_path(g, distmx=weights(g); topological_order=topological_sort_by_dfs(g))

Return a longest path within the directed acyclic graph g, with distance matrix distmx and using topological_order to iterate on vertices.

source
Graphs.FloydWarshallStateType
struct FloydWarshallState{T, U}

An AbstractPathState designed for Floyd-Warshall shortest-paths calculations.

Fields

  • dists::Matrix{T}: dists[u, v] is the length of the shortest path from u to v
  • parents::Matrix{U}: parents[u, v] is the predecessor of vertex v on the shortest path from u to v
source
Graphs.JohnsonStateType
struct JohnsonState{T, U}

An AbstractPathState designed for Johnson shortest-paths calculations.

Fields

  • dists::Matrix{T}: dists[u, v] is the length of the shortest path from u to v
  • parents::Matrix{U}: parents[u, v] is the predecessor of vertex v on the shortest path from u to v
source
Graphs.johnson_shortest_pathsMethod
johnson_shortest_paths(g, distmx=weights(g))

Use the Johnson algorithm to compute the shortest paths between all pairs of vertices in graph g using an optional distance matrix distmx.

Return a Graphs.JohnsonState with relevant traversal information (try querying state.parents or state.dists).

Performance

Complexity: O(|V|*|E|)

source
Graphs.dag_longest_pathFunction
dag_longest_path(g, distmx=weights(g); topological_order=topological_sort_by_dfs(g))

Return a longest path within the directed acyclic graph g, with distance matrix distmx and using topological_order to iterate on vertices.

source
Graphs.has_negative_edge_cycle_spfaMethod

Function which returns true if there is any negative weight cycle in the graph.

Examples

julia> using Graphs
 
 julia> g = complete_graph(3);
 
@@ -54,7 +54,7 @@
 julia> d = [1 1 -1 1; 1 1 -1 1; 1 1 1 1; 1 1 1 1];
 
 julia> has_negative_edge_cycle_spfa(g, d)
-false
source
Graphs.spfa_shortest_pathsMethod
spfa_shortest_paths(g, s, distmx=weights(g))

Compute shortest paths between a source s and all other nodes in graph g using the Shortest Path Faster Algorithm.

Return a vector of distances to the source.

Examples

julia> using Graphs
 
 julia> g = complete_graph(4);
 
@@ -73,4 +73,4 @@
 
 julia> spfa_shortest_paths(g, 1, d)
 ERROR: Graphs.NegativeCycleError()
-[...]
source
Graphs.YenStateType
struct YenState{T, U}

Designed for yen k-shortest-paths calculations.

Fields

  • dists::Vector{T}: dists[k] is the length of the k-th shortest path from the source to the target
  • paths::Vector{Vector{U}}: paths[k] is the description of the k-th shortest path (as a sequence of vertices) from the source to the target
source
Graphs.yen_k_shortest_pathsMethod
yen_k_shortest_paths(g, source, target, distmx=weights(g), K=1; maxdist=typemax(T));

Perform Yen's algorithm on a graph, computing k-shortest distances between source and target other vertices. Return a YenState that contains distances and paths.

source
+[...]
source
Graphs.YenStateType
struct YenState{T, U}

Designed for yen k-shortest-paths calculations.

Fields

  • dists::Vector{T}: dists[k] is the length of the k-th shortest path from the source to the target
  • paths::Vector{Vector{U}}: paths[k] is the description of the k-th shortest path (as a sequence of vertices) from the source to the target
source
Graphs.yen_k_shortest_pathsMethod
yen_k_shortest_paths(g, source, target, distmx=weights(g), K=1; maxdist=typemax(T));

Perform Yen's algorithm on a graph, computing k-shortest distances between source and target other vertices. Return a YenState that contains distances and paths.

source
diff --git a/dev/algorithms/spanningtrees/index.html b/dev/algorithms/spanningtrees/index.html index f825b665..bfb2b4e7 100644 --- a/dev/algorithms/spanningtrees/index.html +++ b/dev/algorithms/spanningtrees/index.html @@ -1,2 +1,2 @@ -Spanning trees · Graphs.jl

Spanning trees

Graphs.jl contains a few algorithms to compute minimum spanning trees.

Index

Full docs

Graphs.boruvka_mstFunction
boruvka_mst(g, distmx = weights(g); minimize = true)

Return a tuple (mst, weights) where mst is a vector of edges representing the optimum (minimum, by default) spanning tree of a connected, undirected graph g with optional matrix distmx that provides distinct edge weights, and weights is the sum of all the edges in the solution by using Boruvka's algorithm. The algorithm requires that all edges have different weights to correctly generate a minimum/maximum spanning tree

Optional Arguments

  • minimize=true: if set to false, calculate the maximum spanning tree.
source
Graphs.kruskal_mstFunction
kruskal_mst(g, distmx=weights(g); minimize=true)

Return a vector of edges representing the minimum (by default) spanning tree of a connected, undirected graph g with optional distance matrix distmx using Kruskal's algorithm.

Optional Arguments

  • minimize=true: if set to false, calculate the maximum spanning tree.
source
Graphs.prim_mstFunction
prim_mst(g, distmx=weights(g))

Return a vector of edges representing the minimum spanning tree of a connected, undirected graph g with optional distance matrix distmx using Prim's algorithm. Return a vector of edges.

source
+Spanning trees · Graphs.jl

Spanning trees

Graphs.jl contains a few algorithms to compute minimum spanning trees.

Index

Full docs

Graphs.boruvka_mstFunction
boruvka_mst(g, distmx = weights(g); minimize = true)

Return a tuple (mst, weights) where mst is a vector of edges representing the optimum (minimum, by default) spanning tree of a connected, undirected graph g with optional matrix distmx that provides distinct edge weights, and weights is the sum of all the edges in the solution by using Boruvka's algorithm. The algorithm requires that all edges have different weights to correctly generate a minimum/maximum spanning tree

Optional Arguments

  • minimize=true: if set to false, calculate the maximum spanning tree.
source
Graphs.kruskal_mstFunction
kruskal_mst(g, distmx=weights(g); minimize=true)

Return a vector of edges representing the minimum (by default) spanning tree of a connected, undirected graph g with optional distance matrix distmx using Kruskal's algorithm.

Optional Arguments

  • minimize=true: if set to false, calculate the maximum spanning tree.
source
Graphs.prim_mstFunction
prim_mst(g, distmx=weights(g))

Return a vector of edges representing the minimum spanning tree of a connected, undirected graph g with optional distance matrix distmx using Prim's algorithm. Return a vector of edges.

source
diff --git a/dev/algorithms/steinertree/index.html b/dev/algorithms/steinertree/index.html index cd38bd16..3c20f9c3 100644 --- a/dev/algorithms/steinertree/index.html +++ b/dev/algorithms/steinertree/index.html @@ -1,2 +1,2 @@ -Steiner tree · Graphs.jl

Steiner tree

Graphs.jl provides some functionalities related to Steiner Trees.

Index

Full docs

Graphs.steiner_treeFunction
steiner_tree(g, term_vert, distmx=weights(g))

Return an approximately minimum steiner tree of connected, undirected graph g with positive edge weights represented by distmx using Approximate Steiner Tree. The minimum steiner tree problem involves finding a subset of edges in g of minimum weight such that all the vertices in term_vert are connected.

t = length(term_vert).

Performance

Runtime: O(t(tlog(t)+|E|log(|V| )) Memory: O(t|V|) Approximation Factor: 2-2/t

source
+Steiner tree · Graphs.jl

Steiner tree

Graphs.jl provides some functionalities related to Steiner Trees.

Index

Full docs

Graphs.steiner_treeFunction
steiner_tree(g, term_vert, distmx=weights(g))

Return an approximately minimum steiner tree of connected, undirected graph g with positive edge weights represented by distmx using Approximate Steiner Tree. The minimum steiner tree problem involves finding a subset of edges in g of minimum weight such that all the vertices in term_vert are connected.

t = length(term_vert).

Performance

Runtime: O(t(tlog(t)+|E|log(|V| )) Memory: O(t|V|) Approximation Factor: 2-2/t

source
diff --git a/dev/algorithms/traversals/index.html b/dev/algorithms/traversals/index.html index 52c76796..4e4c8b85 100644 --- a/dev/algorithms/traversals/index.html +++ b/dev/algorithms/traversals/index.html @@ -1,5 +1,5 @@ -Traversals and coloring · Graphs.jl

Traversals and coloring

Graphs.jl includes various routines for exploring graphs.

Index

Full docs

Graphs.bfs_parentsMethod
bfs_parents(g, s[; dir=:out])

Perform a breadth-first search of graph g starting from vertex s. Return a vector of parent vertices indexed by vertex. If dir is specified, use the corresponding edge direction (:in and :out are acceptable values).

Performance

This implementation is designed to perform well on large graphs. There are implementations which are marginally faster in practice for smaller graphs, but the performance improvements using this implementation on large graphs can be significant.

source
Graphs.bfs_treeMethod
bfs_tree(g, s[; dir=:out])

Provide a breadth-first traversal of the graph g starting with source vertex s, and return a directed acyclic graph of vertices in the order they were discovered. If dir is specified, use the corresponding edge direction (:in and :out are acceptable values).

source
Graphs.gdistances!Method
gdistances!(g, source, dists; sort_alg=QuickSort)

Fill dists with the geodesic distances of vertices in g from source vertex (or collection of vertices) source. dists should be a vector of length nv(g) filled with typemax(T). Return dists.

For vertices in disconnected components the default distance is typemax(T).

An optional sorting algorithm may be specified (see Performance section).

Performance

gdistances uses QuickSort internally for its default sorting algorithm, since it performs the best of the algorithms built into Julia Base. However, passing a RadixSort (available via SortingAlgorithms.jl) will provide significant performance improvements on larger graphs.

source
Graphs.gdistancesMethod
gdistances(g, source; sort_alg=QuickSort)

Return a vector filled with the geodesic distances of vertices in g from source. If source is a collection of vertices each element should be unique. For vertices in disconnected components the default distance is typemax(T).

An optional sorting algorithm may be specified (see Performance section).

Performance

gdistances uses QuickSort internally for its default sorting algorithm, since it performs the best of the algorithms built into Julia Base. However, passing a RadixSort (available via SortingAlgorithms.jl) will provide significant performance improvements on larger graphs.

source
Graphs.has_pathMethod
has_path(g::AbstractGraph, u, v; exclude_vertices=Vector())

Return true if there is a path from u to v in g (while avoiding vertices in exclude_vertices) or u == v. Return false if there is no such path or if u or v is in excluded_vertices.

source
Graphs.treeMethod
tree(parents)

Convert a parents array into a directed graph.

source
Graphs.bipartite_mapMethod
bipartite_map(g) -> Vector{UInt8}

For a bipartite graph g, return a vector c of size $|V|$ containing the assignment of each vertex to one of the two sets ($c_i == 1$ or $c_i == 2$). If g is not bipartite, return an empty vector.

Implementation Notes

Note that an empty vector does not necessarily indicate non-bipartiteness. An empty graph will return an empty vector but is bipartite.

Examples

julia> using Graphs
+Traversals and coloring · Graphs.jl

Traversals and coloring

Graphs.jl includes various routines for exploring graphs.

Index

Full docs

Graphs.bfs_parentsMethod
bfs_parents(g, s[; dir=:out])

Perform a breadth-first search of graph g starting from vertex s. Return a vector of parent vertices indexed by vertex. If dir is specified, use the corresponding edge direction (:in and :out are acceptable values).

Performance

This implementation is designed to perform well on large graphs. There are implementations which are marginally faster in practice for smaller graphs, but the performance improvements using this implementation on large graphs can be significant.

source
Graphs.bfs_treeMethod
bfs_tree(g, s[; dir=:out])

Provide a breadth-first traversal of the graph g starting with source vertex s, and return a directed acyclic graph of vertices in the order they were discovered. If dir is specified, use the corresponding edge direction (:in and :out are acceptable values).

source
Graphs.gdistances!Method
gdistances!(g, source, dists; sort_alg=QuickSort)

Fill dists with the geodesic distances of vertices in g from source vertex (or collection of vertices) source. dists should be a vector of length nv(g) filled with typemax(T). Return dists.

For vertices in disconnected components the default distance is typemax(T).

An optional sorting algorithm may be specified (see Performance section).

Performance

gdistances uses QuickSort internally for its default sorting algorithm, since it performs the best of the algorithms built into Julia Base. However, passing a RadixSort (available via SortingAlgorithms.jl) will provide significant performance improvements on larger graphs.

source
Graphs.gdistancesMethod
gdistances(g, source; sort_alg=QuickSort)

Return a vector filled with the geodesic distances of vertices in g from source. If source is a collection of vertices each element should be unique. For vertices in disconnected components the default distance is typemax(T).

An optional sorting algorithm may be specified (see Performance section).

Performance

gdistances uses QuickSort internally for its default sorting algorithm, since it performs the best of the algorithms built into Julia Base. However, passing a RadixSort (available via SortingAlgorithms.jl) will provide significant performance improvements on larger graphs.

source
Graphs.has_pathMethod
has_path(g::AbstractGraph, u, v; exclude_vertices=Vector())

Return true if there is a path from u to v in g (while avoiding vertices in exclude_vertices) or u == v. Return false if there is no such path or if u or v is in excluded_vertices.

source
Graphs.treeMethod
tree(parents)

Convert a parents array into a directed graph.

source
Graphs.bipartite_mapMethod
bipartite_map(g) -> Vector{UInt8}

For a bipartite graph g, return a vector c of size $|V|$ containing the assignment of each vertex to one of the two sets ($c_i == 1$ or $c_i == 2$). If g is not bipartite, return an empty vector.

Implementation Notes

Note that an empty vector does not necessarily indicate non-bipartiteness. An empty graph will return an empty vector but is bipartite.

Examples

julia> using Graphs
 
 julia> g = SimpleGraph(3);
 
@@ -22,7 +22,7 @@
  0x01
  0x01
  0x01
- 0x01
source
Graphs.is_bipartiteMethod
is_bipartite(g)

Return true if graph g is bipartite.

Examples

julia> using Graphs
 
 julia> g = SimpleGraph(3);
 
@@ -36,9 +36,9 @@
 julia> add_edge!(g, 1, 3);
 
 julia> is_bipartite(g)
-false
source
Graphs.dfs_parentsMethod
dfs_parents(g, s[; dir=:out])

Perform a depth-first search of graph g starting from vertex s. Return a vector of parent vertices indexed by vertex. If dir is specified, use the corresponding edge direction (:in and :out are acceptable values).

Implementation Notes

This version of DFS is iterative.

source
Graphs.dfs_treeMethod
dfs_tree(g, s[;dir=:out])

Provide a depth-first traversal of the graph g starting with source vertex s, and return a directed acyclic graph of vertices in the order they were discovered. If dir is specified, use the corresponding edge direction (:in and :out are acceptable values).

source
Graphs.is_cyclicFunction
is_cyclic(g)

Return true if graph g contains a cycle.

Implementation Notes

The algorithm uses a DFS. Self-loops are counted as cycles.

source
Graphs.topological_sortFunction
topological_sort(g)

Return a topological sort of a directed graph g as a vector of vertices in topological order.

Implementation Notes

This is currently just an alias for topological_sort_by_dfs

source
Graphs.diffusionMethod
diffusion(g, p, n)

Run diffusion simulation on g for n steps with spread probabilities based on p. Return a vector with the set of new vertices reached at each step of the simulation.

Optional Arguments

  • initial_infections=sample(vertices(g), 1): A list of vertices that

are infected at the start of the simulation.

  • watch=Vector(): While simulation is always run on the full graph,

specifying watch limits reporting to a specific set of vertices reached during the simulation. If left empty, all vertices will be watched.

  • normalize=false: if false, set the probability of spread from a vertex $i$ to

each of the outneighbors of $i$ to $p$. If true, set the probability of spread from a vertex $i$ to each of the outneighbors of $i$ to $\frac{p}{outdegreee(g, i)}$.

  • rng=nothing: A random generator to sample from.
source
Graphs.diffusion_rateMethod
diffusion_rate(results)
-diffusion_rate(g, p, n; ...)

Given the results of a diffusion output or the parameters to the diffusion simulation itself, (run and) return the rate of diffusion as a vector representing the cumulative number of vertices infected at each simulation step, restricted to vertices included in watch, if specified.

source
Graphs.ColoringType
struct Coloring{T}

Store the number of colors used and mapping from vertex to color

source
Graphs.greedy_colorMethod
greedy_color(g; sort_degree=false, reps = 1)

Color graph g based on Greedy Coloring Heuristics

The heuristics can be described as choosing a permutation of the vertices and assigning the lowest color index available iteratively in that order.

If sort_degree is true then the permutation is chosen in reverse sorted order of the degree of the vertices. parallel and reps are irrelevant in this case.

If sort_degree is false then reps colorings are obtained based on random permutations and the one using least colors is chosen.

source
Graphs.perm_greedy_colorMethod
perm_greedy_color(g, seq)

Color graph g according to an order specified by seq using a greedy heuristic. seq[i] = v implies that vertex v is the $i^{th}$ vertex to be colored.

source
Graphs.random_greedy_colorMethod
random_greedy_color(g, reps)

Color the graph g iteratively in a random order using a greedy heuristic and choose the best coloring out of reps such random colorings.

source
Graphs.maximum_adjacency_visitMethod
maximum_adjacency_visit(g[, distmx][, log][, io][, s])
-maximum_adjacency_visit(g[, s])

Return the vertices in g traversed by maximum adjacency search, optionally starting from vertex s (default 1). An optional distmx matrix may be specified; if omitted, edge distances are assumed to be 1. If log (default false) is true, visitor events will be printed to io, which defaults to STDOUT; otherwise, no event information will be displayed.

source
Graphs.mincutMethod
mincut(g, distmx=weights(g))

Return a tuple (parity, bestcut), where parity is a vector of integer values that determines the partition in g (1 or 2) and bestcut is the weight of the cut that makes this partition. An optional distmx matrix of non-negative weights may be specified; if omitted, edge distances are assumed to be 1.

source
Graphs.non_backtracking_randomwalkFunction
non_backtracking_randomwalk(g, s, niter; rng=nothing, seed=nothing)

Perform a non-backtracking random walk on directed graph g starting at vertex s and continuing for a maximum of niter steps. Return a vector of vertices visited in order.

source
Graphs.randomwalkMethod
randomwalk(g, s, niter; rng=nothing, seed=nothing)

Perform a random walk on graph g starting at vertex s and continuing for a maximum of niter steps. Return a vector of vertices visited in order.

source
Graphs.self_avoiding_walkMethod
self_avoiding_walk(g, s, niter; rng=nothing, seed=nothing)

Perform a self-avoiding walk on graph g starting at vertex s and continuing for a maximum of niter steps. Return a vector of vertices visited in order.

source
Graphs.eulerianMethod
eulerian(g::AbstractSimpleGraph{T}[, u::T]) --> T[]

Returns a Eulerian trail or cycle through an undirected graph g, starting at vertex u, returning a vector listing the vertices of g in the order that they are traversed. If no such trail or cycle exists, throws an error.

A Eulerian trail or cycle is a path that visits every edge of g exactly once; for a cycle, the path starts and ends at vertex u.

Optional arguments

  • If u is omitted, a Eulerian trail or cycle is computed with u = first(vertices(g)).
source
Graphs.dfs_parentsMethod
dfs_parents(g, s[; dir=:out])

Perform a depth-first search of graph g starting from vertex s. Return a vector of parent vertices indexed by vertex. If dir is specified, use the corresponding edge direction (:in and :out are acceptable values).

Implementation Notes

This version of DFS is iterative.

source
Graphs.dfs_treeMethod
dfs_tree(g, s[;dir=:out])

Provide a depth-first traversal of the graph g starting with source vertex s, and return a directed acyclic graph of vertices in the order they were discovered. If dir is specified, use the corresponding edge direction (:in and :out are acceptable values).

source
Graphs.is_cyclicFunction
is_cyclic(g)

Return true if graph g contains a cycle.

Implementation Notes

The algorithm uses a DFS. Self-loops are counted as cycles.

source
Graphs.topological_sortFunction
topological_sort(g)

Return a topological sort of a directed graph g as a vector of vertices in topological order.

Implementation Notes

This is currently just an alias for topological_sort_by_dfs

source
Graphs.diffusionMethod
diffusion(g, p, n)

Run diffusion simulation on g for n steps with spread probabilities based on p. Return a vector with the set of new vertices reached at each step of the simulation.

Optional Arguments

  • initial_infections=sample(vertices(g), 1): A list of vertices that

are infected at the start of the simulation.

  • watch=Vector(): While simulation is always run on the full graph,

specifying watch limits reporting to a specific set of vertices reached during the simulation. If left empty, all vertices will be watched.

  • normalize=false: if false, set the probability of spread from a vertex $i$ to

each of the outneighbors of $i$ to $p$. If true, set the probability of spread from a vertex $i$ to each of the outneighbors of $i$ to $\frac{p}{outdegreee(g, i)}$.

  • rng=nothing: A random generator to sample from.
source
Graphs.diffusion_rateMethod
diffusion_rate(results)
+diffusion_rate(g, p, n; ...)

Given the results of a diffusion output or the parameters to the diffusion simulation itself, (run and) return the rate of diffusion as a vector representing the cumulative number of vertices infected at each simulation step, restricted to vertices included in watch, if specified.

source
Graphs.ColoringType
struct Coloring{T}

Store the number of colors used and mapping from vertex to color

source
Graphs.greedy_colorMethod
greedy_color(g; sort_degree=false, reps = 1)

Color graph g based on Greedy Coloring Heuristics

The heuristics can be described as choosing a permutation of the vertices and assigning the lowest color index available iteratively in that order.

If sort_degree is true then the permutation is chosen in reverse sorted order of the degree of the vertices. parallel and reps are irrelevant in this case.

If sort_degree is false then reps colorings are obtained based on random permutations and the one using least colors is chosen.

source
Graphs.perm_greedy_colorMethod
perm_greedy_color(g, seq)

Color graph g according to an order specified by seq using a greedy heuristic. seq[i] = v implies that vertex v is the $i^{th}$ vertex to be colored.

source
Graphs.random_greedy_colorMethod
random_greedy_color(g, reps)

Color the graph g iteratively in a random order using a greedy heuristic and choose the best coloring out of reps such random colorings.

source
Graphs.maximum_adjacency_visitMethod
maximum_adjacency_visit(g[, distmx][, log][, io][, s])
+maximum_adjacency_visit(g[, s])

Return the vertices in g traversed by maximum adjacency search, optionally starting from vertex s (default 1). An optional distmx matrix may be specified; if omitted, edge distances are assumed to be 1. If log (default false) is true, visitor events will be printed to io, which defaults to STDOUT; otherwise, no event information will be displayed.

source
Graphs.mincutMethod
mincut(g, distmx=weights(g))

Return a tuple (parity, bestcut), where parity is a vector of integer values that determines the partition in g (1 or 2) and bestcut is the weight of the cut that makes this partition. An optional distmx matrix of non-negative weights may be specified; if omitted, edge distances are assumed to be 1.

source
Graphs.non_backtracking_randomwalkFunction
non_backtracking_randomwalk(g, s, niter; rng=nothing, seed=nothing)

Perform a non-backtracking random walk on directed graph g starting at vertex s and continuing for a maximum of niter steps. Return a vector of vertices visited in order.

source
Graphs.randomwalkMethod
randomwalk(g, s, niter; rng=nothing, seed=nothing)

Perform a random walk on graph g starting at vertex s and continuing for a maximum of niter steps. Return a vector of vertices visited in order.

source
Graphs.self_avoiding_walkMethod
self_avoiding_walk(g, s, niter; rng=nothing, seed=nothing)

Perform a self-avoiding walk on graph g starting at vertex s and continuing for a maximum of niter steps. Return a vector of vertices visited in order.

source
Graphs.eulerianMethod
eulerian(g::AbstractSimpleGraph{T}[, u::T]) --> T[]

Returns a Eulerian trail or cycle through an undirected graph g, starting at vertex u, returning a vector listing the vertices of g in the order that they are traversed. If no such trail or cycle exists, throws an error.

A Eulerian trail or cycle is a path that visits every edge of g exactly once; for a cycle, the path starts and ends at vertex u.

Optional arguments

  • If u is omitted, a Eulerian trail or cycle is computed with u = first(vertices(g)).
source
Graphs.all_simple_pathsMethod
all_simple_paths(g, u, v; cutoff)  --> Graphs.SimplePathIterator
 all_simple_paths(g, u, vs; cutoff) --> Graphs.SimplePathIterator

Returns an iterator that generates all simple paths in the graph g from a source vertex u to a target vertex v or iterable of target vertices vs. A simple path has no repeated vertices.

The iterator's elements (i.e., the paths) can be materialized via collect or iterate. Paths are iterated in the order of a depth-first search.

If the requested path has identical source and target vertices, i.e., if u = v, a zero-length path [u] is included among the iterates.

Keyword arguments

The maximum path length (i.e., number of edges) is limited by the keyword argument cutoff (default, nv(g)-1). If a path's path length is greater than cutoff, it is omitted.

Examples

julia> g = complete_graph(4);
 
 julia> spi = all_simple_paths(g, 1, 4)
@@ -54,4 +54,4 @@
 3-element Vector{Vector{Int64}}:
  [1, 2, 4]
  [1, 3, 4]
- [1, 4]
source
+ [1, 4]
source
diff --git a/dev/algorithms/trees/index.html b/dev/algorithms/trees/index.html index 6743e587..d60347a7 100644 --- a/dev/algorithms/trees/index.html +++ b/dev/algorithms/trees/index.html @@ -1,2 +1,2 @@ -Trees · Graphs.jl

Trees

Graphs.jl algorithms related to trees.

Index

Full docs

Graphs.is_treeFunction
is_tree(g)

Returns true if g is a tree: that is, a simple, connected undirected graph, with nv-1 edges (nv = number of vertices). Trees are the minimal connected graphs; equivalently they have no cycles.

This function does not apply to directed graphs. Directed trees are sometimes called polytrees).

source
Graphs.prufer_decodeMethod
prufer_decode(code)

Returns the unique tree associated with the given (Prüfer) code. Each tree of size n is associated with a Prüfer sequence (a[1], ..., a[n-2]) with 1 ⩽ a[i] ⩽ n. The sequence is constructed recursively by the leaf removal algoritm. At step k, the leaf with smallest index is removed and its unique neighbor is added to the Prüfer sequence, giving a[k]. The decoding algorithm goes backward. The tree associated with the empty sequence is the 2-vertices tree with one edge. Ref: Prüfer sequence on Wikipedia

source
Graphs.prufer_encodeMethod
prufer_encode(g::SimpleGraph)

Given a tree (a connected minimal undirected graph) of size n⩾3, returns the unique Prüfer sequence associated with this tree.

Each tree of size n ⩾ 2 is associated with a Prüfer sequence (a[1], ..., a[n-2]) with 1 ⩽ a[i] ⩽ n. The sequence is constructed recursively by the leaf removal algoritm. At step k, the leaf with smallest index is removed and its unique neighbor is added to the Prüfer sequence, giving a[k]. The Prüfer sequence of the tree with only one edge is the empty sequence.

Ref: Prüfer sequence on Wikipedia

source
+Trees · Graphs.jl

Trees

Graphs.jl algorithms related to trees.

Index

Full docs

Graphs.is_treeFunction
is_tree(g)

Returns true if g is a tree: that is, a simple, connected undirected graph, with nv-1 edges (nv = number of vertices). Trees are the minimal connected graphs; equivalently they have no cycles.

This function does not apply to directed graphs. Directed trees are sometimes called polytrees).

source
Graphs.prufer_decodeMethod
prufer_decode(code)

Returns the unique tree associated with the given (Prüfer) code. Each tree of size n is associated with a Prüfer sequence (a[1], ..., a[n-2]) with 1 ⩽ a[i] ⩽ n. The sequence is constructed recursively by the leaf removal algoritm. At step k, the leaf with smallest index is removed and its unique neighbor is added to the Prüfer sequence, giving a[k]. The decoding algorithm goes backward. The tree associated with the empty sequence is the 2-vertices tree with one edge. Ref: Prüfer sequence on Wikipedia

source
Graphs.prufer_encodeMethod
prufer_encode(g::SimpleGraph)

Given a tree (a connected minimal undirected graph) of size n⩾3, returns the unique Prüfer sequence associated with this tree.

Each tree of size n ⩾ 2 is associated with a Prüfer sequence (a[1], ..., a[n-2]) with 1 ⩽ a[i] ⩽ n. The sequence is constructed recursively by the leaf removal algoritm. At step k, the leaf with smallest index is removed and its unique neighbor is added to the Prüfer sequence, giving a[k]. The Prüfer sequence of the tree with only one edge is the empty sequence.

Ref: Prüfer sequence on Wikipedia

source
diff --git a/dev/algorithms/utils/index.html b/dev/algorithms/utils/index.html index 1eaa595b..314592ca 100644 --- a/dev/algorithms/utils/index.html +++ b/dev/algorithms/utils/index.html @@ -1,2 +1,2 @@ -Utilities · Graphs.jl

Utilities

Here are a few useful functions that didn't fit in the other categories.

Index

Full docs

Graphs.deepcopy_adjlistMethod
deepcopy_adjlist(adjlist::Vector{Vector{T}})

Internal utility function for copying adjacency lists. On adjacency lists this function is more efficient than deepcopy for two reasons:

  • As of Julia v1.0.2, deepcopy is not typestable.
  • deepcopy needs to track all references when traversing a recursive data structure in order to ensure that references to the same location do need get assigned to different locations in the copy. Because we can assume that all lists in our adjacency list are different, we don't need to keep track of them.

If T is not a bitstype (e.g. BigInt), we use the standard deepcopy.

source
Graphs.findall!Method
findall!(A, B)

Set the B[1:|I|] to I where I is the set of indices A[I] returns true.

Assumes length(B) >= |I|.

source
Graphs.greedy_contiguous_partitionMethod
greedy_contiguous_partition(weight, required_partitions, num_items=length(weight))

Partition 1:num_items into at most required_partitions number of contiguous partitions with the objective of minimising the largest partition. The size of a partition is equal to the num of the weight of its elements. weight[i] > 0.

Performance

Time: O(numitems+requiredpartitions) Requires only one iteration over weight but may not output the optimal partition.

Implementation Notes

Balance(wt, left, right, n_items, n_part) = max(sum(wt[left:right])*(n_part-1), sum(wt[right+1:n_items])). Find right that minimises Balance(weight, 1, right, num_items, required_partitions). Set the first partition as 1:right. Repeat on indices right+1:num_items and one less partition.

source
Graphs.insortedMethod
insorted(item, collection)

Return true if item is in sorted collection collection.

Implementation Notes

Does not verify that collection is sorted.

source
Graphs.optimal_contiguous_partitionMethod
optimal_contiguous_partition(weight, required_partitions, num_items=length(weight))

Partition 1:num_items into at most required_partitions number of contiguous partitions such that the largest partition is minimised. The size of a partition is equal to the sum of the weight of its elements. weight[i] > 0.

Performance

Time: O(num_items*log(sum(weight)))

Implementation Notes

Binary Search for the partitioning over [fld(sum(weight)-1, required_partitions), sum(weight)].

source
Graphs.rng_from_rng_or_seedMethod
rng_from_rng_or_seed(rng, seed)

Helper function for randomized functions that can take a random generator as well as a seed argument.

Currently most randomized functions in this package take a seed integer as an argument. As modern randomized Julia functions tend to take a random generator instead of a seed, this function helps with the transition by taking rng and seed as an argument and always returning a random number generator. At least one of these arguments must be nothing.

source
Graphs.sample!Method
sample!([rng, ]a, k)

Sample k element from array a without repetition and eventually excluding elements in exclude.

Optional Arguments

  • exclude=(): elements in a to exclude from sampling.

Implementation Notes

Changes the order of the elements in a. For a non-mutating version, see sample.

source
Graphs.sampleMethod
sample(a, k; exclude=(), rng=nothing, seed=nothing)

Sample k element from AbstractVector a without repetition and eventually excluding elements in exclude.

Optional Arguments

  • exclude=(): elements in a to exclude from sampling.
  • rng=nothing: set the Random Number Generator.
  • seed=nothing: seed the Random Number Generator with this value.

Implementation Notes

Unlike sample!, does not produce side effects.

source
Graphs.unweighted_contiguous_partitionMethod
unweighted_contiguous_partition(num_items, required_partitions)

Partition 1:num_items into required_partitions number of partitions such that the difference in length of the largest and smallest partition is at most 1.

Performance

Time: O(required_partitions)

source
+Utilities · Graphs.jl

Utilities

Here are a few useful functions that didn't fit in the other categories.

Index

Full docs

Graphs.deepcopy_adjlistMethod
deepcopy_adjlist(adjlist::Vector{Vector{T}})

Internal utility function for copying adjacency lists. On adjacency lists this function is more efficient than deepcopy for two reasons:

  • As of Julia v1.0.2, deepcopy is not typestable.
  • deepcopy needs to track all references when traversing a recursive data structure in order to ensure that references to the same location do need get assigned to different locations in the copy. Because we can assume that all lists in our adjacency list are different, we don't need to keep track of them.

If T is not a bitstype (e.g. BigInt), we use the standard deepcopy.

source
Graphs.findall!Method
findall!(A, B)

Set the B[1:|I|] to I where I is the set of indices A[I] returns true.

Assumes length(B) >= |I|.

source
Graphs.greedy_contiguous_partitionMethod
greedy_contiguous_partition(weight, required_partitions, num_items=length(weight))

Partition 1:num_items into at most required_partitions number of contiguous partitions with the objective of minimising the largest partition. The size of a partition is equal to the num of the weight of its elements. weight[i] > 0.

Performance

Time: O(numitems+requiredpartitions) Requires only one iteration over weight but may not output the optimal partition.

Implementation Notes

Balance(wt, left, right, n_items, n_part) = max(sum(wt[left:right])*(n_part-1), sum(wt[right+1:n_items])). Find right that minimises Balance(weight, 1, right, num_items, required_partitions). Set the first partition as 1:right. Repeat on indices right+1:num_items and one less partition.

source
Graphs.insortedMethod
insorted(item, collection)

Return true if item is in sorted collection collection.

Implementation Notes

Does not verify that collection is sorted.

source
Graphs.optimal_contiguous_partitionMethod
optimal_contiguous_partition(weight, required_partitions, num_items=length(weight))

Partition 1:num_items into at most required_partitions number of contiguous partitions such that the largest partition is minimised. The size of a partition is equal to the sum of the weight of its elements. weight[i] > 0.

Performance

Time: O(num_items*log(sum(weight)))

Implementation Notes

Binary Search for the partitioning over [fld(sum(weight)-1, required_partitions), sum(weight)].

source
Graphs.rng_from_rng_or_seedMethod
rng_from_rng_or_seed(rng, seed)

Helper function for randomized functions that can take a random generator as well as a seed argument.

Currently most randomized functions in this package take a seed integer as an argument. As modern randomized Julia functions tend to take a random generator instead of a seed, this function helps with the transition by taking rng and seed as an argument and always returning a random number generator. At least one of these arguments must be nothing.

source
Graphs.sample!Method
sample!([rng, ]a, k)

Sample k element from array a without repetition and eventually excluding elements in exclude.

Optional Arguments

  • exclude=(): elements in a to exclude from sampling.

Implementation Notes

Changes the order of the elements in a. For a non-mutating version, see sample.

source
Graphs.sampleMethod
sample(a, k; exclude=(), rng=nothing, seed=nothing)

Sample k element from AbstractVector a without repetition and eventually excluding elements in exclude.

Optional Arguments

  • exclude=(): elements in a to exclude from sampling.
  • rng=nothing: set the Random Number Generator.
  • seed=nothing: seed the Random Number Generator with this value.

Implementation Notes

Unlike sample!, does not produce side effects.

source
Graphs.unweighted_contiguous_partitionMethod
unweighted_contiguous_partition(num_items, required_partitions)

Partition 1:num_items into required_partitions number of partitions such that the difference in length of the largest and smallest partition is at most 1.

Performance

Time: O(required_partitions)

source
diff --git a/dev/algorithms/vertexcover/index.html b/dev/algorithms/vertexcover/index.html index c94fc6a4..e55f0319 100644 --- a/dev/algorithms/vertexcover/index.html +++ b/dev/algorithms/vertexcover/index.html @@ -8,4 +8,4 @@ julia> vertex_cover(cycle_graph(3), DegreeVertexCover()) 2-element Vector{Int64}: 1 - 3source
Graphs.vertex_coverMethod
vertex_cover(g, RandomVertexCover(); rng=nothing, seed=nothing)

Find a set of vertices such that every edge in g has some vertex in the set as atleast one of its end point.

Implementation Notes

Performs Approximate Minimum Vertex Cover once. Returns a vector of vertices representing the vertices in the Vertex Cover.

Performance

Runtime: O(|V|+|E|) Memory: O(|E|) Approximation Factor: 2

Optional Arguments

  • rng=nothing: set the Random Number Generator.
  • If seed >= 0, a random generator is seeded with this value.
source
+ 3source
Graphs.vertex_coverMethod
vertex_cover(g, RandomVertexCover(); rng=nothing, seed=nothing)

Find a set of vertices such that every edge in g has some vertex in the set as atleast one of its end point.

Implementation Notes

Performs Approximate Minimum Vertex Cover once. Returns a vector of vertices representing the vertices in the Vertex Cover.

Performance

Runtime: O(|V|+|E|) Memory: O(|E|) Approximation Factor: 2

Optional Arguments

  • rng=nothing: set the Random Number Generator.
  • If seed >= 0, a random generator is seeded with this value.
source
diff --git a/dev/contributing/index.html b/dev/contributing/index.html index 529167a0..96b505e2 100644 --- a/dev/contributing/index.html +++ b/dev/contributing/index.html @@ -30,4 +30,4 @@ * [new ref] refs/pull/1009/head -> origin/pr/1009 ...

To check out a particular PR:

$ git checkout pr/999
 Branch pr/999 set up to track remote branch pr/999 from origin.
-Switched to a new branch 'pr/999'

Now you can test a PR by running git fetch && git checkout pr/PRNUMBER && julia -e 'using Pkg; Pkg.test("Graphs")'

+Switched to a new branch 'pr/999'

Now you can test a PR by running git fetch && git checkout pr/PRNUMBER && julia -e 'using Pkg; Pkg.test("Graphs")'

diff --git a/dev/core_functions/core/index.html b/dev/core_functions/core/index.html index 367e2ef0..36fa22da 100644 --- a/dev/core_functions/core/index.html +++ b/dev/core_functions/core/index.html @@ -1,11 +1,11 @@ -Core functions · Graphs.jl

Core functions

Graphs.jl includes the following core functions.

Index

Full docs

Graphs.add_vertices!Method
add_vertices!(g, n)

Add n new vertices to the graph g. Return the number of vertices that were added successfully.

Examples

julia> using Graphs
+Core functions · Graphs.jl

Core functions

Graphs.jl includes the following core functions.

Index

Full docs

Graphs.add_vertices!Method
add_vertices!(g, n)

Add n new vertices to the graph g. Return the number of vertices that were added successfully.

Examples

julia> using Graphs
 
 julia> g = SimpleGraph()
 {0, 0} undirected simple Int64 graph
 
 julia> add_vertices!(g, 2)
-2
source
Graphs.all_neighborsFunction
all_neighbors(g, v)

Return a list of all inbound and outbound neighbors of v in g. For undirected graphs, this is equivalent to both outneighbors and inneighbors.

Implementation Notes

Returns a reference to the current graph's internal structures, not a copy. Do not modify result. If the graph is modified, the behavior is undefined: the array behind this reference may be modified too, but this is not guaranteed.

Examples

julia> using Graphs
+2
source
Graphs.all_neighborsFunction
all_neighbors(g, v)

Return a list of all inbound and outbound neighbors of v in g. For undirected graphs, this is equivalent to both outneighbors and inneighbors.

Implementation Notes

Returns a reference to the current graph's internal structures, not a copy. Do not modify result. If the graph is modified, the behavior is undefined: the array behind this reference may be modified too, but this is not guaranteed.

Examples

julia> using Graphs
 
 julia> g = DiGraph(3);
 
@@ -24,7 +24,7 @@
 julia> all_neighbors(g, 3)
 2-element Vector{Int64}:
  1
- 2
source
Graphs.common_neighborsMethod
common_neighbors(g, u, v)

Return the neighbors common to vertices u and v in g.

Implementation Notes

Returns a reference to the current graph's internal structures, not a copy. Do not modify result. If the graph is modified, the behavior is undefined: the array behind this reference may be modified too, but this is not guaranteed.

Examples

julia> using Graphs
+ 2
source
Graphs.common_neighborsMethod
common_neighbors(g, u, v)

Return the neighbors common to vertices u and v in g.

Implementation Notes

Returns a reference to the current graph's internal structures, not a copy. Do not modify result. If the graph is modified, the behavior is undefined: the array behind this reference may be modified too, but this is not guaranteed.

Examples

julia> using Graphs
 
 julia> g = SimpleGraph(4);
 
@@ -45,7 +45,7 @@
 
 julia> common_neighbors(g, 1, 4)
 1-element Vector{Int64}:
- 3
source
Graphs.degreeFunction
degree(g[, v])

Return a vector corresponding to the number of edges which start or end at each vertex in graph g. If v is specified, only return degrees for vertices in v. For directed graphs, this value equals the incoming plus outgoing edges. For undirected graphs, it equals the connected edges.

Examples

julia> using Graphs
+ 3
source
Graphs.degreeFunction
degree(g[, v])

Return a vector corresponding to the number of edges which start or end at each vertex in graph g. If v is specified, only return degrees for vertices in v. For directed graphs, this value equals the incoming plus outgoing edges. For undirected graphs, it equals the connected edges.

Examples

julia> using Graphs
 
 julia> g = DiGraph(3);
 
@@ -57,7 +57,7 @@
 3-element Vector{Int64}:
  1
  1
- 2
source
Graphs.degree_histogramMethod
degree_histogram(g, degfn=degree)

Return a Dict with values representing the number of vertices that have degree represented by the key.

Degree function (for example, indegree or outdegree) may be specified by overriding degfn.

source
Graphs.densityFunction
density(g)

Return the density of g. Density is defined as the ratio of the number of actual edges to the number of possible edges ($|V|×(|V|-1)$ for directed graphs and $\frac{|V|×(|V|-1)}{2}$ for undirected graphs).

source
Graphs.degree_histogramMethod
degree_histogram(g, degfn=degree)

Return a Dict with values representing the number of vertices that have degree represented by the key.

Degree function (for example, indegree or outdegree) may be specified by overriding degfn.

source
Graphs.densityFunction
density(g)

Return the density of g. Density is defined as the ratio of the number of actual edges to the number of possible edges ($|V|×(|V|-1)$ for directed graphs and $\frac{|V|×(|V|-1)}{2}$ for undirected graphs).

source
Graphs.has_self_loopsMethod
has_self_loops(g)

Return true if g has any self loops.

Examples

julia> using Graphs
 
 julia> g = SimpleGraph(2);
 
@@ -69,7 +69,7 @@
 julia> add_edge!(g, 1, 1);
 
 julia> has_self_loops(g)
-true
source
Graphs.indegreeMethod
indegree(g[, v])

Return a vector corresponding to the number of edges which end at each vertex in graph g. If v is specified, only return degrees for vertices in v.

Examples

julia> using Graphs
+true
source
Graphs.indegreeMethod
indegree(g[, v])

Return a vector corresponding to the number of edges which end at each vertex in graph g. If v is specified, only return degrees for vertices in v.

Examples

julia> using Graphs
 
 julia> g = DiGraph(3);
 
@@ -81,14 +81,14 @@
 3-element Vector{Int64}:
  1
  0
- 1
source
Graphs.is_orderedMethod
is_ordered(e)

Return true if the source vertex of edge e is less than or equal to the destination vertex.

Examples

julia> using Graphs
+ 1
source
Graphs.is_orderedMethod
is_ordered(e)

Return true if the source vertex of edge e is less than or equal to the destination vertex.

Examples

julia> using Graphs
 
 julia> g = DiGraph(2);
 
 julia> add_edge!(g, 2, 1);
 
 julia> is_ordered(first(edges(g)))
-false
source
Graphs.neighborsMethod
neighbors(g, v)

Return a list of all neighbors reachable from vertex v in g. For directed graphs, the default is equivalent to outneighbors; use all_neighbors to list inbound and outbound neighbors.

Implementation Notes

Returns a reference to the current graph's internal structures, not a copy. Do not modify result. If the graph is modified, the behavior is undefined: the array behind this reference may be modified too, but this is not guaranteed.

Examples

julia> using Graphs
+false
source
Graphs.neighborsMethod
neighbors(g, v)

Return a list of all neighbors reachable from vertex v in g. For directed graphs, the default is equivalent to outneighbors; use all_neighbors to list inbound and outbound neighbors.

Implementation Notes

Returns a reference to the current graph's internal structures, not a copy. Do not modify result. If the graph is modified, the behavior is undefined: the array behind this reference may be modified too, but this is not guaranteed.

Examples

julia> using Graphs
 
 julia> g = DiGraph(3);
 
@@ -105,7 +105,7 @@
 
 julia> neighbors(g, 3)
 1-element Vector{Int64}:
- 1
source
Graphs.noallocextremeMethod
noallocextreme(f, comparison, initial, g)

Compute the extreme value of [f(g,i) for i=i:nv(g)] without gathering them all

source
Graphs.noallocextremeMethod
noallocextreme(f, comparison, initial, g)

Compute the extreme value of [f(g,i) for i=i:nv(g)] without gathering them all

source
Graphs.num_self_loopsMethod
num_self_loops(g)

Return the number of self loops in g.

Examples

julia> using Graphs
 
 julia> g = SimpleGraph(2);
 
@@ -117,7 +117,7 @@
 julia> add_edge!(g, 1, 1);
 
 julia> num_self_loops(g)
-1
source
Graphs.outdegreeMethod
outdegree(g[, v])

Return a vector corresponding to the number of edges which start at each vertex in graph g. If v is specified, only return degrees for vertices in v.

Examples

julia> using Graphs
+1
source
Graphs.outdegreeMethod
outdegree(g[, v])

Return a vector corresponding to the number of edges which start at each vertex in graph g. If v is specified, only return degrees for vertices in v.

Examples

julia> using Graphs
 
 julia> g = DiGraph(3);
 
@@ -129,4 +129,4 @@
 3-element Vector{Int64}:
  0
  1
- 1
source
Graphs.squashMethod
squash(g)

Return a copy of a graph with the smallest practical eltype that can accommodate all vertices.

May also return the original graph if the eltype does not change.

source
Graphs.weightsMethod
weights(g)

Return the weights of the edges of a graph g as a matrix. Defaults to Graphs.DefaultDistance.

Implementation Notes

In general, referencing the weight of a nonexistent edge is undefined behavior. Do not rely on the weights matrix as a substitute for the graph's adjacency_matrix.

source
+ 1
source
Graphs.squashMethod
squash(g)

Return a copy of a graph with the smallest practical eltype that can accommodate all vertices.

May also return the original graph if the eltype does not change.

source
Graphs.weightsMethod
weights(g)

Return the weights of the edges of a graph g as a matrix. Defaults to Graphs.DefaultDistance.

Implementation Notes

In general, referencing the weight of a nonexistent edge is undefined behavior. Do not rely on the weights matrix as a substitute for the graph's adjacency_matrix.

source
diff --git a/dev/core_functions/interface/index.html b/dev/core_functions/interface/index.html index b76c0fcd..0657cb15 100644 --- a/dev/core_functions/interface/index.html +++ b/dev/core_functions/interface/index.html @@ -1,12 +1,12 @@ -AbstractGraph interface · Graphs.jl

AbstractGraph interface

Graphs.jl defines the AbstractGraph interface for compatibility with external graph formats.

Index

Full docs

Graphs.NotImplementedErrorType
NotImplementedError{M}(m)

Exception thrown when a method from the AbstractGraph interface is not implemented by a given graph type.

source
Base.eltypeMethod
eltype(G)

Return the type of the graph's vertices (must be <: Integer)

source
Base.reverseMethod
reverse(e)

Create a new edge from e with source and destination vertices reversed.

Examples

julia> using Graphs
+AbstractGraph interface · Graphs.jl

AbstractGraph interface

Graphs.jl defines the AbstractGraph interface for compatibility with external graph formats.

Index

Full docs

Graphs.NotImplementedErrorType
NotImplementedError{M}(m)

Exception thrown when a method from the AbstractGraph interface is not implemented by a given graph type.

source
Base.eltypeMethod
eltype(G)

Return the type of the graph's vertices (must be <: Integer)

source
Base.reverseMethod
reverse(e)

Create a new edge from e with source and destination vertices reversed.

Examples

julia> using Graphs
 
 julia> g = SimpleDiGraph(2);
 
 julia> add_edge!(g, 1, 2);
 
 julia> reverse(first(edges(g)))
-Edge 2 => 1
source
Base.zeroMethod
zero(G)

Return a zero-vertex, zero-edge version of the graph type G. The fallback is defined for graph values zero(g::G) = zero(G).

Examples

julia> using Graphs
+Edge 2 => 1
source
Base.zeroMethod
zero(G)

Return a zero-vertex, zero-edge version of the graph type G. The fallback is defined for graph values zero(g::G) = zero(G).

Examples

julia> using Graphs
 
 julia> g = SimpleDiGraph([0 1 0 0 0; 0 0 1 0 0; 1 0 0 1 0; 0 0 0 0 1; 0 0 0 1 0]);
 
@@ -14,21 +14,21 @@
 {0, 0} directed simple Int64 graph
 
 julia> zero(g)
-{0, 0} directed simple Int64 graph
source
Graphs.dstMethod
dst(e)

Return the destination vertex of edge e.

Examples

julia> using Graphs
+{0, 0} directed simple Int64 graph
source
Graphs.dstMethod
dst(e)

Return the destination vertex of edge e.

Examples

julia> using Graphs
 
 julia> g = SimpleGraph(2);
 
 julia> add_edge!(g, 1, 2);
 
 julia> dst(first(edges(g)))
-2
source
Graphs.edgesMethod
edges(g)

Return (an iterator to or collection of) the edges of a graph. For AbstractSimpleGraphs it returns a SimpleEdgeIter. The expressions e in edges(g) and e ∈ edges(g) evaluate as calls to has_edge.

Implementation Notes

A returned iterator is valid for one pass over the edges, and is invalidated by changes to g.

Examples

julia> using Graphs
+2
source
Graphs.edgesMethod
edges(g)

Return (an iterator to or collection of) the edges of a graph. For AbstractSimpleGraphs it returns a SimpleEdgeIter. The expressions e in edges(g) and e ∈ edges(g) evaluate as calls to has_edge.

Implementation Notes

A returned iterator is valid for one pass over the edges, and is invalidated by changes to g.

Examples

julia> using Graphs
 
 julia> g = path_graph(3);
 
 julia> collect(edges(g))
 2-element Vector{Graphs.SimpleGraphs.SimpleEdge{Int64}}:
  Edge 1 => 2
- Edge 2 => 3
source
Graphs.has_edgeMethod
has_edge(g, s, d)

Return true if the graph g has an edge from node s to node d.

An optional has_edge(g, e) can be implemented to check if an edge belongs to a graph, including any data other than source and destination node.

e in edges(g) or e ∈ edges(g) evaluate as calls to has_edge, c.f. edges.

Examples

julia> using Graphs
+ Edge 2 => 3
source
Graphs.has_edgeMethod
has_edge(g, s, d)

Return true if the graph g has an edge from node s to node d.

An optional has_edge(g, e) can be implemented to check if an edge belongs to a graph, including any data other than source and destination node.

e in edges(g) or e ∈ edges(g) evaluate as calls to has_edge, c.f. edges.

Examples

julia> using Graphs
 
 julia> g = SimpleDiGraph(2);
 
@@ -38,20 +38,20 @@
 true
 
 julia> has_edge(g, 2, 1)
-false
source
Graphs.has_vertexMethod
has_vertex(g, v)

Return true if v is a vertex of g.

Examples

julia> using Graphs
+false
source
Graphs.has_vertexMethod
has_vertex(g, v)

Return true if v is a vertex of g.

Examples

julia> using Graphs
 
 julia> has_vertex(SimpleGraph(2), 1)
 true
 
 julia> has_vertex(SimpleGraph(2), 3)
-false
source
Graphs.inneighborsMethod
inneighbors(g, v)

Return a list of all neighbors connected to vertex v by an incoming edge.

Implementation Notes

Returns a reference to the current graph's internal structures, not a copy. Do not modify result. If the graph is modified, the behavior is undefined: the array behind this reference may be modified too, but this is not guaranteed.

Examples

julia> using Graphs
+false
source
Graphs.inneighborsMethod
inneighbors(g, v)

Return a list of all neighbors connected to vertex v by an incoming edge.

Implementation Notes

Returns a reference to the current graph's internal structures, not a copy. Do not modify result. If the graph is modified, the behavior is undefined: the array behind this reference may be modified too, but this is not guaranteed.

Examples

julia> using Graphs
 
 julia> g = SimpleDiGraph([0 1 0 0 0; 0 0 1 0 0; 1 0 0 1 0; 0 0 0 0 1; 0 0 0 1 0]);
 
 julia> inneighbors(g, 4)
 2-element Vector{Int64}:
  3
- 5
source
Graphs.is_directedMethod
is_directed(G)

Return true if the graph type G is a directed graph; false otherwise. New graph types must implement is_directed(::Type{<:G}). The method can also be called with is_directed(g::G)

Examples

julia> using Graphs
+ 5
source
Graphs.is_directedMethod
is_directed(G)

Return true if the graph type G is a directed graph; false otherwise. New graph types must implement is_directed(::Type{<:G}). The method can also be called with is_directed(g::G)

Examples

julia> using Graphs
 
 julia> is_directed(SimpleGraph(2))
 false
@@ -60,35 +60,35 @@
 false
 
 julia> is_directed(SimpleDiGraph(2))
-true
source
Graphs.neMethod
ne(g)

Return the number of edges in g.

Examples

julia> using Graphs
+true
source
Graphs.neMethod
ne(g)

Return the number of edges in g.

Examples

julia> using Graphs
 
 julia> g = path_graph(3);
 
 julia> ne(g)
-2
source
Graphs.nvMethod
nv(g)

Return the number of vertices in g.

Examples

julia> using Graphs
+2
source
Graphs.nvMethod
nv(g)

Return the number of vertices in g.

Examples

julia> using Graphs
 
 julia> nv(SimpleGraph(3))
-3
source
Graphs.outneighborsMethod
outneighbors(g, v)

Return a list of all neighbors connected to vertex v by an outgoing edge.

Implementation Notes

Returns a reference to the current graph's internal structures, not a copy. Do not modify result. If the graph is modified, the behavior is undefined: the array behind this reference may be modified too, but this is not guaranteed.

Examples

julia> using Graphs
+3
source
Graphs.outneighborsMethod
outneighbors(g, v)

Return a list of all neighbors connected to vertex v by an outgoing edge.

Implementation Notes

Returns a reference to the current graph's internal structures, not a copy. Do not modify result. If the graph is modified, the behavior is undefined: the array behind this reference may be modified too, but this is not guaranteed.

Examples

julia> using Graphs
 
 julia> g = SimpleDiGraph([0 1 0 0 0; 0 0 1 0 0; 1 0 0 1 0; 0 0 0 0 1; 0 0 0 1 0]);
 
 julia> outneighbors(g, 4)
 1-element Vector{Int64}:
- 5
source
Graphs.srcMethod
src(e)

Return the source vertex of edge e.

Examples

julia> using Graphs
+ 5
source
Graphs.srcMethod
src(e)

Return the source vertex of edge e.

Examples

julia> using Graphs
 
 julia> g = SimpleGraph(2);
 
 julia> add_edge!(g, 1, 2);
 
 julia> src(first(edges(g)))
-1
source
Graphs.verticesMethod
vertices(g)

Return (an iterator to or collection of) the vertices of a graph.

Implementation Notes

A returned iterator is valid for one pass over the vertices, and is invalidated by changes to g.

Examples

julia> using Graphs
+1
source
Graphs.verticesMethod
vertices(g)

Return (an iterator to or collection of) the vertices of a graph.

Implementation Notes

A returned iterator is valid for one pass over the vertices, and is invalidated by changes to g.

Examples

julia> using Graphs
 
 julia> collect(vertices(SimpleGraph(4)))
 4-element Vector{Int64}:
  1
  2
  3
- 4
source
Base.zeroMethod
zero(G)

Return a zero-vertex, zero-edge version of the graph type G. The fallback is defined for graph values zero(g::G) = zero(G).

Examples

julia> using Graphs
+ 4
source
Base.zeroMethod
zero(G)

Return a zero-vertex, zero-edge version of the graph type G. The fallback is defined for graph values zero(g::G) = zero(G).

Examples

julia> using Graphs
 
 julia> g = SimpleDiGraph([0 1 0 0 0; 0 0 1 0 0; 1 0 0 1 0; 0 0 0 0 1; 0 0 0 1 0]);
 
@@ -96,4 +96,4 @@
 {0, 0} directed simple Int64 graph
 
 julia> zero(g)
-{0, 0} directed simple Int64 graph
source
+{0, 0} directed simple Int64 graph
source
diff --git a/dev/core_functions/module/index.html b/dev/core_functions/module/index.html index 7e0a1685..b232345a 100644 --- a/dev/core_functions/module/index.html +++ b/dev/core_functions/module/index.html @@ -1,2 +1,2 @@ -Module · Graphs.jl

Module

Graphs.jl has some module-level definitions.

Index

Full docs

Graphs.GraphsModule
Graphs

An optimized graphs package.

Simple graphs (not multi- or hypergraphs) are represented in a memory- and time-efficient manner with adjacency lists and edge sets. Both directed and undirected graphs are supported via separate types, and conversion is available from directed to undirected.

The project goal is to mirror the functionality of robust network and graph analysis libraries such as NetworkX while being simple to use and efficient. It is an explicit design decision that any data not required for graph manipulation (attributes and other information, for example) is expected to be stored outside of the graph structure itself. Such data lends itself to storage in more traditional and better-optimized mechanisms.

Full documentation is available, and tutorials are available at the JuliaGraphsTutorials repository.

source
Graphs.EdgeType
Edge

A datastruture representing an edge between two vertices in a Graph or DiGraph.

source
+Module · Graphs.jl

Module

Graphs.jl has some module-level definitions.

Index

Full docs

Graphs.GraphsModule
Graphs

An optimized graphs package.

Simple graphs (not multi- or hypergraphs) are represented in a memory- and time-efficient manner with adjacency lists and edge sets. Both directed and undirected graphs are supported via separate types, and conversion is available from directed to undirected.

The project goal is to mirror the functionality of robust network and graph analysis libraries such as NetworkX while being simple to use and efficient. It is an explicit design decision that any data not required for graph manipulation (attributes and other information, for example) is expected to be stored outside of the graph structure itself. Such data lends itself to storage in more traditional and better-optimized mechanisms.

Full documentation is available, and tutorials are available at the JuliaGraphsTutorials repository.

source
Graphs.EdgeType
Edge

A datastruture representing an edge between two vertices in a Graph or DiGraph.

source
diff --git a/dev/core_functions/operators/index.html b/dev/core_functions/operators/index.html index 750832ec..a8138a70 100644 --- a/dev/core_functions/operators/index.html +++ b/dev/core_functions/operators/index.html @@ -1,5 +1,5 @@ -Operators · Graphs.jl

Operators

Graphs.jl implements the following graph operators. In general, functions with two graph arguments will require them to be of the same type (either both SimpleGraph or both SimpleDiGraph).

Index

Full docs

Base.intersectMethod
intersect(g, h)

Return a graph with edges that are only in both graph g and graph h.

Implementation Notes

This function may produce a graph with 0-degree vertices. Preserves the eltype of the input graph.

Examples

julia> using Graphs
+Operators · Graphs.jl

Operators

Graphs.jl implements the following graph operators. In general, functions with two graph arguments will require them to be of the same type (either both SimpleGraph or both SimpleDiGraph).

Index

Full docs

Base.intersectMethod
intersect(g, h)

Return a graph with edges that are only in both graph g and graph h.

Implementation Notes

This function may produce a graph with 0-degree vertices. Preserves the eltype of the input graph.

Examples

julia> using Graphs
 
 julia> g1 = SimpleDiGraph([0 1 0 0 0; 0 0 1 0 0; 1 0 0 1 0; 0 0 0 0 1; 0 0 0 1 0]);
 
@@ -8,7 +8,7 @@
 julia> foreach(println, edges(intersect(g1, g2)))
 Edge 1 => 2
 Edge 2 => 3
-Edge 3 => 1
source
Base.joinMethod
join(g, h)

Return a graph that combines graphs g and h using blockdiag and then adds all the edges between the vertices in g and those in h.

Implementation Notes

Preserves the eltype of the input graph. Will error if the number of vertices in the generated graph exceeds the eltype.

Examples

julia> using Graphs
+Edge 3 => 1
source
Base.joinMethod
join(g, h)

Return a graph that combines graphs g and h using blockdiag and then adds all the edges between the vertices in g and those in h.

Implementation Notes

Preserves the eltype of the input graph. Will error if the number of vertices in the generated graph exceeds the eltype.

Examples

julia> using Graphs
 
 julia> g = join(star_graph(3), path_graph(2))
 {5, 9} undirected simple Int64 graph
@@ -23,7 +23,7 @@
  Edge 2 => 5
  Edge 3 => 4
  Edge 3 => 5
- Edge 4 => 5
source
Base.reverseFunction
reverse(g)

Return a directed graph where all edges are reversed from the original directed graph.

Implementation Notes

Preserves the eltype of the input graph.

Examples

julia> using Graphs
+ Edge 4 => 5
source
Base.reverseFunction
reverse(g)

Return a directed graph where all edges are reversed from the original directed graph.

Implementation Notes

Preserves the eltype of the input graph.

Examples

julia> using Graphs
 
 julia> g = SimpleDiGraph([0 1 0 0 0; 0 0 1 0 0; 1 0 0 1 0; 0 0 0 0 1; 0 0 0 1 0]);
 
@@ -33,7 +33,7 @@
 Edge 3 => 2
 Edge 4 => 3
 Edge 4 => 5
-Edge 5 => 4
source
Base.reverse!Function
reverse!(g)

In-place reverse of a directed graph (modifies the original graph). See reverse for a non-modifying version.

source
Base.sizeMethod
size(g, i)

Return the number of vertices in g if i=1 or i=2, or 1 otherwise.

Examples

julia> using Graphs
+Edge 5 => 4
source
Base.reverse!Function
reverse!(g)

In-place reverse of a directed graph (modifies the original graph). See reverse for a non-modifying version.

source
Base.sizeMethod
size(g, i)

Return the number of vertices in g if i=1 or i=2, or 1 otherwise.

Examples

julia> using Graphs
 
 julia> g = cycle_graph(4);
 
@@ -44,7 +44,7 @@
 4
 
 julia> size(g, 3)
-1
source
Base.sumMethod
sum(g, i)

Return a vector of indegree (i=1) or outdegree (i=2) values for graph g.

Examples

julia> using Graphs
+1
source
Base.sumMethod
sum(g, i)

Return a vector of indegree (i=1) or outdegree (i=2) values for graph g.

Examples

julia> using Graphs
 
 julia> g = SimpleDiGraph([0 1 0 0 0; 0 0 1 0 0; 1 0 0 1 0; 0 0 0 0 1; 0 0 0 1 0]);
 
@@ -62,12 +62,12 @@
  1
  1
  2
- 1
source
Base.sumMethod
sum(g)

Return the number of edges in g.

Examples

julia> using Graphs
+ 1
source
Base.sumMethod
sum(g)

Return the number of edges in g.

Examples

julia> using Graphs
 
 julia> g = SimpleGraph([0 1 0; 1 0 1; 0 1 0]);
 
 julia> sum(g)
-2
source
Base.unionMethod
union(g, h)

Return a graph that combines graphs g and h by taking the set union of all vertices and edges.

Implementation Notes

Preserves the eltype of the input graph. Will error if the number of vertices in the generated graph exceeds the eltype.

Examples

julia> using Graphs
+2
source
Base.unionMethod
union(g, h)

Return a graph that combines graphs g and h by taking the set union of all vertices and edges.

Implementation Notes

Preserves the eltype of the input graph. Will error if the number of vertices in the generated graph exceeds the eltype.

Examples

julia> using Graphs
 
 julia> g = SimpleGraph(3); h = SimpleGraph(5);
 
@@ -89,7 +89,7 @@
  Edge 1 => 3
  Edge 3 => 4
  Edge 3 => 5
- Edge 4 => 5
source
Graphs.cartesian_productMethod
cartesian_product(g, h)

Return the cartesian product of g and h.

Implementation Notes

Preserves the eltype of the input graph. Will error if the number of vertices in the generated graph exceeds the eltype.

Examples

julia> using Graphs
+ Edge 4 => 5
source
Graphs.cartesian_productMethod
cartesian_product(g, h)

Return the cartesian product of g and h.

Implementation Notes

Preserves the eltype of the input graph. Will error if the number of vertices in the generated graph exceeds the eltype.

Examples

julia> using Graphs
 
 julia> g = cartesian_product(star_graph(3), path_graph(3))
 {9, 12} undirected simple Int64 graph
@@ -107,7 +107,7 @@
  Edge 4 => 5
  Edge 5 => 6
  Edge 7 => 8
- Edge 8 => 9
source
Graphs.complementMethod
complement(g)

Return the graph complement of a graph

Implementation Notes

Preserves the eltype of the input graph.

Examples

julia> using Graphs
 
 julia> g = SimpleDiGraph([0 1 0 0 0; 0 0 1 0 0; 1 0 0 1 0; 0 0 0 0 1; 0 0 0 1 0]);
 
@@ -125,7 +125,7 @@
 Edge 4 => 3
 Edge 5 => 1
 Edge 5 => 2
-Edge 5 => 3
source
Graphs.compute_shiftsMethod
compute_shifts(n::Int, x::AbstractArray)

Determine how many elements of x are less than i for all i in 1:n.

source
Graphs.crosspathFunction
crosspath(len::Integer, g::Graph)

Return a graph that duplicates g len times and connects each vertex with its copies in a path.

Implementation Notes

Preserves the eltype of the input graph. Will error if the number of vertices in the generated graph exceeds the eltype.

Examples

julia> using Graphs
+Edge 5 => 3
source
Graphs.compute_shiftsMethod
compute_shifts(n::Int, x::AbstractArray)

Determine how many elements of x are less than i for all i in 1:n.

source
Graphs.crosspathFunction
crosspath(len::Integer, g::Graph)

Return a graph that duplicates g len times and connects each vertex with its copies in a path.

Implementation Notes

Preserves the eltype of the input graph. Will error if the number of vertices in the generated graph exceeds the eltype.

Examples

julia> using Graphs
 
 julia> g = crosspath(3, path_graph(3))
 {9, 12} undirected simple Int64 graph
@@ -143,7 +143,7 @@
  Edge 5 => 8
  Edge 6 => 9
  Edge 7 => 8
- Edge 8 => 9
source
Graphs.differenceMethod
difference(g, h)

Return a graph with edges in graph g that are not in graph h.

Implementation Notes

Note that this function may produce a graph with 0-degree vertices. Preserves the eltype of the input graph.

Examples

julia> using Graphs
+ Edge 8 => 9
source
Graphs.differenceMethod
difference(g, h)

Return a graph with edges in graph g that are not in graph h.

Implementation Notes

Note that this function may produce a graph with 0-degree vertices. Preserves the eltype of the input graph.

Examples

julia> using Graphs
 
 julia> g1 = SimpleDiGraph([0 1 0 0 0; 0 0 1 0 0; 1 0 0 1 0; 0 0 0 0 1; 0 0 0 1 0]);
 
@@ -152,7 +152,7 @@
 julia> foreach(println, edges(difference(g1, g2)))
 Edge 3 => 4
 Edge 4 => 5
-Edge 5 => 4
source
Graphs.egonetMethod
egonet(g, v, d, distmx=weights(g))

Return the subgraph of g induced by the neighbors of v up to distance d, using weights (optionally) provided by distmx. This is equivalent to induced_subgraph(g, neighborhood(g, v, d, dir=dir))[1].

Optional Arguments

  • dir=:out: if g is directed, this argument specifies the edge direction

with respect to v (i.e. :in or :out).

source
Graphs.egonetMethod
egonet(g, v, d, distmx=weights(g))

Return the subgraph of g induced by the neighbors of v up to distance d, using weights (optionally) provided by distmx. This is equivalent to induced_subgraph(g, neighborhood(g, v, d, dir=dir))[1].

Optional Arguments

  • dir=:out: if g is directed, this argument specifies the edge direction

with respect to v (i.e. :in or :out).

source
Graphs.induced_subgraphMethod
induced_subgraph(g, vlist)
 induced_subgraph(g, elist)

Return the subgraph of g induced by the vertices in vlist or edges in elist along with a vector mapping the new vertices to the old ones (the vertex i in the subgraph corresponds to the vertex vmap[i] in g.)

The returned graph has length(vlist) vertices, with the new vertex i corresponding to the vertex of the original graph in the i-th position of vlist.

Usage Examples

julia> g = complete_graph(10)
 
 julia> sg, vmap = induced_subgraph(g, 5:8)
@@ -173,7 +173,7 @@
 
 julia> sg, vmap = induced_subgraph(g, elist)
 
-julia> @assert sg == g[elist]
source
Graphs.merge_vertices!Method
merge_vertices!(g, vs)

Combine vertices specified in vs into single vertex whose index will be the lowest value in vs. All edges connected to vertices in vs connect to the new merged vertex.

Return a vector with new vertex values are indexed by the original vertex indices.

Implementation Notes

Supports SimpleGraph only.

Examples

julia> using Graphs
+julia> @assert sg == g[elist]
source
Graphs.merge_vertices!Method
merge_vertices!(g, vs)

Combine vertices specified in vs into single vertex whose index will be the lowest value in vs. All edges connected to vertices in vs connect to the new merged vertex.

Return a vector with new vertex values are indexed by the original vertex indices.

Implementation Notes

Supports SimpleGraph only.

Examples

julia> using Graphs
 
 julia> g = path_graph(5);
 
@@ -196,7 +196,7 @@
 3-element Vector{Graphs.SimpleGraphs.SimpleEdge{Int64}}:
  Edge 1 => 2
  Edge 2 => 3
- Edge 3 => 4
source
Graphs.merge_verticesMethod
merge_vertices(g::AbstractGraph, vs)

Create a new graph where all vertices in vs have been aliased to the same vertex minimum(vs).

Examples

julia> using Graphs
+ Edge 3 => 4
source
Graphs.merge_verticesMethod
merge_vertices(g::AbstractGraph, vs)

Create a new graph where all vertices in vs have been aliased to the same vertex minimum(vs).

Examples

julia> using Graphs
 
 julia> g = path_graph(5);
 
@@ -213,7 +213,7 @@
 3-element Vector{Graphs.SimpleGraphs.SimpleEdge{Int64}}:
  Edge 1 => 2
  Edge 2 => 3
- Edge 3 => 4
source
Graphs.symmetric_differenceMethod
symmetric_difference(g, h)

Return a graph with edges from graph g that do not exist in graph h, and vice versa.

Implementation Notes

Note that this function may produce a graph with 0-degree vertices. Preserves the eltype of the input graph. Will error if the number of vertices in the generated graph exceeds the eltype.

Examples

julia> using Graphs
+ Edge 3 => 4
source
Graphs.symmetric_differenceMethod
symmetric_difference(g, h)

Return a graph with edges from graph g that do not exist in graph h, and vice versa.

Implementation Notes

Note that this function may produce a graph with 0-degree vertices. Preserves the eltype of the input graph. Will error if the number of vertices in the generated graph exceeds the eltype.

Examples

julia> using Graphs
 
 julia> g = SimpleGraph(3); h = SimpleGraph(3);
 
@@ -229,7 +229,7 @@
 3-element Vector{Graphs.SimpleGraphs.SimpleEdge{Int64}}:
  Edge 1 => 2
  Edge 1 => 3
- Edge 2 => 3
source
Graphs.tensor_productMethod
tensor_product(g, h)

Return the tensor product of g and h.

Implementation Notes

Preserves the eltype of the input graph. Will error if the number of vertices in the generated graph exceeds the eltype.

Examples

julia> using Graphs
+ Edge 2 => 3
source
Graphs.tensor_productMethod
tensor_product(g, h)

Return the tensor product of g and h.

Implementation Notes

Preserves the eltype of the input graph. Will error if the number of vertices in the generated graph exceeds the eltype.

Examples

julia> using Graphs
 
 julia> g = tensor_product(star_graph(3), path_graph(3))
 {9, 8} undirected simple Int64 graph
@@ -243,7 +243,7 @@
  Edge 2 => 7
  Edge 2 => 9
  Edge 3 => 5
- Edge 3 => 8
source
SparseArrays.blockdiagMethod
blockdiag(g, h)

Return a graph with $|V(g)| + |V(h)|$ vertices and $|E(g)| + |E(h)|$ edges where the vertices and edges from graph h are appended to graph g.

Implementation Notes

Preserves the eltype of the input graph. Will error if the number of vertices in the generated graph exceeds the eltype.

Examples

julia> using Graphs
+ Edge 3 => 8
source
SparseArrays.blockdiagMethod
blockdiag(g, h)

Return a graph with $|V(g)| + |V(h)|$ vertices and $|E(g)| + |E(h)|$ edges where the vertices and edges from graph h are appended to graph g.

Implementation Notes

Preserves the eltype of the input graph. Will error if the number of vertices in the generated graph exceeds the eltype.

Examples

julia> using Graphs
 
 julia> g1 = SimpleDiGraph([0 1 0 0 0; 0 0 1 0 0; 1 0 0 1 0; 0 0 0 0 1; 0 0 0 1 0]);
 
@@ -261,4 +261,4 @@
 Edge 5 => 4
 Edge 6 => 7
 Edge 7 => 8
-Edge 8 => 6
source
+Edge 8 => 6
source
diff --git a/dev/core_functions/persistence/index.html b/dev/core_functions/persistence/index.html index 6e8995d9..d27d0bee 100644 --- a/dev/core_functions/persistence/index.html +++ b/dev/core_functions/persistence/index.html @@ -1,5 +1,5 @@ -Reading and writing files · Graphs.jl

Reading and writing files

Graphs.jl includes functions for working with graphs stored in various file formats/

Index

Full docs

Graphs.loadgraphMethod
loadgraph(file, gname="graph", format=LGFormat())

Read a graph named gname from file in the format format.

Implementation Notes

gname is graph-format dependent and is only used if the file contains multiple graphs; if the file format does not support multiple graphs, this value is ignored. The default value may change in the future.

source
Graphs.loadgraphsMethod
loadgraphs(file, format=LGFormat())

Load multiple graphs from file in the format format. Return a dictionary mapping graph name to graph.

Implementation Notes

For unnamed graphs the default name "graph" will be used. This default may change in the future.

source
Graphs.savegraphMethod
savegraph(file, g, gname="graph", format=LGFormat)

Saves a graph g with name gname to file in the format format. Return the number of graphs written.

Implementation Notes

The default graph name assigned to gname may change in the future.

source
Graphs.savegraphMethod
savegraph(file, d, format=LGFormat())

Save a dictionary d of graphname => graph to file in the format format. Return the number of graphs written.

Examples

julia> using Graphs
+Reading and writing files · Graphs.jl

Reading and writing files

Graphs.jl includes functions for working with graphs stored in various file formats/

Index

Full docs

Graphs.loadgraphMethod
loadgraph(file, gname="graph", format=LGFormat())

Read a graph named gname from file in the format format.

Implementation Notes

gname is graph-format dependent and is only used if the file contains multiple graphs; if the file format does not support multiple graphs, this value is ignored. The default value may change in the future.

source
Graphs.loadgraphsMethod
loadgraphs(file, format=LGFormat())

Load multiple graphs from file in the format format. Return a dictionary mapping graph name to graph.

Implementation Notes

For unnamed graphs the default name "graph" will be used. This default may change in the future.

source
Graphs.savegraphMethod
savegraph(file, g, gname="graph", format=LGFormat)

Saves a graph g with name gname to file in the format format. Return the number of graphs written.

Implementation Notes

The default graph name assigned to gname may change in the future.

source
Graphs.savegraphMethod
savegraph(file, d, format=LGFormat())

Save a dictionary d of graphname => graph to file in the format format. Return the number of graphs written.

Examples

julia> using Graphs
 
 julia> g1 = SimpleGraph(5,8)
 {5, 8} undirected simple Int64 graph
@@ -10,4 +10,4 @@
 julia> d = Dict("graph_1" => g1, "graph_2" => g2);
 
 julia> savegraph("myfile.txt", d, LGFormat())
-2

Implementation Notes

Will only work if the file format supports multiple graph types.

source
Graphs.savelgMethod
savelg(io, g, gname)

Write a graph g with name gname in a proprietary format to the IO stream designated by io. Return 1 (number of graphs written).

source
Graphs.savelg_multMethod
savelg_mult(io, graphs)

Write a dictionary of (name=>graph) to an IO stream io, with default GZip compression. Return number of graphs written.

source
+2

Implementation Notes

Will only work if the file format supports multiple graph types.

source
Graphs.savelgMethod
savelg(io, g, gname)

Write a graph g with name gname in a proprietary format to the IO stream designated by io. Return 1 (number of graphs written).

source
Graphs.savelg_multMethod
savelg_mult(io, graphs)

Write a dictionary of (name=>graph) to an IO stream io, with default GZip compression. Return number of graphs written.

source
diff --git a/dev/core_functions/simplegraphs/index.html b/dev/core_functions/simplegraphs/index.html index 8905892f..9eba5412 100644 --- a/dev/core_functions/simplegraphs/index.html +++ b/dev/core_functions/simplegraphs/index.html @@ -1,5 +1,5 @@ -SimpleGraphs formats · Graphs.jl

SimpleGraphs formats

Graphs.jl provides two basic graph formats based on adjacency lists, along with many other functions defined in the Graphs.SimpleGraphs submodule.

Index

Full docs

Graphs.SimpleGraphs.SimpleDiGraphMethod
SimpleDiGraph{T}(adjm::AbstractMatrix)

Construct a SimpleDiGraph{T} from the adjacency matrix adjm. If adjm[i][j] != 0, an edge (i, j) is inserted. adjm must be a square matrix. The element type T can be omitted.

Examples

julia> using Graphs
+SimpleGraphs formats · Graphs.jl

SimpleGraphs formats

Graphs.jl provides two basic graph formats based on adjacency lists, along with many other functions defined in the Graphs.SimpleGraphs submodule.

Index

Full docs

Graphs.SimpleGraphs.SimpleDiGraphMethod
SimpleDiGraph{T}(adjm::AbstractMatrix)

Construct a SimpleDiGraph{T} from the adjacency matrix adjm. If adjm[i][j] != 0, an edge (i, j) is inserted. adjm must be a square matrix. The element type T can be omitted.

Examples

julia> using Graphs
 
 julia> A1 = [false true; false false]
 2×2 Matrix{Bool}:
@@ -15,14 +15,14 @@
  5  0
 
 julia> SimpleDiGraph{Int16}(A2)
-{2, 3} directed simple Int16 graph
source
Graphs.SimpleGraphs.SimpleDiGraphMethod
SimpleDiGraph(g::AbstractSimpleGraph)

Construct an directed SimpleDiGraph from a graph g. The element type is the same as for g.

Examples

julia> using Graphs
+{2, 3} directed simple Int16 graph
source
Graphs.SimpleGraphs.SimpleDiGraphMethod
SimpleDiGraph(g::AbstractSimpleGraph)

Construct an directed SimpleDiGraph from a graph g. The element type is the same as for g.

Examples

julia> using Graphs
 
 julia> g = path_graph(Int8(5))
 {5, 4} undirected simple Int8 graph
 
 julia> SimpleDiGraph(g)
-{5, 8} directed simple Int8 graph
source
Graphs.SimpleGraphs.SimpleDiGraphMethod
SimpleDiGraph{T}(g::AbstractGraph)
-SimpleDiGraph(g::AbstractGraph)

Construct a SimpleDiGraph from any AbstractGraph by enumerating edges.

If g is undirected, both directed edges (u, v) and (v, u) are added if undirected edge {u, v} exists.

source
Graphs.SimpleGraphs.SimpleDiGraphMethod
SimpleDiGraph(edge_list::Vector)

Construct a SimpleDiGraph from a vector of edges. The element type is taken from the edges in edge_list. The number of vertices is the highest that is used in an edge in edge_list.

Implementation Notes

This constructor works the fastest when edge_list is sorted by the lexical ordering and does not contain any duplicates.

See also

SimpleDiGraphFromIterator

Examples

julia> using Graphs
+{5, 8} directed simple Int8 graph
source
Graphs.SimpleGraphs.SimpleDiGraphMethod
SimpleDiGraph{T}(g::AbstractGraph)
+SimpleDiGraph(g::AbstractGraph)

Construct a SimpleDiGraph from any AbstractGraph by enumerating edges.

If g is undirected, both directed edges (u, v) and (v, u) are added if undirected edge {u, v} exists.

source
Graphs.SimpleGraphs.SimpleDiGraphMethod
SimpleDiGraph(edge_list::Vector)

Construct a SimpleDiGraph from a vector of edges. The element type is taken from the edges in edge_list. The number of vertices is the highest that is used in an edge in edge_list.

Implementation Notes

This constructor works the fastest when edge_list is sorted by the lexical ordering and does not contain any duplicates.

See also

SimpleDiGraphFromIterator

Examples

julia> using Graphs
 
 julia> el = Edge.([ (1, 3), (1, 5), (3, 1) ])
 3-element Vector{Graphs.SimpleGraphs.SimpleEdge{Int64}}:
@@ -31,19 +31,19 @@
  Edge 3 => 1
  
 julia> SimpleDiGraph(el)
-{5, 3} directed simple Int64 graph
source
Graphs.SimpleGraphs.SimpleDiGraphMethod
SimpleDiGraph{T}(g::SimpleDiGraph)

Construct a copy of g. If the element type T is specified, the vertices of g are converted to this type. Otherwise the element type is the same as for g.

Examples

julia> using Graphs
+{5, 3} directed simple Int64 graph
source
Graphs.SimpleGraphs.SimpleDiGraphMethod
SimpleDiGraph{T}(g::SimpleDiGraph)

Construct a copy of g. If the element type T is specified, the vertices of g are converted to this type. Otherwise the element type is the same as for g.

Examples

julia> using Graphs
 
 julia> g = complete_digraph(5)
 {5, 20} directed simple Int64 graph
 
 julia> SimpleDiGraph{UInt8}(g)
-{5, 20} directed simple UInt8 graph
source
Graphs.SimpleGraphs.SimpleDiGraphMethod
SimpleDiGraph(::Type{T})

Construct an empty SimpleDiGraph{T} with 0 vertices and 0 edges.

Examples

julia> using Graphs
+{5, 20} directed simple UInt8 graph
source
Graphs.SimpleGraphs.SimpleDiGraphMethod
SimpleDiGraph(::Type{T})

Construct an empty SimpleDiGraph{T} with 0 vertices and 0 edges.

Examples

julia> using Graphs
 
 julia> SimpleDiGraph(UInt8)
-{0, 0} directed simple UInt8 graph
source
Graphs.SimpleGraphs.SimpleDiGraphMethod
SimpleDiGraph{T}(n=0)

Construct a SimpleDiGraph{T} with n vertices and 0 edges. If not specified, the element type T is the type of n.

Examples

julia> using Graphs
+{0, 0} directed simple UInt8 graph
source
Graphs.SimpleGraphs.SimpleDiGraphMethod
SimpleDiGraph{T}(n=0)

Construct a SimpleDiGraph{T} with n vertices and 0 edges. If not specified, the element type T is the type of n.

Examples

julia> using Graphs
 
 julia> SimpleDiGraph(UInt8(10))
-{10, 0} directed simple UInt8 graph
source
Graphs.SimpleGraphs.SimpleDiGraphFromIteratorMethod
SimpleDiGraphFromIterator(iter)

Create a SimpleDiGraph from an iterator iter. The elements in iter must be of type <: SimpleEdge.

Examples

julia> using Graphs
 
 julia> g = SimpleDiGraph(2);
 
@@ -57,7 +57,7 @@
 julia> collect(edges(h))
 2-element Vector{Graphs.SimpleGraphs.SimpleEdge{Int64}}:
  Edge 1 => 2
- Edge 2 => 1
source
Graphs.SimpleGraphs.SimpleEdgeIterType
SimpleEdgeIter

The function edges returns a SimpleEdgeIter for AbstractSimpleGraphs. The iterates are in lexicographical order, smallest first. The iterator is valid for one pass over the edges, and is invalidated by changes to the graph.

Examples

julia> using Graphs
+ Edge 2 => 1
source
Graphs.SimpleGraphs.SimpleEdgeIterType
SimpleEdgeIter

The function edges returns a SimpleEdgeIter for AbstractSimpleGraphs. The iterates are in lexicographical order, smallest first. The iterator is valid for one pass over the edges, and is invalidated by changes to the graph.

Examples

julia> using Graphs
 
 julia> g = path_graph(3);
 
@@ -68,7 +68,7 @@
 (Edge 1 => 2, (1, 2))
 
 julia> iterate(es, e_it[2])
-(Edge 2 => 3, (2, 3))
source
Graphs.SimpleGraphs.SimpleGraphMethod
SimpleGraph{T}(adjm::AbstractMatrix)

Construct a SimpleGraph{T} from the adjacency matrix adjm. If adjm[i][j] != 0, an edge (i, j) is inserted. adjm must be a square and symmetric matrix. The element type T can be omitted.

Examples

julia> using Graphs
+(Edge 2 => 3, (2, 3))
source
Graphs.SimpleGraphs.SimpleGraphMethod
SimpleGraph{T}(adjm::AbstractMatrix)

Construct a SimpleGraph{T} from the adjacency matrix adjm. If adjm[i][j] != 0, an edge (i, j) is inserted. adjm must be a square and symmetric matrix. The element type T can be omitted.

Examples

julia> using Graphs
 
 julia> A1 = [false true; true false];
 
@@ -78,20 +78,20 @@
 julia> A2 = [2 7; 7 0];
 
 julia> SimpleGraph{Int16}(A2)
-{2, 2} undirected simple Int16 graph
source
Graphs.SimpleGraphs.SimpleGraphMethod
SimpleGraph(g::SimpleDiGraph)

Construct an undirected SimpleGraph from a directed SimpleDiGraph. Every directed edge in g is added as an undirected edge. The element type is the same as for g.

Examples

julia> using Graphs
+{2, 2} undirected simple Int16 graph
source
Graphs.SimpleGraphs.SimpleGraphMethod
SimpleGraph(g::SimpleDiGraph)

Construct an undirected SimpleGraph from a directed SimpleDiGraph. Every directed edge in g is added as an undirected edge. The element type is the same as for g.

Examples

julia> using Graphs
 
 julia> g = path_digraph(Int8(5))
 {5, 4} directed simple Int8 graph
 
 julia> SimpleGraph(g)
-{5, 4} undirected simple Int8 graph
source
Graphs.SimpleGraphs.SimpleGraphMethod
SimpleGraph{T}(g::SimpleGraph)

Construct a copy of g. If the element type T is specified, the vertices of g are converted to this type. Otherwise the element type is the same as for g.

Examples

julia> using Graphs
+{5, 4} undirected simple Int8 graph
source
Graphs.SimpleGraphs.SimpleGraphMethod
SimpleGraph{T}(g::SimpleGraph)

Construct a copy of g. If the element type T is specified, the vertices of g are converted to this type. Otherwise the element type is the same as for g.

Examples

julia> using Graphs
 
 julia> g = complete_graph(5)
 {5, 10} undirected simple Int64 graph
 
 julia> SimpleGraph{UInt8}(g)
-{5, 10} undirected simple UInt8 graph
source
Graphs.SimpleGraphs.SimpleGraphMethod
SimpleGraph{T}(g::AbstractGraph)
-SimpleGraph(g::AbstractGraph)

Construct a SimpleGraph from any AbstractGraph by enumerating edges.

If g is directed, a directed edge {u, v} is added if either directed edge (u, v) or (v, u) exists.

source
Graphs.SimpleGraphs.SimpleGraphMethod
SimpleGraph(edge_list::Vector)

Construct a SimpleGraph from a vector of edges. The element type is taken from the edges in edge_list. The number of vertices is the highest that is used in an edge in edge_list.

Implementation Notes

This constructor works the fastest when edge_list is sorted by the lexical ordering and does not contain any duplicates.

See also

SimpleGraphFromIterator

Examples

julia> using Graphs
+{5, 10} undirected simple UInt8 graph
source
Graphs.SimpleGraphs.SimpleGraphMethod
SimpleGraph{T}(g::AbstractGraph)
+SimpleGraph(g::AbstractGraph)

Construct a SimpleGraph from any AbstractGraph by enumerating edges.

If g is directed, a directed edge {u, v} is added if either directed edge (u, v) or (v, u) exists.

source
Graphs.SimpleGraphs.SimpleGraphMethod
SimpleGraph(edge_list::Vector)

Construct a SimpleGraph from a vector of edges. The element type is taken from the edges in edge_list. The number of vertices is the highest that is used in an edge in edge_list.

Implementation Notes

This constructor works the fastest when edge_list is sorted by the lexical ordering and does not contain any duplicates.

See also

SimpleGraphFromIterator

Examples

julia> using Graphs
 
 julia> el = Edge.([ (1, 2), (1, 5) ])
 2-element Vector{Graphs.SimpleGraphs.SimpleEdge{Int64}}:
@@ -99,13 +99,13 @@
  Edge 1 => 5
 
 julia> SimpleGraph(el)
-{5, 2} undirected simple Int64 graph
source
Graphs.SimpleGraphs.SimpleGraphMethod
SimpleGraph(::Type{T})

Construct an empty SimpleGraph{T} with 0 vertices and 0 edges.

Examples

julia> using Graphs
+{5, 2} undirected simple Int64 graph
source
Graphs.SimpleGraphs.SimpleGraphMethod
SimpleGraph(::Type{T})

Construct an empty SimpleGraph{T} with 0 vertices and 0 edges.

Examples

julia> using Graphs
 
 julia> SimpleGraph(UInt8)
-{0, 0} undirected simple UInt8 graph
source
Graphs.SimpleGraphs.SimpleGraphMethod
SimpleGraph{T}(n=0)

Construct a SimpleGraph{T} with n vertices and 0 edges. If not specified, the element type T is the type of n.

Examples

julia> using Graphs
+{0, 0} undirected simple UInt8 graph
source
Graphs.SimpleGraphs.SimpleGraphMethod
SimpleGraph{T}(n=0)

Construct a SimpleGraph{T} with n vertices and 0 edges. If not specified, the element type T is the type of n.

Examples

julia> using Graphs
 
 julia> SimpleGraph(UInt8(10))
-{10, 0} undirected simple UInt8 graph
source
Graphs.SimpleGraphs.SimpleGraphFromIteratorMethod
SimpleGraphFromIterator(iter)

Create a SimpleGraph from an iterator iter. The elements in iter must be of type <: SimpleEdge.

Examples

julia> using Graphs
 
 julia> g = SimpleGraph(3);
 
@@ -118,7 +118,7 @@
 julia> collect(edges(h))
 2-element Vector{Graphs.SimpleGraphs.SimpleEdge{Int64}}:
  Edge 1 => 2
- Edge 2 => 3
source
Graphs.SimpleGraphs.add_edge!Method
add_edge!(g, e)

Add an edge e to graph g. Return true if edge was added successfully, otherwise return false.

Examples

julia> using Graphs
+ Edge 2 => 3
source
Graphs.SimpleGraphs.add_edge!Method
add_edge!(g, e)

Add an edge e to graph g. Return true if edge was added successfully, otherwise return false.

Examples

julia> using Graphs
 
 julia> g = SimpleGraph(2);
 
@@ -126,7 +126,7 @@
 true
 
 julia> add_edge!(g, 2, 3)
-false
source
Graphs.SimpleGraphs.add_vertex!Method
add_vertex!(g)

Add a new vertex to the graph g. Return true if addition was successful.

Examples

julia> using Graphs
 
 julia> g = SimpleGraph(Int8(typemax(Int8) - 1))
 {126, 0} undirected simple Int8 graph
@@ -135,7 +135,7 @@
 true
 
 julia> add_vertex!(g)
-false
source
Graphs.SimpleGraphs.adjMethod
adj(g[, v])

Return the adjacency list of a graph. If v is specified, return only the adjacency list for that vertex.

Implementation Notes

Returns a reference to the current graph's internal structures, not a copy. Do not modify result. If the graph is modified, the behavior is undefined: the array behind this reference may be modified too, but this is not guaranteed.

source
Graphs.SimpleGraphs.badjMethod
badj(g::SimpleGraph[, v::Integer])

Return the backwards adjacency list of a graph. If v is specified, return only the adjacency list for that vertex.

Implementation Notes

Returns a reference to the current graph's internal structures, not a copy. Do not modify result. If the graph is modified, the behavior is undefined: the array behind this reference may be modified too, but this is not guaranteed.

source
Graphs.SimpleGraphs.rem_edge!Method
rem_edge!(g, e)

Remove an edge e from graph g. Return true if edge was removed successfully, otherwise return false.

Implementation Notes

If rem_edge! returns false, the graph may be in an indeterminate state, as there are multiple points where the function can exit with false.

Examples

julia> using Graphs
+false
source
Graphs.SimpleGraphs.adjMethod
adj(g[, v])

Return the adjacency list of a graph. If v is specified, return only the adjacency list for that vertex.

Implementation Notes

Returns a reference to the current graph's internal structures, not a copy. Do not modify result. If the graph is modified, the behavior is undefined: the array behind this reference may be modified too, but this is not guaranteed.

source
Graphs.SimpleGraphs.badjMethod
badj(g::SimpleGraph[, v::Integer])

Return the backwards adjacency list of a graph. If v is specified, return only the adjacency list for that vertex.

Implementation Notes

Returns a reference to the current graph's internal structures, not a copy. Do not modify result. If the graph is modified, the behavior is undefined: the array behind this reference may be modified too, but this is not guaranteed.

source
Graphs.SimpleGraphs.rem_edge!Method
rem_edge!(g, e)

Remove an edge e from graph g. Return true if edge was removed successfully, otherwise return false.

Implementation Notes

If rem_edge! returns false, the graph may be in an indeterminate state, as there are multiple points where the function can exit with false.

Examples

julia> using Graphs
 
 julia> g = SimpleGraph(2);
 
@@ -145,7 +145,7 @@
 true
 
 julia> rem_edge!(g, 1, 2)
-false
source
Graphs.SimpleGraphs.rem_vertices!Method
rem_vertices!(g, vs, keep_order=false) -> vmap

Remove all vertices in vs from g. Return a vector vmap that maps the vertices in the modified graph to the ones in the unmodified graph. If keep_order is true, the vertices in the modified graph appear in the same order as they did in the unmodified graph. This might be slower.

Implementation Notes

This function is not part of the official Graphs API and is subject to change/removal between major versions.

Examples

julia> using Graphs
+false
source
Graphs.SimpleGraphs.rem_vertices!Method
rem_vertices!(g, vs, keep_order=false) -> vmap

Remove all vertices in vs from g. Return a vector vmap that maps the vertices in the modified graph to the ones in the unmodified graph. If keep_order is true, the vertices in the modified graph appear in the same order as they did in the unmodified graph. This might be slower.

Implementation Notes

This function is not part of the official Graphs API and is subject to change/removal between major versions.

Examples

julia> using Graphs
 
 julia> g = complete_graph(5)
 {5, 10} undirected simple Int64 graph
@@ -159,7 +159,7 @@
  5
 
 julia> g
-{3, 3} undirected simple Int64 graph
source
Graphs.SimpleGraphs.AbstractSimpleGraphType
AbstractSimpleGraph

An abstract type representing a simple graph structure. AbstractSimpleGraphs must have the following elements:

  • vertices::UnitRange{Integer}
  • fadjlist::Vector{Vector{Integer}}
  • ne::Integer
source
Graphs.SimpleGraphs.rem_vertex!Method
rem_vertex!(g, v)

Remove the vertex v from graph g. Return false if removal fails (e.g., if vertex is not in the graph); true otherwise.

Performance

Time complexity is $\mathcal{O}(k^2)$, where $k$ is the max of the degrees of vertex $v$ and vertex $|V|$.

Implementation Notes

This operation has to be performed carefully if one keeps external data structures indexed by edges or vertices in the graph, since internally the removal is performed swapping the vertices v and $|V|$, and removing the last vertex $|V|$ from the graph. After removal the vertices in g will be indexed by $1:|V|-1$.

Examples

julia> using Graphs
+{3, 3} undirected simple Int64 graph
source
Graphs.SimpleGraphs.AbstractSimpleGraphType
AbstractSimpleGraph

An abstract type representing a simple graph structure. AbstractSimpleGraphs must have the following elements:

  • vertices::UnitRange{Integer}
  • fadjlist::Vector{Vector{Integer}}
  • ne::Integer
source
Graphs.SimpleGraphs.rem_vertex!Method
rem_vertex!(g, v)

Remove the vertex v from graph g. Return false if removal fails (e.g., if vertex is not in the graph); true otherwise.

Performance

Time complexity is $\mathcal{O}(k^2)$, where $k$ is the max of the degrees of vertex $v$ and vertex $|V|$.

Implementation Notes

This operation has to be performed carefully if one keeps external data structures indexed by edges or vertices in the graph, since internally the removal is performed swapping the vertices v and $|V|$, and removing the last vertex $|V|$ from the graph. After removal the vertices in g will be indexed by $1:|V|-1$.

Examples

julia> using Graphs
 
 julia> g = SimpleGraph(2);
 
@@ -167,4 +167,4 @@
 true
 
 julia> rem_vertex!(g, 2)
-false
source
Graphs.SimpleGraphs.throw_if_invalid_eltypeMethod
throw_if_invalid_eltype(T)

Internal function, throw a DomainError if T is not a concrete type Integer. Can be used in the constructor of AbstractSimpleGraphs, as Julia's typesystem does not enforce concrete types, which can lead to problems. E.g SimpleGraph{Signed}.

source
Graphs.squashMethod
squash(g::Union{SimpleGraph, SimpleDiGraph}; alwayscopy=true)

Specialised version of Graphs.squash for SimpleGraph and SimpleDiGraph. If alwayscopy is true, the resulting graph will always be a copy, otherwise it can also be the original graph.

source
+false
source
Graphs.SimpleGraphs.throw_if_invalid_eltypeMethod
throw_if_invalid_eltype(T)

Internal function, throw a DomainError if T is not a concrete type Integer. Can be used in the constructor of AbstractSimpleGraphs, as Julia's typesystem does not enforce concrete types, which can lead to problems. E.g SimpleGraph{Signed}.

source
Graphs.squashMethod
squash(g::Union{SimpleGraph, SimpleDiGraph}; alwayscopy=true)

Specialised version of Graphs.squash for SimpleGraph and SimpleDiGraph. If alwayscopy is true, the resulting graph will always be a copy, otherwise it can also be the original graph.

source
diff --git a/dev/core_functions/simplegraphs_generators/index.html b/dev/core_functions/simplegraphs_generators/index.html index 34abb789..c039547f 100644 --- a/dev/core_functions/simplegraphs_generators/index.html +++ b/dev/core_functions/simplegraphs_generators/index.html @@ -1,5 +1,5 @@ -Generators for common graphs · Graphs.jl

Generators for common graphs

Graphs.jl defines generators for various families of deterministic and random graphs.

Index

Full docs

Graphs.SimpleGraphs.euclidean_graphMethod
euclidean_graph(N, d; rng=nothing, seed=nothing, L=1., p=2., cutoff=-1., bc=:open)

Generate N uniformly distributed points in the box $[0,L]^{d}$ and return a Euclidean graph, a map containing the distance on each edge and a matrix with the points' positions.

Examples

julia> using Graphs
+Generators for common graphs · Graphs.jl

Generators for common graphs

Graphs.jl defines generators for various families of deterministic and random graphs.

Index

Full docs

Graphs.SimpleGraphs.euclidean_graphMethod
euclidean_graph(N, d; rng=nothing, seed=nothing, L=1., p=2., cutoff=-1., bc=:open)

Generate N uniformly distributed points in the box $[0,L]^{d}$ and return a Euclidean graph, a map containing the distance on each edge and a matrix with the points' positions.

Examples

julia> using Graphs
 
 julia> g, dists = euclidean_graph(5, 2, cutoff=0.3);
 
@@ -11,20 +11,20 @@
   Edge 1 => 5 => 0.205756
   Edge 2 => 5 => 0.271359
   Edge 2 => 4 => 0.247703
-  Edge 4 => 5 => 0.168372
source
Graphs.SimpleGraphs.euclidean_graphMethod
euclidean_graph(points)

Given the d×N matrix points build an Euclidean graph of N vertices and return a graph and Dict containing the distance on each edge.

Optional Arguments

  • L=1: used to bound the d dimensional box from which points are selected.
  • p=2
  • bc=:open

Implementation Notes

Defining the d-dimensional vectors x[i] = points[:,i], an edge between vertices i and j is inserted if norm(x[i]-x[j], p) < cutoff. In case of negative cutoff instead every edge is inserted. For p=2 we have the standard Euclidean distance. Set bc=:periodic to impose periodic boundary conditions in the box $[0,L]^d$.

Examples

julia> using Graphs
+  Edge 4 => 5 => 0.168372
source
Graphs.SimpleGraphs.euclidean_graphMethod
euclidean_graph(points)

Given the d×N matrix points build an Euclidean graph of N vertices and return a graph and Dict containing the distance on each edge.

Optional Arguments

  • L=1: used to bound the d dimensional box from which points are selected.
  • p=2
  • bc=:open

Implementation Notes

Defining the d-dimensional vectors x[i] = points[:,i], an edge between vertices i and j is inserted if norm(x[i]-x[j], p) < cutoff. In case of negative cutoff instead every edge is inserted. For p=2 we have the standard Euclidean distance. Set bc=:periodic to impose periodic boundary conditions in the box $[0,L]^d$.

Examples

julia> using Graphs
 
 julia> pts = rand(3, 10); # 10 vertices in R^3
 
 julia> g, dists = euclidean_graph(pts, p=1, bc=:periodic) # Taxicab-distance (L^1);
 
 julia> g
-{10, 45} undirected simple Int64 graph
source
Graphs.SimpleGraphs.SimpleDiGraphMethod
SimpleDiGraph{T}(nv, ne; rng=nothing, seed=nothing)

Construct a random SimpleDiGraph{T} with nv vertices and ne edges. The graph is sampled uniformly from all such graphs. If seed >= 0, a random generator is seeded with this value. If not specified, the element type T is the type of nv.

See also

erdos_renyi

Examples

julia> using Graphs
+{10, 45} undirected simple Int64 graph
source
Graphs.SimpleGraphs.SimpleDiGraphMethod
SimpleDiGraph{T}(nv, ne; rng=nothing, seed=nothing)

Construct a random SimpleDiGraph{T} with nv vertices and ne edges. The graph is sampled uniformly from all such graphs. If seed >= 0, a random generator is seeded with this value. If not specified, the element type T is the type of nv.

See also

erdos_renyi

Examples

julia> using Graphs
 
 julia> SimpleDiGraph(5, 7)
-{5, 7} directed simple Int64 graph
source
Graphs.SimpleGraphs.SimpleGraphMethod
SimpleGraph{T}(nv, ne, edgestream::Channel)

Construct a SimpleGraph{T} with nv vertices and ne edges from edgestream. Can result in less than ne edges if the channel edgestream is closed prematurely. Duplicate edges are only counted once. The element type is the type of nv.

source
Graphs.SimpleGraphs.SimpleGraphMethod
SimpleGraph{T}(nv, ne, smb::StochasticBlockModel)

Construct a random SimpleGraph{T} with nv vertices and ne edges. The graph is sampled according to the stochastic block model smb. The element type is the type of nv.

source
Graphs.SimpleGraphs.SimpleGraphMethod
SimpleGraph{T}(nv, ne; rng=nothing, seed=nothing)

Construct a random SimpleGraph{T} with nv vertices and ne edges. The graph is sampled uniformly from all such graphs. If seed >= 0, a random generator is seeded with this value. If not specified, the element type T is the type of nv.

See also

erdos_renyi

Examples

julia> using Graphs
+{5, 7} directed simple Int64 graph
source
Graphs.SimpleGraphs.SimpleGraphMethod
SimpleGraph{T}(nv, ne, edgestream::Channel)

Construct a SimpleGraph{T} with nv vertices and ne edges from edgestream. Can result in less than ne edges if the channel edgestream is closed prematurely. Duplicate edges are only counted once. The element type is the type of nv.

source
Graphs.SimpleGraphs.SimpleGraphMethod
SimpleGraph{T}(nv, ne, smb::StochasticBlockModel)

Construct a random SimpleGraph{T} with nv vertices and ne edges. The graph is sampled according to the stochastic block model smb. The element type is the type of nv.

source
Graphs.SimpleGraphs.SimpleGraphMethod
SimpleGraph{T}(nv, ne; rng=nothing, seed=nothing)

Construct a random SimpleGraph{T} with nv vertices and ne edges. The graph is sampled uniformly from all such graphs. If seed >= 0, a random generator is seeded with this value. If not specified, the element type T is the type of nv.

See also

erdos_renyi

Examples

julia> using Graphs
 
 julia> SimpleGraph(5, 7)
-{5, 7} undirected simple Int64 graph
source
Graphs.SimpleGraphs.StochasticBlockModelType
StochasticBlockModel{T,P}

A type capturing the parameters of the SBM. Each vertex is assigned to a block and the probability of edge (i,j) depends only on the block labels of vertex i and vertex j.

The assignment is stored in nodemap and the block affinities a k by k matrix is stored in affinities.

affinities[k,l] is the probability of an edge between any vertex in block k and any vertex in block l.

Implementation Notes

Graphs are generated by taking random $i,j ∈ V$ and flipping a coin with probability affinities[nodemap[i],nodemap[j]].

source
Graphs.SimpleGraphs.barabasi_albert!Method
barabasi_albert!(g::AbstractGraph, n::Integer, k::Integer)

Create a Barabási–Albert model random graph with n vertices. It is grown by adding new vertices to an initial graph g. Each new vertex is attached with k edges to k different vertices already present in the system by preferential attachment.

Optional Arguments

  • rng=nothing: set the Random Number Generator.
  • seed=nothing: set the RNG seed.

Examples

julia> using Graphs
+{5, 7} undirected simple Int64 graph
source
Graphs.SimpleGraphs.StochasticBlockModelType
StochasticBlockModel{T,P}

A type capturing the parameters of the SBM. Each vertex is assigned to a block and the probability of edge (i,j) depends only on the block labels of vertex i and vertex j.

The assignment is stored in nodemap and the block affinities a k by k matrix is stored in affinities.

affinities[k,l] is the probability of an edge between any vertex in block k and any vertex in block l.

Implementation Notes

Graphs are generated by taking random $i,j ∈ V$ and flipping a coin with probability affinities[nodemap[i],nodemap[j]].

source
Graphs.SimpleGraphs.barabasi_albert!Method
barabasi_albert!(g::AbstractGraph, n::Integer, k::Integer)

Create a Barabási–Albert model random graph with n vertices. It is grown by adding new vertices to an initial graph g. Each new vertex is attached with k edges to k different vertices already present in the system by preferential attachment.

Optional Arguments

  • rng=nothing: set the Random Number Generator.
  • seed=nothing: set the RNG seed.

Examples

julia> using Graphs
 
 julia> g = cycle_graph(4)
 {4, 4} undirected simple Int64 graph
@@ -32,37 +32,37 @@
 julia> barabasi_albert!(g, 16, 3);
 
 julia> g
-{16, 40} undirected simple Int64 graph
source
Graphs.SimpleGraphs.barabasi_albertMethod
barabasi_albert(n::Integer, n0::Integer, k::Integer)

Create a Barabási–Albert model random graph with n vertices. It is grown by adding new vertices to an initial graph with n0 vertices. Each new vertex is attached with k edges to k different vertices already present in the system by preferential attachment. Initial graphs are undirected and consist of isolated vertices by default.

Optional Arguments

  • is_directed=false: if true, return a directed graph.
  • complete=false: if true, use a complete graph for the initial graph.
  • rng=nothing: set the Random Number Generator.
  • seed=nothing: set the RNG seed.

Examples

julia> using Graphs
+{16, 40} undirected simple Int64 graph
source
Graphs.SimpleGraphs.barabasi_albertMethod
barabasi_albert(n::Integer, n0::Integer, k::Integer)

Create a Barabási–Albert model random graph with n vertices. It is grown by adding new vertices to an initial graph with n0 vertices. Each new vertex is attached with k edges to k different vertices already present in the system by preferential attachment. Initial graphs are undirected and consist of isolated vertices by default.

Optional Arguments

  • is_directed=false: if true, return a directed graph.
  • complete=false: if true, use a complete graph for the initial graph.
  • rng=nothing: set the Random Number Generator.
  • seed=nothing: set the RNG seed.

Examples

julia> using Graphs
 
 julia> barabasi_albert(10, 3, 2)
 {10, 14} undirected simple Int64 graph
 
 julia> barabasi_albert(100, Int8(10), 3, is_directed=true, seed=123)
-{100, 270} directed simple Int8 graph
source
Graphs.SimpleGraphs.barabasi_albertMethod
barabasi_albert(n, k)

Create a Barabási–Albert model random graph with n vertices. It is grown by adding new vertices to an initial graph with k vertices. Each new vertex is attached with k edges to k different vertices already present in the system by preferential attachment. Initial graphs are undirected and consist of isolated vertices by default.

Optional Arguments

  • is_directed=false: if true, return a directed graph.
  • complete=false: if true, use a complete graph for the initial graph.
  • rng=nothing: set the Random Number Generator.
  • seed=nothing: set the RNG seed.

Examples

julia> using Graphs
+{100, 270} directed simple Int8 graph
source
Graphs.SimpleGraphs.barabasi_albertMethod
barabasi_albert(n, k)

Create a Barabási–Albert model random graph with n vertices. It is grown by adding new vertices to an initial graph with k vertices. Each new vertex is attached with k edges to k different vertices already present in the system by preferential attachment. Initial graphs are undirected and consist of isolated vertices by default.

Optional Arguments

  • is_directed=false: if true, return a directed graph.
  • complete=false: if true, use a complete graph for the initial graph.
  • rng=nothing: set the Random Number Generator.
  • seed=nothing: set the RNG seed.

Examples

julia> using Graphs
 
 julia> barabasi_albert(50, 3)
 {50, 141} undirected simple Int64 graph
 
 julia> barabasi_albert(100, Int8(10), is_directed=true, complete=true, seed=123)
-{100, 990} directed simple Int8 graph
source
Graphs.SimpleGraphs.dorogovtsev_mendesMethod
dorogovtsev_mendes(n)

Generate a random n vertex graph by the Dorogovtsev-Mendes method (with n \ge 3).

The Dorogovtsev-Mendes process begins with a triangle graph and inserts n-3 additional vertices. Each time a vertex is added, a random edge is selected and the new vertex is connected to the two endpoints of the chosen edge. This creates graphs with many triangles and a high local clustering coefficient.

It is often useful to track the evolution of the graph as vertices are added, you can access the graph from the tth stage of this algorithm by accessing the first t vertices with g[1:t].

References

  • http://graphstream-project.org/doc/Generators/Dorogovtsev-Mendes-generator/
  • https://arxiv.org/pdf/cond-mat/0106144.pdf#page=24

Examples

julia> using Graphs
+{100, 990} directed simple Int8 graph
source
Graphs.SimpleGraphs.dorogovtsev_mendesMethod
dorogovtsev_mendes(n)

Generate a random n vertex graph by the Dorogovtsev-Mendes method (with n \ge 3).

The Dorogovtsev-Mendes process begins with a triangle graph and inserts n-3 additional vertices. Each time a vertex is added, a random edge is selected and the new vertex is connected to the two endpoints of the chosen edge. This creates graphs with many triangles and a high local clustering coefficient.

It is often useful to track the evolution of the graph as vertices are added, you can access the graph from the tth stage of this algorithm by accessing the first t vertices with g[1:t].

References

  • http://graphstream-project.org/doc/Generators/Dorogovtsev-Mendes-generator/
  • https://arxiv.org/pdf/cond-mat/0106144.pdf#page=24

Examples

julia> using Graphs
 
 julia> dorogovtsev_mendes(10)
 {10, 17} undirected simple Int64 graph
 
 julia> dorogovtsev_mendes(11, seed=123)
-{11, 19} undirected simple Int64 graph
source
Graphs.SimpleGraphs.erdos_renyiMethod
erdos_renyi(n, ne::Integer)

Create an Erdős–Rényi random graph with n vertices and ne edges.

Optional Arguments

  • is_directed=false: if true, return a directed graph.
  • rng=nothing: set the Random Number Generator.
  • seed=nothing: set the RNG seed.

Examples

julia> using Graphs
+{11, 19} undirected simple Int64 graph
source
Graphs.SimpleGraphs.erdos_renyiMethod
erdos_renyi(n, ne::Integer)

Create an Erdős–Rényi random graph with n vertices and ne edges.

Optional Arguments

  • is_directed=false: if true, return a directed graph.
  • rng=nothing: set the Random Number Generator.
  • seed=nothing: set the RNG seed.

Examples

julia> using Graphs
 
 julia> erdos_renyi(10, 30)
 {10, 30} undirected simple Int64 graph
 
 julia> erdos_renyi(10, 30, is_directed=true, seed=123)
-{10, 30} directed simple Int64 graph
source
Graphs.SimpleGraphs.erdos_renyiMethod
erdos_renyi(n, p::Real)

Create an Erdős–Rényi random graph with n vertices. Edges are added between pairs of vertices with probability p.

Note that there exists another definition of the Erdös-Rényi model in which the total number of edges is kept constant, rather than the probability p. To access this definition, use erdos_renyi(n, ne::Integer) (specifically: erdos_renyi(n, 1) != erdos_renyi(n, 1.0)).

Optional Arguments

  • is_directed=false: if true, return a directed graph.
  • rng=nothing: set the Random Number Generator.
  • seed=nothing: set the RNG seed.

Examples

julia> using Graphs
+{10, 30} directed simple Int64 graph
source
Graphs.SimpleGraphs.erdos_renyiMethod
erdos_renyi(n, p::Real)

Create an Erdős–Rényi random graph with n vertices. Edges are added between pairs of vertices with probability p.

Note that there exists another definition of the Erdös-Rényi model in which the total number of edges is kept constant, rather than the probability p. To access this definition, use erdos_renyi(n, ne::Integer) (specifically: erdos_renyi(n, 1) != erdos_renyi(n, 1.0)).

Optional Arguments

  • is_directed=false: if true, return a directed graph.
  • rng=nothing: set the Random Number Generator.
  • seed=nothing: set the RNG seed.

Examples

julia> using Graphs
 
 julia> erdos_renyi(10, 0.5)
 {10, 20} undirected simple Int64 graph
julia> using Graphs
 
 julia> erdos_renyi(10, 0.5, is_directed=true, seed=123)
-{10, 49} directed simple Int64 graph
source
Graphs.SimpleGraphs.expected_degree_graphMethod
expected_degree_graph(ω)

Given a vector of expected degrees ω indexed by vertex, create a random undirected graph in which vertices i and j are connected with probability ω[i]*ω[j]/sum(ω).

Optional Arguments

  • rng=nothing: set the Random Number Generator.
  • seed=nothing: set the RNG seed.

Implementation Notes

The algorithm should work well for maximum(ω) << sum(ω). As maximum(ω) approaches sum(ω), some deviations from the expected values are likely.

References

Examples

# 1)
+{10, 49} directed simple Int64 graph
source
Graphs.SimpleGraphs.expected_degree_graphMethod
expected_degree_graph(ω)

Given a vector of expected degrees ω indexed by vertex, create a random undirected graph in which vertices i and j are connected with probability ω[i]*ω[j]/sum(ω).

Optional Arguments

  • rng=nothing: set the Random Number Generator.
  • seed=nothing: set the RNG seed.

Implementation Notes

The algorithm should work well for maximum(ω) << sum(ω). As maximum(ω) approaches sum(ω), some deviations from the expected values are likely.

References

Examples

# 1)
 julia> using Graphs
 
 julia> g = expected_degree_graph([3, 1//2, 1//2, 1//2, 1//2])
@@ -76,23 +76,23 @@
 {3, 1} undirected simple Int64 graph
 
 julia> print(degree(g))
-[1, 0, 1]
source
Graphs.SimpleGraphs.kroneckerFunction
kronecker(SCALE, edgefactor, A=0.57, B=0.19, C=0.19; rng=nothing, seed=nothing)

Generate a directed Kronecker graph with the default Graph500 parameters.

References

  • http://www.graph500.org/specifications#alg:generator
source
Graphs.SimpleGraphs.make_edgestreamMethod
make_edgestream(sbm; rng=nothing, seed=nothing)

Take an infinite sample from the Stochastic Block Model sbm. Pass to Graph(nvg, neg, edgestream) to get a Graph object based on sbm.

source
Graphs.SimpleGraphs.nearbipartiteaffinityMethod
nearbipartiteaffinity(sizes, between, intra)

Construct the affinity matrix for a near bipartite SBM. between is the affinity between the two parts of each bipartite community. intra is the probability of an edge within the parts of the partitions.

This is a specific type of SBM with `\frac{k}{2} blocks each with two halves. Each half is connected as a random bipartite graph with probabilityintraThe blocks are connected with probabilitybetween`.

source
Graphs.SimpleGraphs.newman_watts_strogatzMethod
newman_watts_strogatz(n, k, β)

Return a Newman-Watts-Strogatz small world random graph with n vertices, each with expected degree k(1 + β) (or (k - 1)(1 + β) if k is odd). Edges are randomized per the model based on probability β.

The algorithm proceeds as follows. First, a perfect 1-lattice is constructed, where each vertex has exacly div(k, 2) neighbors on each side (i.e., k or k - 1 in total). Then the following steps are repeated for a hop length i of 1 through div(k, 2).

  1. Consider each vertex s in turn, along with the edge to its ith nearest neighbor t, in a clockwise sense.

  2. Generate a uniformly random number r. If r < β, s is connected to some vertex d, chosen uniformly at random from the entire graph, excluding s and its neighbors. (Note that t is a valid candidate.)

For β = 0, the graph will remain a 1-lattice, and for β = 1, all edges will be rewired randomly.

Note: In the original paper by Newman and Watts, self-loops and double edges were allowed, which is not the case here. However, for large enough networks and small enough p and k, this should not deviate much from the original model.

Optional Arguments

  • is_directed=false: if true, return a directed graph.
  • rng=nothing: set the Random Number Generator.
  • seed=nothing: set the RNG seed.

Examples

julia> using Graphs
+[1, 0, 1]
source
Graphs.SimpleGraphs.kroneckerFunction
kronecker(SCALE, edgefactor, A=0.57, B=0.19, C=0.19; rng=nothing, seed=nothing)

Generate a directed Kronecker graph with the default Graph500 parameters.

References

  • http://www.graph500.org/specifications#alg:generator
source
Graphs.SimpleGraphs.make_edgestreamMethod
make_edgestream(sbm; rng=nothing, seed=nothing)

Take an infinite sample from the Stochastic Block Model sbm. Pass to Graph(nvg, neg, edgestream) to get a Graph object based on sbm.

source
Graphs.SimpleGraphs.nearbipartiteaffinityMethod
nearbipartiteaffinity(sizes, between, intra)

Construct the affinity matrix for a near bipartite SBM. between is the affinity between the two parts of each bipartite community. intra is the probability of an edge within the parts of the partitions.

This is a specific type of SBM with `\frac{k}{2} blocks each with two halves. Each half is connected as a random bipartite graph with probabilityintraThe blocks are connected with probabilitybetween`.

source
Graphs.SimpleGraphs.newman_watts_strogatzMethod
newman_watts_strogatz(n, k, β)

Return a Newman-Watts-Strogatz small world random graph with n vertices, each with expected degree k(1 + β) (or (k - 1)(1 + β) if k is odd). Edges are randomized per the model based on probability β.

The algorithm proceeds as follows. First, a perfect 1-lattice is constructed, where each vertex has exacly div(k, 2) neighbors on each side (i.e., k or k - 1 in total). Then the following steps are repeated for a hop length i of 1 through div(k, 2).

  1. Consider each vertex s in turn, along with the edge to its ith nearest neighbor t, in a clockwise sense.

  2. Generate a uniformly random number r. If r < β, s is connected to some vertex d, chosen uniformly at random from the entire graph, excluding s and its neighbors. (Note that t is a valid candidate.)

For β = 0, the graph will remain a 1-lattice, and for β = 1, all edges will be rewired randomly.

Note: In the original paper by Newman and Watts, self-loops and double edges were allowed, which is not the case here. However, for large enough networks and small enough p and k, this should not deviate much from the original model.

Optional Arguments

  • is_directed=false: if true, return a directed graph.
  • rng=nothing: set the Random Number Generator.
  • seed=nothing: set the RNG seed.

Examples

julia> using Graphs
 
 julia> newman_watts_strogatz(10, 4, 0.3)
 {10, 26} undirected simple Int64 graph
-````

jldoctest

julia> newmanwattsstrogatz(Int8(10), 4, 0.8, is_directed=true, seed=123) {10, 36} directed simple Int8 graph ```

References

source
Graphs.SimpleGraphs.randbnMethod
randbn(n, p; rng=nothing, seed=nothing)

Return a binomially-distributed random number with parameters n and p and optional seed.

References

  • "Non-Uniform Random Variate Generation," Luc Devroye, p. 522. Retrieved via http://www.eirene.de/Devroye.pdf.
  • http://stackoverflow.com/questions/23561551/a-efficient-binomial-random-number-generator-code-in-java
source
Graphs.SimpleGraphs.random_configuration_modelMethod
random_configuration_model(n, k)

Create a random undirected graph according to the configuration model containing n vertices, with each node i having degree k[i].

Optional Arguments

  • rng=nothing: set the Random Number Generator.
  • seed=nothing: set the RNG seed.
  • check_graphical=false: if true, ensure that k is a graphical sequence

(see isgraphical).

Performance

Time complexity is approximately $\mathcal{O}(n \bar{k}^2)$.

Implementation Notes

Allocates an array of $n \bar{k}$ Ints.

source
Graphs.SimpleGraphs.random_orientation_dagMethod
random_orientation_dag(g)

Generate a random oriented acyclical digraph. The function takes in a simple graph and a random number generator as an argument. The probability of each directional acyclic graph randomly being generated depends on the architecture of the original directed graph.

DAG's have a finite topological order; this order is randomly generated via "order = randperm()".

Examples

julia> using Graphs
+````

jldoctest

julia> newmanwattsstrogatz(Int8(10), 4, 0.8, is_directed=true, seed=123) {10, 36} directed simple Int8 graph ```

References

source
Graphs.SimpleGraphs.randbnMethod
randbn(n, p; rng=nothing, seed=nothing)

Return a binomially-distributed random number with parameters n and p and optional seed.

References

  • "Non-Uniform Random Variate Generation," Luc Devroye, p. 522. Retrieved via http://www.eirene.de/Devroye.pdf.
  • http://stackoverflow.com/questions/23561551/a-efficient-binomial-random-number-generator-code-in-java
source
Graphs.SimpleGraphs.random_configuration_modelMethod
random_configuration_model(n, k)

Create a random undirected graph according to the configuration model containing n vertices, with each node i having degree k[i].

Optional Arguments

  • rng=nothing: set the Random Number Generator.
  • seed=nothing: set the RNG seed.
  • check_graphical=false: if true, ensure that k is a graphical sequence

(see isgraphical).

Performance

Time complexity is approximately $\mathcal{O}(n \bar{k}^2)$.

Implementation Notes

Allocates an array of $n \bar{k}$ Ints.

source
Graphs.SimpleGraphs.random_orientation_dagMethod
random_orientation_dag(g)

Generate a random oriented acyclical digraph. The function takes in a simple graph and a random number generator as an argument. The probability of each directional acyclic graph randomly being generated depends on the architecture of the original directed graph.

DAG's have a finite topological order; this order is randomly generated via "order = randperm()".

Examples

julia> using Graphs
 
 julia> random_orientation_dag(complete_graph(10))
 {10, 45} directed simple Int64 graph
 
 julia> random_orientation_dag(star_graph(Int8(10)), seed=123)
-{10, 9} directed simple Int8 graph
source
Graphs.SimpleGraphs.random_regular_digraphMethod
random_regular_digraph(n, k)

Create a random directed regular graph with n vertices, each with degree k.

Optional Arguments

  • dir=:out: the direction of the edges for the degree parameter.
  • rng=nothing: set the Random Number Generator.
  • seed=nothing: set the RNG seed.

Implementation Notes

Allocates an $n × n$ sparse matrix of boolean as an adjacency matrix and uses that to generate the directed graph.

source
Graphs.SimpleGraphs.random_regular_graphMethod
random_regular_graph(n, k)

Create a random undirected regular graph with n vertices, each with degree k.

Optional Arguments

  • rng=nothing: set the Random Number Generator.
  • seed=nothing: set the RNG seed.

Performance

Time complexity is approximately $\mathcal{O}(nk^2)$.

Implementation Notes

Allocates an array of nk Ints, and . For $k > \frac{n}{2}$, generates a graph of degree $n-k-1$ and returns its complement.

source
Graphs.SimpleGraphs.random_regular_digraphMethod
random_regular_digraph(n, k)

Create a random directed regular graph with n vertices, each with degree k.

Optional Arguments

  • dir=:out: the direction of the edges for the degree parameter.
  • rng=nothing: set the Random Number Generator.
  • seed=nothing: set the RNG seed.

Implementation Notes

Allocates an $n × n$ sparse matrix of boolean as an adjacency matrix and uses that to generate the directed graph.

source
Graphs.SimpleGraphs.random_regular_graphMethod
random_regular_graph(n, k)

Create a random undirected regular graph with n vertices, each with degree k.

Optional Arguments

  • rng=nothing: set the Random Number Generator.
  • seed=nothing: set the RNG seed.

Performance

Time complexity is approximately $\mathcal{O}(nk^2)$.

Implementation Notes

Allocates an array of nk Ints, and . For $k > \frac{n}{2}$, generates a graph of degree $n-k-1$ and returns its complement.

source
Graphs.SimpleGraphs.random_tournament_digraphMethod
random_tournament_digraph(n)

Create a random directed tournament graph with n vertices.

Optional Arguments

  • rng=nothing: set the Random Number Generator.
  • seed=nothing: set the RNG seed.

Examples

julia> using Graphs
 
 julia> random_tournament_digraph(5)
 {5, 10} directed simple Int64 graph
 
 julia> random_tournament_digraph(Int8(10), seed=123)
-{10, 45} directed simple Int8 graph
source
Graphs.SimpleGraphs.sbmaffinityMethod
sbmaffinity(internalp, externalp, sizes)

Produce the sbm affinity matrix with internal probabilities internalp and external probabilities externalp.

source
Graphs.SimpleGraphs.static_fitness_modelMethod
static_fitness_model(m, fitness)

Generate a random graph with $|fitness|$ vertices and m edges, in which the probability of the existence of $Edge_{ij}$ is proportional to $fitness_i × fitness_j$.

Optional Arguments

  • rng=nothing: set the Random Number Generator.
  • seed=nothing: set the RNG seed.

Performance

Time complexity is $\mathcal{O}(|V| + |E| log |E|)$.

References

  • Goh K-I, Kahng B, Kim D: Universal behaviour of load distribution in scale-free networks. Phys Rev Lett 87(27):278701, 2001.

Examples

julia> g = static_fitness_model(5, [1, 1, 0.5, 0.1])
+{10, 45} directed simple Int8 graph
source
Graphs.SimpleGraphs.sbmaffinityMethod
sbmaffinity(internalp, externalp, sizes)

Produce the sbm affinity matrix with internal probabilities internalp and external probabilities externalp.

source
Graphs.SimpleGraphs.static_fitness_modelMethod
static_fitness_model(m, fitness)

Generate a random graph with $|fitness|$ vertices and m edges, in which the probability of the existence of $Edge_{ij}$ is proportional to $fitness_i × fitness_j$.

Optional Arguments

  • rng=nothing: set the Random Number Generator.
  • seed=nothing: set the RNG seed.

Performance

Time complexity is $\mathcal{O}(|V| + |E| log |E|)$.

References

  • Goh K-I, Kahng B, Kim D: Universal behaviour of load distribution in scale-free networks. Phys Rev Lett 87(27):278701, 2001.

Examples

julia> g = static_fitness_model(5, [1, 1, 0.5, 0.1])
 {4, 5} undirected simple Int64 graph
 
 julia> edges(g) |> collect
@@ -112,7 +112,7 @@
  Edge 1 => 3
  Edge 2 => 3
  Edge 2 => 4
- Edge 3 => 4
source
Graphs.SimpleGraphs.static_fitness_modelMethod
static_fitness_model(m, fitness_out, fitness_in)

Generate a random directed graph with $|fitness\_out + fitness\_in|$ vertices and m edges, in which the probability of the existence of $Edge_{ij}$ is proportional with respect to $i ∝ fitness\_out$ and $j ∝ fitness\_in$.

Optional Arguments

  • rng=nothing: set the Random Number Generator.
  • seed=nothing: set the RNG seed.

Performance

Time complexity is $\mathcal{O}(|V| + |E| log |E|)$.

References

  • Goh K-I, Kahng B, Kim D: Universal behaviour of load distribution in scale-free networks. Phys Rev Lett 87(27):278701, 2001.

Examples

julia> using Graphs
+ Edge 3 => 4
source
Graphs.SimpleGraphs.static_fitness_modelMethod
static_fitness_model(m, fitness_out, fitness_in)

Generate a random directed graph with $|fitness\_out + fitness\_in|$ vertices and m edges, in which the probability of the existence of $Edge_{ij}$ is proportional with respect to $i ∝ fitness\_out$ and $j ∝ fitness\_in$.

Optional Arguments

  • rng=nothing: set the Random Number Generator.
  • seed=nothing: set the RNG seed.

Performance

Time complexity is $\mathcal{O}(|V| + |E| log |E|)$.

References

  • Goh K-I, Kahng B, Kim D: Universal behaviour of load distribution in scale-free networks. Phys Rev Lett 87(27):278701, 2001.

Examples

julia> using Graphs
 
 julia> g = static_fitness_model(6, [1, 0.2, 0.2, 0.2], [0.1, 0.1, 0.1, 0.9]; seed=123)
 {4, 6} directed simple Int64 graph
@@ -124,83 +124,83 @@
  Edge 1 => 4
  Edge 2 => 3
  Edge 2 => 4
- Edge 3 => 4
source
Graphs.SimpleGraphs.static_scale_freeMethod
static_scale_free(n, m, α_out, α_in)

Generate a random graph with n vertices, m edges and expected power-law degree distribution with exponent α_out for outbound edges and α_in for inbound edges.

Optional Arguments

  • rng=nothing: set the Random Number Generator.
  • seed=nothing: set the RNG seed.
  • finite_size_correction=true: determines whether to use the finite size correction

proposed by Cho et al.

Performance

Time complexity is $\mathcal{O}(|V| + |E| log |E|)$.

References

  • Goh K-I, Kahng B, Kim D: Universal behaviour of load distribution in scale-free networks. Phys Rev Lett 87(27):278701, 2001.
  • Chung F and Lu L: Connected components in a random graph with given degree sequences. Annals of Combinatorics 6, 125-145, 2002.
  • Cho YS, Kim JS, Park J, Kahng B, Kim D: Percolation transitions in scale-free networks under the Achlioptas process. Phys Rev Lett 103:135702, 2009.
source
Graphs.SimpleGraphs.static_scale_freeMethod
static_scale_free(n, m, α)

Generate a random graph with n vertices, m edges and expected power-law degree distribution with exponent α.

Optional Arguments

  • rng=nothing: set the Random Number Generator.
  • seed=nothing: set the RNG seed.
  • finite_size_correction=true: determines whether to use the finite size correction

proposed by Cho et al.

Performance

Time complexity is $\mathcal{O}(|V| + |E| log |E|)$.

References

  • Goh K-I, Kahng B, Kim D: Universal behaviour of load distribution in scale-free networks. Phys Rev Lett 87(27):278701, 2001.
  • Chung F and Lu L: Connected components in a random graph with given degree sequences. Annals of Combinatorics 6, 125-145, 2002.
  • Cho YS, Kim JS, Park J, Kahng B, Kim D: Percolation transitions in scale-free networks under the Achlioptas process. Phys Rev Lett 103:135702, 2009.
source
Graphs.SimpleGraphs.stochastic_block_modelMethod
stochastic_block_model(c, n)

Return a Graph generated according to the Stochastic Block Model (SBM).

c[a,b] : Mean number of neighbors of a vertex in block a belonging to block b. Only the upper triangular part is considered, since the lower triangular is determined by $c[b,a] = c[a,b] * \frac{n[a]}{n[b]}$. n[a] : Number of vertices in block a

Optional Arguments

  • rng=nothing: set the Random Number Generator.
  • seed=nothing: set the RNG seed.

For a dynamic version of the SBM see the StochasticBlockModel type and related functions.

source
Graphs.SimpleGraphs.uniform_treeMethod
uniform_tree(n)

Generates a random labelled tree, drawn uniformly at random over the $n^{n-2}$ such trees. A uniform word of length n-2 over the alphabet 1:n is generated (Prüfer sequence) then decoded. See also the prufer_decode function and this page on Prüfer codes.

Optional Arguments

  • rng=nothing: set the Random Number Generator.

Examples

julia> using Graphs
+ Edge 3 => 4
source
Graphs.SimpleGraphs.static_scale_freeMethod
static_scale_free(n, m, α_out, α_in)

Generate a random graph with n vertices, m edges and expected power-law degree distribution with exponent α_out for outbound edges and α_in for inbound edges.

Optional Arguments

  • rng=nothing: set the Random Number Generator.
  • seed=nothing: set the RNG seed.
  • finite_size_correction=true: determines whether to use the finite size correction

proposed by Cho et al.

Performance

Time complexity is $\mathcal{O}(|V| + |E| log |E|)$.

References

  • Goh K-I, Kahng B, Kim D: Universal behaviour of load distribution in scale-free networks. Phys Rev Lett 87(27):278701, 2001.
  • Chung F and Lu L: Connected components in a random graph with given degree sequences. Annals of Combinatorics 6, 125-145, 2002.
  • Cho YS, Kim JS, Park J, Kahng B, Kim D: Percolation transitions in scale-free networks under the Achlioptas process. Phys Rev Lett 103:135702, 2009.
source
Graphs.SimpleGraphs.static_scale_freeMethod
static_scale_free(n, m, α)

Generate a random graph with n vertices, m edges and expected power-law degree distribution with exponent α.

Optional Arguments

  • rng=nothing: set the Random Number Generator.
  • seed=nothing: set the RNG seed.
  • finite_size_correction=true: determines whether to use the finite size correction

proposed by Cho et al.

Performance

Time complexity is $\mathcal{O}(|V| + |E| log |E|)$.

References

  • Goh K-I, Kahng B, Kim D: Universal behaviour of load distribution in scale-free networks. Phys Rev Lett 87(27):278701, 2001.
  • Chung F and Lu L: Connected components in a random graph with given degree sequences. Annals of Combinatorics 6, 125-145, 2002.
  • Cho YS, Kim JS, Park J, Kahng B, Kim D: Percolation transitions in scale-free networks under the Achlioptas process. Phys Rev Lett 103:135702, 2009.
source
Graphs.SimpleGraphs.stochastic_block_modelMethod
stochastic_block_model(c, n)

Return a Graph generated according to the Stochastic Block Model (SBM).

c[a,b] : Mean number of neighbors of a vertex in block a belonging to block b. Only the upper triangular part is considered, since the lower triangular is determined by $c[b,a] = c[a,b] * \frac{n[a]}{n[b]}$. n[a] : Number of vertices in block a

Optional Arguments

  • rng=nothing: set the Random Number Generator.
  • seed=nothing: set the RNG seed.

For a dynamic version of the SBM see the StochasticBlockModel type and related functions.

source
Graphs.SimpleGraphs.uniform_treeMethod
uniform_tree(n)

Generates a random labelled tree, drawn uniformly at random over the $n^{n-2}$ such trees. A uniform word of length n-2 over the alphabet 1:n is generated (Prüfer sequence) then decoded. See also the prufer_decode function and this page on Prüfer codes.

Optional Arguments

  • rng=nothing: set the Random Number Generator.

Examples

julia> using Graphs
 
 julia> uniform_tree(10)
-{10, 9} undirected simple Int64 graph
source
Graphs.SimpleGraphs.watts_strogatzMethod
watts_strogatz(n, k, β)

Return a Watts-Strogatz small world random graph with n vertices, each with expected degree k (or k - 1 if k is odd). Edges are randomized per the model based on probability β.

The algorithm proceeds as follows. First, a perfect 1-lattice is constructed, where each vertex has exacly div(k, 2) neighbors on each side (i.e., k or k - 1 in total). Then the following steps are repeated for a hop length i of 1 through div(k, 2).

  1. Consider each vertex s in turn, along with the edge to its ith nearest neighbor t, in a clockwise sense.

  2. Generate a uniformly random number r. If r ≥ β, then the edge (s, t) is left unaltered. Otherwise, the edge is deleted and rewired so that s is connected to some vertex d, chosen uniformly at random from the entire graph, excluding s and its neighbors. (Note that t is a valid candidate.)

For β = 0, the graph will remain a 1-lattice, and for β = 1, all edges will be rewired randomly.

Optional Arguments

  • remove_edges=true: if false, do not remove the original edges.
  • is_directed=false: if true, return a directed graph.
  • rng=nothing: set the Random Number Generator.
  • seed=nothing: set the RNG seed.

Examples

julia> using Graphs
+{10, 9} undirected simple Int64 graph
source
Graphs.SimpleGraphs.watts_strogatzMethod
watts_strogatz(n, k, β)

Return a Watts-Strogatz small world random graph with n vertices, each with expected degree k (or k - 1 if k is odd). Edges are randomized per the model based on probability β.

The algorithm proceeds as follows. First, a perfect 1-lattice is constructed, where each vertex has exacly div(k, 2) neighbors on each side (i.e., k or k - 1 in total). Then the following steps are repeated for a hop length i of 1 through div(k, 2).

  1. Consider each vertex s in turn, along with the edge to its ith nearest neighbor t, in a clockwise sense.

  2. Generate a uniformly random number r. If r ≥ β, then the edge (s, t) is left unaltered. Otherwise, the edge is deleted and rewired so that s is connected to some vertex d, chosen uniformly at random from the entire graph, excluding s and its neighbors. (Note that t is a valid candidate.)

For β = 0, the graph will remain a 1-lattice, and for β = 1, all edges will be rewired randomly.

Optional Arguments

  • remove_edges=true: if false, do not remove the original edges.
  • is_directed=false: if true, return a directed graph.
  • rng=nothing: set the Random Number Generator.
  • seed=nothing: set the RNG seed.

Examples

julia> using Graphs
 
 julia> watts_strogatz(10, 4, 0.3)
 {10, 20} undirected simple Int64 graph
 
 julia> watts_strogatz(Int8(10), 4, 0.8, is_directed=true, seed=123)
-{10, 20} directed simple Int8 graph

References

source
Graphs.SimpleGraphs.smallgraphMethod
smallgraph(s)
-smallgraph(s)

Create a small graph of type s. Admissible values for s are:

sgraph type
:bullA bull graph.
:chvatalA Chvátal graph.
:cubicalA Platonic cubical graph.
:desarguesA Desarguesgraph.
:diamondA diamond graph.
:dodecahedralA Platonic dodecahedral graph.
:fruchtA Frucht graph.
:heawoodA Heawood graph.
:houseA graph mimicing the classic outline of a house.
:housexA house graph, with two edges crossing the bottom square.
:icosahedralA Platonic icosahedral graph.
:karateA social network graph called Zachary's karate club.
:krackhardtkiteA Krackhardt-Kite social network graph.
:moebiuskantorA Möbius-Kantor graph.
:octahedralA Platonic octahedral graph.
:pappusA Pappus graph.
:petersenA Petersen graph.
:sedgewickmazeA simple maze graph used in Sedgewick's Algorithms in C++: Graph Algorithms (3rd ed.)
:tetrahedralA Platonic tetrahedral graph.
:truncatedcubeA skeleton of the truncated cube graph.
:truncatedtetrahedronA skeleton of the truncated tetrahedron graph.
:truncatedtetrahedron_dirA skeleton of the truncated tetrahedron digraph.
:tutteA Tutte graph.
source
Graphs.SimpleGraphs.barbell_graphMethod
barbell_graph(n1, n2)

Create a barbell graph consisting of a clique of size n1 connected by an edge to a clique of size n2.

Implementation Notes

Preserves the eltype of n1 and n2. Will error if the required number of vertices exceeds the eltype. n1 and n2 must be at least 1 so that both cliques are non-empty. The cliques are organized with nodes 1:n1 being the left clique and n1+1:n1+n2 being the right clique. The cliques are connected by and edge (n1, n1+1).

Examples

julia> using Graphs
+{10, 20} directed simple Int8 graph

References

source
Graphs.SimpleGraphs.smallgraphMethod
smallgraph(s)
+smallgraph(s)

Create a small graph of type s. Admissible values for s are:

sgraph type
:bullA bull graph.
:chvatalA Chvátal graph.
:cubicalA Platonic cubical graph.
:desarguesA Desarguesgraph.
:diamondA diamond graph.
:dodecahedralA Platonic dodecahedral graph.
:fruchtA Frucht graph.
:heawoodA Heawood graph.
:houseA graph mimicing the classic outline of a house.
:housexA house graph, with two edges crossing the bottom square.
:icosahedralA Platonic icosahedral graph.
:karateA social network graph called Zachary's karate club.
:krackhardtkiteA Krackhardt-Kite social network graph.
:moebiuskantorA Möbius-Kantor graph.
:octahedralA Platonic octahedral graph.
:pappusA Pappus graph.
:petersenA Petersen graph.
:sedgewickmazeA simple maze graph used in Sedgewick's Algorithms in C++: Graph Algorithms (3rd ed.)
:tetrahedralA Platonic tetrahedral graph.
:truncatedcubeA skeleton of the truncated cube graph.
:truncatedtetrahedronA skeleton of the truncated tetrahedron graph.
:truncatedtetrahedron_dirA skeleton of the truncated tetrahedron digraph.
:tutteA Tutte graph.
source
Graphs.SimpleGraphs.barbell_graphMethod
barbell_graph(n1, n2)

Create a barbell graph consisting of a clique of size n1 connected by an edge to a clique of size n2.

Implementation Notes

Preserves the eltype of n1 and n2. Will error if the required number of vertices exceeds the eltype. n1 and n2 must be at least 1 so that both cliques are non-empty. The cliques are organized with nodes 1:n1 being the left clique and n1+1:n1+n2 being the right clique. The cliques are connected by and edge (n1, n1+1).

Examples

julia> using Graphs
 
 julia> barbell_graph(3, 4)
 {7, 10} undirected simple Int64 graph
 
 julia> barbell_graph(Int8(5), Int8(5))
-{10, 21} undirected simple Int8 graph
source
Graphs.SimpleGraphs.binary_treeMethod
binary_tree(k::Integer)

Create a binary tree of depth k.

Examples

julia> using Graphs
 
 julia> binary_tree(4)
 {15, 14} undirected simple Int64 graph
 
 julia> binary_tree(Int8(5))
-{31, 30} undirected simple Int8 graph
source
Graphs.SimpleGraphs.circular_ladder_graphMethod
circular_ladder_graph(n)

Create a circular ladder graph consisting of 2n nodes and 3n edges. This is also known as the prism graph.

Implementation Notes

Preserves the eltype of the partitions vector. Will error if the required number of vertices exceeds the eltype. n must be at least 3 to avoid self-loops and multi-edges.

Examples

julia> using Graphs
+{31, 30} undirected simple Int8 graph
source
Graphs.SimpleGraphs.circular_ladder_graphMethod
circular_ladder_graph(n)

Create a circular ladder graph consisting of 2n nodes and 3n edges. This is also known as the prism graph.

Implementation Notes

Preserves the eltype of the partitions vector. Will error if the required number of vertices exceeds the eltype. n must be at least 3 to avoid self-loops and multi-edges.

Examples

julia> using Graphs
 
 julia> circular_ladder_graph(3)
 {6, 9} undirected simple Int64 graph
 
 julia> circular_ladder_graph(Int8(4))
-{8, 12} undirected simple Int8 graph
source
Graphs.SimpleGraphs.clique_graphMethod
clique_graph(k, n)

Create a graph consisting of n connected k-cliques.

Examples

julia> using Graphs
 
 julia> clique_graph(4, 10)
 {40, 70} undirected simple Int64 graph
 
 julia> clique_graph(Int8(10), Int8(4))
-{40, 184} undirected simple Int8 graph
source
Graphs.SimpleGraphs.complete_digraphMethod
complete_digraph(n)

Create a directed complete graph with n vertices.

Examples

julia> using Graphs
 
 julia> complete_digraph(5)
 {5, 20} directed simple Int64 graph
 
 julia> complete_digraph(Int8(6))
-{6, 30} directed simple Int8 graph
source
Graphs.SimpleGraphs.complete_graphMethod
complete_graph(n)

Create an undirected complete graph with n vertices.

Examples

julia> using Graphs
 
 julia> complete_graph(5)
 {5, 10} undirected simple Int64 graph
 
 julia> complete_graph(Int8(6))
-{6, 15} undirected simple Int8 graph
source
Graphs.SimpleGraphs.complete_multipartite_graphMethod
complete_multipartite_graph(partitions)

Create an undirected complete bipartite graph with sum(partitions) vertices. A partition with 0 vertices is skipped.

Implementation Notes

Preserves the eltype of the partitions vector. Will error if the required number of vertices exceeds the eltype.

Examples

julia> using Graphs
+{6, 15} undirected simple Int8 graph
source
Graphs.SimpleGraphs.complete_multipartite_graphMethod
complete_multipartite_graph(partitions)

Create an undirected complete bipartite graph with sum(partitions) vertices. A partition with 0 vertices is skipped.

Implementation Notes

Preserves the eltype of the partitions vector. Will error if the required number of vertices exceeds the eltype.

Examples

julia> using Graphs
 
 julia> complete_multipartite_graph([1,2,3])
 {6, 11} undirected simple Int64 graph
 
 julia> complete_multipartite_graph(Int8[5,5,5])
-{15, 75} undirected simple Int8 graph
source
Graphs.SimpleGraphs.cycle_digraphMethod
cycle_digraph(n)

Create a directed cycle graph with n vertices.

Examples

julia> using Graphs
 
 julia> cycle_digraph(3)
 {3, 3} directed simple Int64 graph
 
 julia> cycle_digraph(Int8(5))
-{5, 5} directed simple Int8 graph
source
Graphs.SimpleGraphs.cycle_graphMethod
cycle_graph(n)

Create an undirected cycle graph with n vertices.

Examples

julia> using Graphs
 
 julia> cycle_graph(3)
 {3, 3} undirected simple Int64 graph
 
 julia> cycle_graph(Int8(5))
-{5, 5} undirected simple Int8 graph
source
Graphs.SimpleGraphs.double_binary_treeMethod
double_binary_tree(k::Integer)

Create a double complete binary tree with k levels.

References

  • Used as an example for spectral clustering by Guattery and Miller 1998.

Examples

julia> using Graphs
+{5, 5} undirected simple Int8 graph
source
Graphs.SimpleGraphs.double_binary_treeMethod
double_binary_tree(k::Integer)

Create a double complete binary tree with k levels.

References

  • Used as an example for spectral clustering by Guattery and Miller 1998.

Examples

julia> using Graphs
 
 julia> double_binary_tree(4)
 {30, 29} undirected simple Int64 graph
 
 julia> double_binary_tree(Int8(5))
-{62, 61} undirected simple Int8 graph
source
Graphs.SimpleGraphs.gridMethod
grid(dims; periodic=false)

Create a $|dims|$-dimensional cubic lattice, with length dims[i] in dimension i.

Optional Arguments

  • periodic=false: If true, the resulting lattice will have periodic boundary

condition in each dimension.

Examples

julia> using Graphs
+{62, 61} undirected simple Int8 graph
source
Graphs.SimpleGraphs.gridMethod
grid(dims; periodic=false)

Create a $|dims|$-dimensional cubic lattice, with length dims[i] in dimension i.

Optional Arguments

  • periodic=false: If true, the resulting lattice will have periodic boundary

condition in each dimension.

Examples

julia> using Graphs
 
 julia> grid([2,3])
 {6, 7} undirected simple Int64 graph
@@ -209,61 +209,61 @@
 {8, 12} undirected simple Int8 graph
 
 julia> grid((2,3))
-{6, 7} undirected simple Int64 graph
source
Graphs.SimpleGraphs.ladder_graphMethod
ladder_graph(n)

Create a ladder graph consisting of 2n nodes and 3n-2 edges.

Implementation Notes

Preserves the eltype of n. Will error if the required number of vertices exceeds the eltype.

Examples

julia> using Graphs
+{6, 7} undirected simple Int64 graph
source
Graphs.SimpleGraphs.ladder_graphMethod
ladder_graph(n)

Create a ladder graph consisting of 2n nodes and 3n-2 edges.

Implementation Notes

Preserves the eltype of n. Will error if the required number of vertices exceeds the eltype.

Examples

julia> using Graphs
 
 julia> ladder_graph(3)
 {6, 7} undirected simple Int64 graph
 
 julia> ladder_graph(Int8(4))
-{8, 10} undirected simple Int8 graph
source
Graphs.SimpleGraphs.lollipop_graphMethod
lollipop_graph(n1, n2)

Create a lollipop graph consisting of a clique of size n1 connected by an edge to a path of size n2.

Implementation Notes

Preserves the eltype of n1 and n2. Will error if the required number of vertices exceeds the eltype. n1 and n2 must be at least 1 so that both the clique and the path have at least one vertex. The graph is organized with nodes 1:n1 being the clique and n1+1:n1+n2 being the path. The clique is connected to the path by an edge (n1, n1+1).

Examples

julia> using Graphs
+{8, 10} undirected simple Int8 graph
source
Graphs.SimpleGraphs.lollipop_graphMethod
lollipop_graph(n1, n2)

Create a lollipop graph consisting of a clique of size n1 connected by an edge to a path of size n2.

Implementation Notes

Preserves the eltype of n1 and n2. Will error if the required number of vertices exceeds the eltype. n1 and n2 must be at least 1 so that both the clique and the path have at least one vertex. The graph is organized with nodes 1:n1 being the clique and n1+1:n1+n2 being the path. The clique is connected to the path by an edge (n1, n1+1).

Examples

julia> using Graphs
 
 julia> lollipop_graph(2, 5)
 {7, 6} undirected simple Int64 graph
 
 julia> lollipop_graph(Int8(3), Int8(4))
-{7, 7} undirected simple Int8 graph
source
Graphs.SimpleGraphs.path_digraphMethod
path_digraph(n)

Creates a directed path graph with n vertices.

Examples

julia> using Graphs
 
 julia> path_digraph(5)
 {5, 4} directed simple Int64 graph
 
 julia> path_digraph(Int8(10))
-{10, 9} directed simple Int8 graph
source
Graphs.SimpleGraphs.path_graphMethod
path_graph(n)

Create an undirected path graph with n vertices.

Examples

julia> using Graphs
 
 julia> path_graph(5)
 {5, 4} undirected simple Int64 graph
 
 julia> path_graph(Int8(10))
-{10, 9} undirected simple Int8 graph
source
Graphs.SimpleGraphs.roach_graphMethod
roach_graph(k)

Create a Roach graph of size k.

References

  • Guattery and Miller 1998

Examples

julia> using Graphs
+{10, 9} undirected simple Int8 graph
source
Graphs.SimpleGraphs.roach_graphMethod
roach_graph(k)

Create a Roach graph of size k.

References

  • Guattery and Miller 1998

Examples

julia> using Graphs
 
 julia> roach_graph(10)
-{40, 48} undirected simple Int64 graph
source
Graphs.SimpleGraphs.star_digraphMethod
star_digraph(n)

Create a directed star graph with n vertices.

Examples

julia> using Graphs
 
 julia> star_digraph(3)
 {3, 2} directed simple Int64 graph
 
 julia> star_digraph(Int8(10))
-{10, 9} directed simple Int8 graph
source
Graphs.SimpleGraphs.star_graphMethod
star_graph(n)

Create an undirected star graph with n vertices.

Examples

julia> using Graphs
 
 julia> star_graph(3)
 {3, 2} undirected simple Int64 graph
 
 julia> star_graph(Int8(10))
-{10, 9} undirected simple Int8 graph
source
Graphs.SimpleGraphs.turan_graphMethod
turan_graph(n, r)

Creates a Turán Graph, a complete multipartite graph with n vertices and r partitions.

Examples

julia> using Graphs
 
 julia> turan_graph(6, 2)
 {6, 9} undirected simple Int64 graph
 
 julia> turan_graph(Int8(7), 2)
-{7, 12} undirected simple Int8 graph
source
Graphs.SimpleGraphs.wheel_digraphMethod
wheel_digraph(n)

Create a directed wheel graph with n vertices.

Examples

julia> using Graphs
 
 julia> wheel_digraph(5)
 {5, 8} directed simple Int64 graph
 
 julia> wheel_digraph(Int8(6))
-{6, 10} directed simple Int8 graph
source
Graphs.SimpleGraphs.wheel_graphMethod
wheel_graph(n)

Create an undirected wheel graph with n vertices.

Examples

julia> using Graphs
 
 julia> wheel_graph(5)
 {5, 8} undirected simple Int64 graph
 
 julia> wheel_graph(Int8(6))
-{6, 10} undirected simple Int8 graph
source
+{6, 10} undirected simple Int8 graph
source
diff --git a/dev/ecosystem/graphtypes/index.html b/dev/ecosystem/graphtypes/index.html index 3da26388..63cac3ae 100644 --- a/dev/ecosystem/graphtypes/index.html +++ b/dev/ecosystem/graphtypes/index.html @@ -1,2 +1,2 @@ -Graph types · Graphs.jl

Graph types

Defined by Graphs.jl

Graphs.jl provides two concrete graph types: SimpleGraph is an undirected graph, and SimpleDiGraph is its directed counterpart. Both of these types can be parameterized to specify how vertices are identified (by default, SimpleGraph and SimpleDiGraph use the system default integer type, usually Int64).

A graph G is described by a set of vertices V and edges E: G = {V, E}. V is an integer range 1:n; E is represented using forward (and, for directed graphs, backward) adjacency lists indexed by vertices. Edges may also be accessed via an iterator that yields Edge types containing (src<:Integer, dst<:Integer) values. Both vertices and edges may be integers of any type, and the smallest type that fits the data is recommended in order to save memory.

Graphs are created using SimpleGraph() or SimpleDiGraph(), see Graph construction for details.

Multiple edges between two given vertices are not allowed: an attempt to add an edge that already exists in a graph will not raise an error. This event can be detected using the return value of add_edge!.

Note that graphs in which the number of vertices equals or approaches the typemax of the underlying graph element (e.g., a SimpleGraph{UInt8} with 127 vertices) may encounter arithmetic overflow errors in some functions, which should be reported as bugs. To be safe, please ensure that your graph is sized with some capacity to spare.

Available in the wider ecosystem

In addition to providing SimpleGraph and SimpleDiGraph implementations, Graphs.jl also serves as an interface for custom graph types (see AbstractGraph interface).

Currently, several other packages implement alternative graph types:

  • SimpleWeightedGraphs.jl provides a structure for (un)directed graphs with the ability to specify weights on edges.
  • MetaGraphs.jl provides a structure for (un)directed graphs that supports user-defined properties on the graph, vertices, and edges.
  • MetaGraphsNext.jl does the same but in a type-stable manner, and with a slightly different interface.
  • StaticGraphs.jl supports very large graph structures in a space- and time-efficient manner, but as the name implies, does not allow modification of the graph once created.

Which graph type should I use?

These are general guidelines to help you select the proper graph type.

  • In general, prefer the native SimpleGraphs/SimpleDiGraphs structures in Graphs.jl.
  • If you need edge weights and don't require large numbers of graph modifications, use SimpleWeightedGraphs.jl.
  • If you need labeling of vertices or edges, use MetaGraphs.jl or MetaGraphsNext.jl.
  • If you work with very large graphs (billions to tens of billions of edges) and don't need mutability, use StaticGraphs.jl.
+Graph types · Graphs.jl

Graph types

Defined by Graphs.jl

Graphs.jl provides two concrete graph types: SimpleGraph is an undirected graph, and SimpleDiGraph is its directed counterpart. Both of these types can be parameterized to specify how vertices are identified (by default, SimpleGraph and SimpleDiGraph use the system default integer type, usually Int64).

A graph G is described by a set of vertices V and edges E: G = {V, E}. V is an integer range 1:n; E is represented using forward (and, for directed graphs, backward) adjacency lists indexed by vertices. Edges may also be accessed via an iterator that yields Edge types containing (src<:Integer, dst<:Integer) values. Both vertices and edges may be integers of any type, and the smallest type that fits the data is recommended in order to save memory.

Graphs are created using SimpleGraph() or SimpleDiGraph(), see Graph construction for details.

Multiple edges between two given vertices are not allowed: an attempt to add an edge that already exists in a graph will not raise an error. This event can be detected using the return value of add_edge!.

Note that graphs in which the number of vertices equals or approaches the typemax of the underlying graph element (e.g., a SimpleGraph{UInt8} with 127 vertices) may encounter arithmetic overflow errors in some functions, which should be reported as bugs. To be safe, please ensure that your graph is sized with some capacity to spare.

Available in the wider ecosystem

In addition to providing SimpleGraph and SimpleDiGraph implementations, Graphs.jl also serves as an interface for custom graph types (see AbstractGraph interface).

Currently, several other packages implement alternative graph types:

  • SimpleWeightedGraphs.jl provides a structure for (un)directed graphs with the ability to specify weights on edges.
  • MetaGraphs.jl provides a structure for (un)directed graphs that supports user-defined properties on the graph, vertices, and edges.
  • MetaGraphsNext.jl does the same but in a type-stable manner, and with a slightly different interface.
  • StaticGraphs.jl supports very large graph structures in a space- and time-efficient manner, but as the name implies, does not allow modification of the graph once created.

Which graph type should I use?

These are general guidelines to help you select the proper graph type.

  • In general, prefer the native SimpleGraphs/SimpleDiGraphs structures in Graphs.jl.
  • If you need edge weights and don't require large numbers of graph modifications, use SimpleWeightedGraphs.jl.
  • If you need labeling of vertices or edges, use MetaGraphs.jl or MetaGraphsNext.jl.
  • If you work with very large graphs (billions to tens of billions of edges) and don't need mutability, use StaticGraphs.jl.
diff --git a/dev/ecosystem/interface/index.html b/dev/ecosystem/interface/index.html index be353f42..d036bad0 100644 --- a/dev/ecosystem/interface/index.html +++ b/dev/ecosystem/interface/index.html @@ -1,2 +1,2 @@ -Creating your own graph format · Graphs.jl

Creating your own graph format

This section is designed to guide developers who wish to write their own graph structures.

All Graphs.jl functions rely on a standard API to function. As long as your graph structure is a subtype of AbstractGraph and implements the following API functions with the given return values, all functions within the Graphs.jl package should just work:

  • edges
  • edgetype (example: edgetype(g::CustomGraph) = Graphs.SimpleEdge{eltype(g)}))
  • has_edge
  • has_vertex
  • inneighbors
  • ne
  • nv
  • outneighbors
  • vertices
  • is_directed: Note that since Graphs uses traits to determine directedness, is_directed for a CustomGraph type should be implemented with both of the following signatures:
    • is_directed(::Type{CustomGraph})::Bool (example: is_directed(::Type{<:CustomGraph}) = false)
    • is_directed(g::CustomGraph)::Bool

If the graph structure is designed to represent weights on edges, the weights function should also be defined. Note that the output does not necessarily have to be a dense matrix, but it must be a subtype of AbstractMatrix{<:Real} and indexable via [u, v].

Note on inheriting from AbstractSimpleGraph

Every subtype of AbstractSimpleGraph must have vertices forming a UnitRange starting from 1 and return neighbors in ascending order. The extend to which code for graph types other than subtypes of AbstractSimpleGraph does not rely on AbstractSimpleGraph assumptions needs to be carefully checked, though in principle the requirement is only part of the AbstractSimpleGraph API.

+Creating your own graph format · Graphs.jl

Creating your own graph format

This section is designed to guide developers who wish to write their own graph structures.

All Graphs.jl functions rely on a standard API to function. As long as your graph structure is a subtype of AbstractGraph and implements the following API functions with the given return values, all functions within the Graphs.jl package should just work:

  • edges
  • edgetype (example: edgetype(g::CustomGraph) = Graphs.SimpleEdge{eltype(g)}))
  • has_edge
  • has_vertex
  • inneighbors
  • ne
  • nv
  • outneighbors
  • vertices
  • is_directed: Note that since Graphs uses traits to determine directedness, is_directed for a CustomGraph type should be implemented with both of the following signatures:
    • is_directed(::Type{CustomGraph})::Bool (example: is_directed(::Type{<:CustomGraph}) = false)
    • is_directed(g::CustomGraph)::Bool

If the graph structure is designed to represent weights on edges, the weights function should also be defined. Note that the output does not necessarily have to be a dense matrix, but it must be a subtype of AbstractMatrix{<:Real} and indexable via [u, v].

Note on inheriting from AbstractSimpleGraph

Every subtype of AbstractSimpleGraph must have vertices forming a UnitRange starting from 1 and return neighbors in ascending order. The extend to which code for graph types other than subtypes of AbstractSimpleGraph does not rely on AbstractSimpleGraph assumptions needs to be carefully checked, though in principle the requirement is only part of the AbstractSimpleGraph API.

diff --git a/dev/first_steps/access/index.html b/dev/first_steps/access/index.html index 348a0624..9618ab66 100644 --- a/dev/first_steps/access/index.html +++ b/dev/first_steps/access/index.html @@ -28,4 +28,4 @@ false julia> has_edge(g, 3, 7) # vertex number 11 "renamed" to vertex number 7 -true +true diff --git a/dev/first_steps/construction/index.html b/dev/first_steps/construction/index.html index 24e041c4..d0fbc574 100644 --- a/dev/first_steps/construction/index.html +++ b/dev/first_steps/construction/index.html @@ -1,2 +1,2 @@ -Graph construction · Graphs.jl

Graph construction

Graphs.jl provides a number of methods for creating a graph. These include tools for building and modifying graph objects, a wide array of graph generator functions, and the ability to read and write graphs from files (using GraphIO.jl).

Creating graphs

Standard generators

Graphs.jl implements numerous graph generators, including random graph generators, constructors for classic graphs, numerous small graphs with familiar topologies, and random and static graphs embedded in Euclidean space. An empty simple Graph can be constructed using g = SimpleGraph() and similary g = SimpleDiGraph() for directed graphs. See Generators for common graphs for a complete list of available templates.

Datasets

Other notorious graphs and integration with the MatrixDepot.jl package are available in the Datasets submodule of the companion package LightGraphsExtras.jl. Selected graphs from the Stanford Large Network Dataset Collection may be found in the SNAPDatasets.jl package.

Modifying graphs

Starting from a (possibly empty) graph g, one can modify it using the following functions:

  • add_vertex!(g) adds one vertex to g
  • add_vertices!(g, n) adds n vertices to g
  • add_edge!(g, s, d) adds the edge (s, d) to g
  • rem_vertex!(g, v) removes vertex v from g
  • rem_edge!(g, s, d) removes edge (s, d) from g

If an iterator of edges edgelist is available, then one can directly use SimpleGraphFromIterator(edgelist) or SimpleDiGraphFromIterator(edgelist).

In addition to these core functions, more advanced operators can be found in Operators.

+Graph construction · Graphs.jl

Graph construction

Graphs.jl provides a number of methods for creating a graph. These include tools for building and modifying graph objects, a wide array of graph generator functions, and the ability to read and write graphs from files (using GraphIO.jl).

Creating graphs

Standard generators

Graphs.jl implements numerous graph generators, including random graph generators, constructors for classic graphs, numerous small graphs with familiar topologies, and random and static graphs embedded in Euclidean space. An empty simple Graph can be constructed using g = SimpleGraph() and similary g = SimpleDiGraph() for directed graphs. See Generators for common graphs for a complete list of available templates.

Datasets

Other notorious graphs and integration with the MatrixDepot.jl package are available in the Datasets submodule of the companion package LightGraphsExtras.jl. Selected graphs from the Stanford Large Network Dataset Collection may be found in the SNAPDatasets.jl package.

Modifying graphs

Starting from a (possibly empty) graph g, one can modify it using the following functions:

  • add_vertex!(g) adds one vertex to g
  • add_vertices!(g, n) adds n vertices to g
  • add_edge!(g, s, d) adds the edge (s, d) to g
  • rem_vertex!(g, v) removes vertex v from g
  • rem_edge!(g, s, d) removes edge (s, d) from g

If an iterator of edges edgelist is available, then one can directly use SimpleGraphFromIterator(edgelist) or SimpleDiGraphFromIterator(edgelist).

In addition to these core functions, more advanced operators can be found in Operators.

diff --git a/dev/first_steps/paths_traversal/index.html b/dev/first_steps/paths_traversal/index.html index 5b4fb5fc..617ec053 100644 --- a/dev/first_steps/paths_traversal/index.html +++ b/dev/first_steps/paths_traversal/index.html @@ -1,2 +1,2 @@ -Paths and traversal · Graphs.jl

Paths and traversal

Graphs.jl provides several traversal and shortest-path algorithms, along with various utility functions. Where appropriate, edge distances may be passed in as a matrix of real number values.

Edge distances for most traversals may be passed in as a sparse or dense matrix of values, indexed by [src,dst] vertices. That is, distmx[2,4] = 2.5 assigns the distance 2.5 to the (directed) edge connecting vertex 2 and vertex 4. Note that for undirected graphs distmx[4,2] also has to be set.

Default edge distances may be passed in via the Graphs.DefaultDistance structure.

Any graph traversal will traverse an edge only if it is present in the graph. When a distance matrix is given:

  1. distance values for undefined edges will be ignored;
  2. any unassigned values (in sparse distance matrices) for edges that are present in the graph will be assumed to take the default value of 1.0;
  3. any zero values (in sparse/dense distance matrices) for edges that are present in the graph will instead have an implicit edge cost of 1.0.

Graph traversal

Graph traversal refers to a process that traverses vertices of a graph following certain order (starting from user-input sources). This package implements three traversal schemes:

  • BreadthFirst
  • DepthFirst
  • MaximumAdjacency

The package also includes uniform random walks and self avoiding walks with the following functions:

  • randomwalk
  • non_backtracking_randomwalk
  • self_avoiding_walk

Shortest paths

The following properties always hold for shortest path algorithms implemented here:

  • The distance from a vertex to itself is always 0.
  • The distance between two vertices with no connecting edge is always Inf or typemax(eltype(distmx)).

The dijkstra_shortest_paths, desopo_pape_shortest_paths, floyd_warshall_shortest_paths, bellman_ford_shortest_paths, and yen_k_shortest_paths functions return path states (subtypes of Graphs.AbstractPathState) that contain various information about the graph learned during traversal.

The corresponding state types (with the exception of YenState) have the following common fields:

  • state.dists holds a vector with the distances computed, indexed by source vertex.
  • state.parents holds a vector of parents of each vertex on the shortest paths (the parent of a source vertex is always 0). YenState substitutes .paths for .parents.

In addition, with the appropriate optional arguments, dijkstra_shortest_paths will return information on all possible shortest paths available from the source.

+Paths and traversal · Graphs.jl

Paths and traversal

Graphs.jl provides several traversal and shortest-path algorithms, along with various utility functions. Where appropriate, edge distances may be passed in as a matrix of real number values.

Edge distances for most traversals may be passed in as a sparse or dense matrix of values, indexed by [src,dst] vertices. That is, distmx[2,4] = 2.5 assigns the distance 2.5 to the (directed) edge connecting vertex 2 and vertex 4. Note that for undirected graphs distmx[4,2] also has to be set.

Default edge distances may be passed in via the Graphs.DefaultDistance structure.

Any graph traversal will traverse an edge only if it is present in the graph. When a distance matrix is given:

  1. distance values for undefined edges will be ignored;
  2. any unassigned values (in sparse distance matrices) for edges that are present in the graph will be assumed to take the default value of 1.0;
  3. any zero values (in sparse/dense distance matrices) for edges that are present in the graph will instead have an implicit edge cost of 1.0.

Graph traversal

Graph traversal refers to a process that traverses vertices of a graph following certain order (starting from user-input sources). This package implements three traversal schemes:

  • BreadthFirst
  • DepthFirst
  • MaximumAdjacency

The package also includes uniform random walks and self avoiding walks with the following functions:

  • randomwalk
  • non_backtracking_randomwalk
  • self_avoiding_walk

Shortest paths

The following properties always hold for shortest path algorithms implemented here:

  • The distance from a vertex to itself is always 0.
  • The distance between two vertices with no connecting edge is always Inf or typemax(eltype(distmx)).

The dijkstra_shortest_paths, desopo_pape_shortest_paths, floyd_warshall_shortest_paths, bellman_ford_shortest_paths, and yen_k_shortest_paths functions return path states (subtypes of Graphs.AbstractPathState) that contain various information about the graph learned during traversal.

The corresponding state types (with the exception of YenState) have the following common fields:

  • state.dists holds a vector with the distances computed, indexed by source vertex.
  • state.parents holds a vector of parents of each vertex on the shortest paths (the parent of a source vertex is always 0). YenState substitutes .paths for .parents.

In addition, with the appropriate optional arguments, dijkstra_shortest_paths will return information on all possible shortest paths available from the source.

diff --git a/dev/first_steps/persistence/index.html b/dev/first_steps/persistence/index.html index 8384b544..c0f318e5 100644 --- a/dev/first_steps/persistence/index.html +++ b/dev/first_steps/persistence/index.html @@ -13,4 +13,4 @@ savegraph("mygraph_dict.lg", graph_dict) # Re-load only graph g1 -reloaded_g1 = loadgraph("mygraph_dict.lg", "g1")

GraphIO for other formats

The GraphIO.jl library provides tools for importing and exporting graph objects using common file types like edgelists, GraphML, Pajek NET, and more.

+reloaded_g1 = loadgraph("mygraph_dict.lg", "g1")

GraphIO for other formats

The GraphIO.jl library provides tools for importing and exporting graph objects using common file types like edgelists, GraphML, Pajek NET, and more.

diff --git a/dev/first_steps/plotting/index.html b/dev/first_steps/plotting/index.html index 126d78f8..1e3d4117 100644 --- a/dev/first_steps/plotting/index.html +++ b/dev/first_steps/plotting/index.html @@ -37,4 +37,4 @@ [RGB(rand(3)/2...) for i in 1:nv(g)] ) -end 600 400

Karnak.jl example plot

+end 600 400

Karnak.jl example plot

diff --git a/dev/first_steps/theory/index.html b/dev/first_steps/theory/index.html index 49fb67b9..2a466e9e 100644 --- a/dev/first_steps/theory/index.html +++ b/dev/first_steps/theory/index.html @@ -1,2 +1,2 @@ -Basics of graph theory · Graphs.jl
+Basics of graph theory · Graphs.jl
diff --git a/dev/first_steps/tutorials/index.html b/dev/first_steps/tutorials/index.html index 9b88539d..b018417a 100644 --- a/dev/first_steps/tutorials/index.html +++ b/dev/first_steps/tutorials/index.html @@ -1,2 +1,2 @@ -Tutorials · Graphs.jl
+Tutorials · Graphs.jl
diff --git a/dev/index.html b/dev/index.html index 790a1fb6..91441298 100644 --- a/dev/index.html +++ b/dev/index.html @@ -1,5 +1,5 @@ -Graphs.jl · Graphs.jl

Graphs.jl

Documentation stable Documentation dev Build status Code coverage Code style: Blue Aqua QA ColPrac: Contributor's Guide on Collaborative Practices for Community Packages

Overview

The goal of Graphs.jl is to offer a performant platform for network and graph analysis in Julia, following the example of libraries such as NetworkX in Python. To this end, Graphs.jl offers:

  • a set of simple, concrete graph implementations – SimpleGraph (for undirected graphs) and SimpleDiGraph (for directed graphs)
  • an API for the development of more sophisticated graph implementations under the AbstractGraph type
  • a large collection of graph algorithms with the same requirements as this API.

Installation

Installation is straightforward. First, enter Pkg mode by hitting ], and then run the following command:

pkg> add Graphs

Basic use

Graphs.jl includes numerous convenience functions for generating graphs, such as path_graph, which builds a simple undirected path graph of a given length. Once created, these graphs can be easily interrogated and modified.

julia> g = path_graph(6)
+Graphs.jl · Graphs.jl

Graphs.jl

Documentation stable Documentation dev Build status Code coverage Code style: Blue Aqua QA ColPrac: Contributor's Guide on Collaborative Practices for Community Packages

Overview

The goal of Graphs.jl is to offer a performant platform for network and graph analysis in Julia, following the example of libraries such as NetworkX in Python. To this end, Graphs.jl offers:

  • a set of simple, concrete graph implementations – SimpleGraph (for undirected graphs) and SimpleDiGraph (for directed graphs)
  • an API for the development of more sophisticated graph implementations under the AbstractGraph type
  • a large collection of graph algorithms with the same requirements as this API.

Installation

Installation is straightforward. First, enter Pkg mode by hitting ], and then run the following command:

pkg> add Graphs

Basic use

Graphs.jl includes numerous convenience functions for generating graphs, such as path_graph, which builds a simple undirected path graph of a given length. Once created, these graphs can be easily interrogated and modified.

julia> g = path_graph(6)
 {6, 5} undirected simple Int64 graph
 
 # Number of vertices
@@ -11,4 +11,4 @@
 5
 
 # Add an edge to make the path a loop
-julia> add_edge!(g, 1, 6);

Documentation

The full documentation is available at GitHub Pages. Documentation for methods is also available via the Julia REPL help system. Additional tutorials can be found at JuliaGraphsTutorials.

Citing

We encourage you to cite our work if you have used our libraries, tools or datasets. Starring the Graphs.jl repository on GitHub is also appreciated.

The latest citation information may be found in the CITATION.bib file within the repository.

Contributing

We welcome contributions and bug reports! Please see CONTRIBUTING.md for guidance on development and bug reporting.

JuliaGraphs development subscribes to the Julia Community Standards.

It is an explicit design decision that any data not required for graph manipulation (attributes and other information, for example) is expected to be stored outside of the graph structure itself.

Additional functionality like advanced IO and file formats, weighted graphs, property graphs, and optimization-related functions can be found in the packages of the JuliaGraphs organization.

Project status

The Graphs.jl project is a reboot of the LightGraphs.jl package (archived in October 2021), which remains available on GitHub at sbromberger/LightGraphs.jl. If you don't need any new features developed since the fork, you can continue to use older versions of LightGraphs.jl indefinitely. New versions will be released here using the name Graphs.jl instead of LightGraphs.jl. There was an older package also called Graphs.jl. The source history and versions are still available in this repository, but the current code base is unrelated to the old Graphs.jl code and is derived purely from LightGraphs.jl. To access the history of the old Graphs.jl code, you can start from commit 9a25019.

Transition from LightGraphs to Graphs

LightGraphs.jl and Graphs.jl are functionally identical, still there are some steps involved making the change:

  • Change LightGraphs = "093fc24a-ae57-5d10-9952-331d41423f4d" to Graphs = "86223c79-3864-5bf0-83f7-82e725a168b6" in your Project.toml.
  • Update your using and import statements.
  • Update your type constraints and other references to LightGraphs to Graphs.
  • Increment your version number. Following semantic versioning, we suggest a patch release when no graphs or other Graphs.jl-objects can be passed through the API of your package by those depending on it, otherwise consider it a breaking release. "Passed through" entails created outside and consumed inside your package and vice versa.
  • Tag a release.

About versions

  • The master branch of Graphs.jl is generally designed to work with versions of Julia starting from the LTS release all the way to the current stable release, except during Julia version increments as we transition to the new version.
  • Later versions: Some functionality might not work with prerelease / unstable / nightly versions of Julia. If you run into a problem, please file an issue.
  • The project was previously developed under the name LightGraphs.jl and older versions of LightGraphs.jl (≤ v1.3.5) must still be used with that name.
  • There was also an older package also called Graphs.jl (git tags v0.2.5 through v0.10.3), but the current code base here is a fork of LightGraphs.jl v1.3.5.
  • All older LightGraphs.jl versions are tagged using the naming scheme lg-vX.Y.Z rather than plain vX.Y.Z, which is used for old Graphs.jl versions (≤ v0.10) and newer versions derived from LightGraphs.jl but released with the Graphs.jl name (≥ v1.4).
  • If you are using a version of Julia prior to 1.x, then you should use LightGraphs.jl at lg-v.12.* or Graphs.jl at v0.10.3
+julia> add_edge!(g, 1, 6);

Documentation

The full documentation is available at GitHub Pages. Documentation for methods is also available via the Julia REPL help system. Additional tutorials can be found at JuliaGraphsTutorials.

Citing

We encourage you to cite our work if you have used our libraries, tools or datasets. Starring the Graphs.jl repository on GitHub is also appreciated.

The latest citation information may be found in the CITATION.bib file within the repository.

Contributing

We welcome contributions and bug reports! Please see CONTRIBUTING.md for guidance on development and bug reporting.

JuliaGraphs development subscribes to the Julia Community Standards.

It is an explicit design decision that any data not required for graph manipulation (attributes and other information, for example) is expected to be stored outside of the graph structure itself.

Additional functionality like advanced IO and file formats, weighted graphs, property graphs, and optimization-related functions can be found in the packages of the JuliaGraphs organization.

Project status

The Graphs.jl project is a reboot of the LightGraphs.jl package (archived in October 2021), which remains available on GitHub at sbromberger/LightGraphs.jl. If you don't need any new features developed since the fork, you can continue to use older versions of LightGraphs.jl indefinitely. New versions will be released here using the name Graphs.jl instead of LightGraphs.jl. There was an older package also called Graphs.jl. The source history and versions are still available in this repository, but the current code base is unrelated to the old Graphs.jl code and is derived purely from LightGraphs.jl. To access the history of the old Graphs.jl code, you can start from commit 9a25019.

Transition from LightGraphs to Graphs

LightGraphs.jl and Graphs.jl are functionally identical, still there are some steps involved making the change:

  • Change LightGraphs = "093fc24a-ae57-5d10-9952-331d41423f4d" to Graphs = "86223c79-3864-5bf0-83f7-82e725a168b6" in your Project.toml.
  • Update your using and import statements.
  • Update your type constraints and other references to LightGraphs to Graphs.
  • Increment your version number. Following semantic versioning, we suggest a patch release when no graphs or other Graphs.jl-objects can be passed through the API of your package by those depending on it, otherwise consider it a breaking release. "Passed through" entails created outside and consumed inside your package and vice versa.
  • Tag a release.

About versions

  • The master branch of Graphs.jl is generally designed to work with versions of Julia starting from the LTS release all the way to the current stable release, except during Julia version increments as we transition to the new version.
  • Later versions: Some functionality might not work with prerelease / unstable / nightly versions of Julia. If you run into a problem, please file an issue.
  • The project was previously developed under the name LightGraphs.jl and older versions of LightGraphs.jl (≤ v1.3.5) must still be used with that name.
  • There was also an older package also called Graphs.jl (git tags v0.2.5 through v0.10.3), but the current code base here is a fork of LightGraphs.jl v1.3.5.
  • All older LightGraphs.jl versions are tagged using the naming scheme lg-vX.Y.Z rather than plain vX.Y.Z, which is used for old Graphs.jl versions (≤ v0.10) and newer versions derived from LightGraphs.jl but released with the Graphs.jl name (≥ v1.4).
  • If you are using a version of Julia prior to 1.x, then you should use LightGraphs.jl at lg-v.12.* or Graphs.jl at v0.10.3
diff --git a/dev/license/index.html b/dev/license/index.html index 7c3e0560..2d203eab 100644 --- a/dev/license/index.html +++ b/dev/license/index.html @@ -1,2 +1,2 @@ -License information · Graphs.jl

License information

The Graphs.jl (formerly called LightGraphs.jl) package is licensed under the Simplified "2-clause" BSD License:

Copyright (c) 2015: Seth Bromberger and other contributors. Copyright (c) 2012: John Myles White and other contributors.

Redistribution and use in source and binary forms, with or without modification, are permitted provided that the following conditions are met:

  1. Redistributions of source code must retain the above copyright notice, this list of conditions and the following disclaimer.
  2. Redistributions in binary form must reproduce the above copyright notice, this list of conditions and the following disclaimer in the documentation and/or other materials provided with the distribution.

THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.

Graphs uses code derived from and/or inspired by the following package(s):

NetworkX:

Copyright (C) 2004-2012, NetworkX Developers Aric Hagberg <hagberg@lanl.gov> Dan Schult <dschult@colgate.edu> Pieter Swart <swart@lanl.gov> All rights reserved.

Redistribution and use in source and binary forms, with or without modification, are permitted provided that the following conditions are met:

  • Redistributions of source code must retain the above copyright notice, this list of conditions and the following disclaimer.

  • Redistributions in binary form must reproduce the above with the distribution.

  • Neither the name of the NetworkX Developers nor the names of its contributors may be used to endorse or promote products derived from this software without specific prior written permission.

THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.

+License information · Graphs.jl

License information

The Graphs.jl (formerly called LightGraphs.jl) package is licensed under the Simplified "2-clause" BSD License:

Copyright (c) 2015: Seth Bromberger and other contributors. Copyright (c) 2012: John Myles White and other contributors.

Redistribution and use in source and binary forms, with or without modification, are permitted provided that the following conditions are met:

  1. Redistributions of source code must retain the above copyright notice, this list of conditions and the following disclaimer.
  2. Redistributions in binary form must reproduce the above copyright notice, this list of conditions and the following disclaimer in the documentation and/or other materials provided with the distribution.

THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.

Graphs uses code derived from and/or inspired by the following package(s):

NetworkX:

Copyright (C) 2004-2012, NetworkX Developers Aric Hagberg <hagberg@lanl.gov> Dan Schult <dschult@colgate.edu> Pieter Swart <swart@lanl.gov> All rights reserved.

Redistribution and use in source and binary forms, with or without modification, are permitted provided that the following conditions are met:

  • Redistributions of source code must retain the above copyright notice, this list of conditions and the following disclaimer.

  • Redistributions in binary form must reproduce the above with the distribution.

  • Neither the name of the NetworkX Developers nor the names of its contributors may be used to endorse or promote products derived from this software without specific prior written permission.

THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.