Basic Interface

Erdos.jl defines the following basic functionalities:

Erdos.neFunction
ne(g)

The number of edges in g.

Time Complexity: O(1)

source
Erdos.add_vertices!Function
add_vertices!(g, n)

Add n new vertices to the graph g. Returns the final number of vertices.

source
Erdos.pop_vertex!Function
pop_vertex!(g)

Remove the last vertex of g. Equivalent to rem_vertex!(g, nv(g)).

source
Erdos.rem_vertices!Function
rem_vertices!(g, vs)
rem_vertices!(g, v1, v2, ....)

Remove the vertices in vs from graph g.

Some vertices of g may be reindexed during the removal. To keep track of the reindexing, a vertex map is returned, associating vertices with changed indexes to their old indexes.

source
Erdos.has_edgeFunction
has_edge(g, e)
has_edge(g, u, v)

Returns true if the graph g has an edge e (from u to v).

source
Erdos.edgeFunction
edge(g, u, v)

Returns an edge from 'u' to 'v'. The edge doesn't necessarily exists in g.

source
Erdos.add_edge!Function
add_edge!(g, e) -> (ok, new_edge)

Add to g the edge e.

add_edge!(g, u, v) -> (ok, new_edge)

Add to g an edge from u to v.

ok=false if add fails (e.g. if vertices are not in the graph or the edge is already present) and true otherwise. new_edge is the descriptor of the new edge.

source
Erdos.unsafe_add_edge!Function
unsafe_add_edge!(g, u, v)

Possibly faster and unsafer version of add_edge!, which doesn't guarantee some graph invariant properties.

For example, some graph types (e.g. Graph) assume sorted adjacency lists as members. In this case order is not preserved while inserting new edges, resulting in a faster construction of the graph. As a consequence though, some functions such has_edge(g, u, v) could give incorrect results.

To restore the correct behaviour, call rebuild!(g) after the last call to unsafe_add_edge!.

source
Erdos.rem_edge!Function
rem_edge!(g, e)

Remove the edge e.

rem_edge!(g, u, v)

Remove the edge from u to v.

Returns false if edge removal fails (e.g., if the edge does not exist) and true otherwise.

source
Erdos.neighborsFunction
neighbors(g, v)

Returns a list of all neighbors from vertex v in g.

For directed graph, this is equivalent to out_neighbors(g, v).

NOTE: it may return a reference, not a copy. Do not modify result.

source
Erdos.in_neighborsFunction
in_neighbors(g, v)

Returns an iterable to all neighbors connected to vertex v by an incoming edge.

NOTE: it may return a reference, not a copy. Do not modify result.

source
Erdos.out_neighborsFunction
out_neighbors(g::AGraphOrDiGraph, v)

Returns an iterable to all neighbors connected to vertex v by an outgoing edge.

NOTE: it may return a reference, not a copy. Do not modify result.

source
Erdos.edgesFunction
edges(g, v)

Returns an iterator to the edges in g coming from vertex v. v == src(e) for each returned edge e.

It is equivalent to out_edges.

For digraphs, use all_edges to iterate over both in and out edges.

source
Erdos.in_edgesFunction
in_edges(g, v)

Returns an iterator to the edges in g going to vertex v. v == dst(e) for each returned edge e.

source
Erdos.out_edgesFunction
out_edges(g, v)

Returns an iterator to the edges in g coming from vertex v. v == src(e) for each returned edge e.

source
Erdos.swap_vertices!Function
swap_vertices!(g, u, v)

Swap the labels of vertices u and v. In the new graph all old neighbors of vertex u will be neighbors of v and viceversa.

source
Base.reverseFunction
reverse(e)

Returns an edge with swapped src(e) and dst(e).

source
reverse(g::ADiGraph)

Produces a graph where all edges are reversed from the original.

source
Base.reverse!Function
reverse!(g::DiGraph)

In-place reverse (modifies the original graph).

source
Erdos.adjacency_listFunction
adjacency_list(g::AGraph)
adjacency_list(g::ADiGraph, dir=:out)

Returns the adjacency list a of a graph (a vector of vector of ints). The i-th element of the adjacency list is a vector containing the neighbors of i in g.

For directed graphs a second optional argument can be specified (:out or :in). The neighbors in the returned adjacency list are considered accordingly as those related through outgoing or incoming edges.

The elements of a[i] have the same order as in the iterator (out_/in_)neighbors(g,i).

Attention: For some graph types it returns a reference, not a copy, therefore the returned object should not be modified.

source
Erdos.densityFunction
density(g)

Density is defined as the ratio of the number of actual edges to the number of possible edges. This is $|v| |v-1|$ for directed graphs and $(|v| |v-1|) / 2$ for undirected graphs.

source
Erdos.verticesFunction
vertices(g)

Returns an iterator to the vertices of a graph (i.e. 1:nv(g))

source
Erdos.graphFunction
graph{G<:AGraph}(n, edgelist::Vector{Tuple{Int,Int}},
    G = Graph)

Build a graph with n vertices, of type G, and given edgelist.

source
graph(s::Symbol, G = Graph)

Creates a notorious graph s of type G. 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.
: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.
:tutteA Tutte graph.

A collection of real world graphs is available through the readgraph function.

source
Erdos.digraphFunction
digraph{G<:AGraph}(n, edgelist::Vector{Tuple{Int,Int}},
    G = Graph)

Build a digraph with n vertices, type G, and given edgelist.

source
digraph(s::Symbol, G = DiGraph)

Creates a notorious digraph s of type G. Admissible values for s are:

sgraph type
:truncatedtetrahedronA skeleton of the truncated tetrahedron digraph.
source
Erdos.edgetypeFunction
edgetype(g)
edgetype(G)

Returns the type of edges of graph g (or graph type G), i. e. the element type returned of the iterator edges(g).

source
Erdos.vertextypeFunction
vertextype(g)
vertextype(G)

Returns the integer type of vertices of graph g (or graph type G).

source
Erdos.graphtypeFunction
graphtype{G<:AGraphOrDiGraph}(::Type{G})

The graph type corresponding to G. If G<:AGraph returns G, if G<:ADiGraph returns a type H<:AGraph.

source
Erdos.digraphtypeFunction
digraphtype{G<:AGraphOrDiGraph}(::Type{G})

The digraph type corresponding to G. If G<:ADiGraph returns G, if G<:AGraph returns a type H<:ADiGraph.

source