Skip to content

Latest commit

 

History

History
48 lines (30 loc) · 1.65 KB

graph_factories.rst

File metadata and controls

48 lines (30 loc) · 1.65 KB

Graph Factories

jgrapht

Creating graphs can be accomplished using factory methods. During runtime the type of the graph can be queried using :py.Graph.type which returns a :pyGraphType <jgrapht.types.GraphType> instance. This allows algorithms to adjust their behavior depending on the graph they are working on.

Graph

The main factory function which creates graphs is :pyjgrapht.create_graph. Depending on the given parameters different types of graphs can be represented. All graphs returned by this function are instances of :pyjgrapht.types.Graph. Most users should create graphs using this function:

jgrapht.create_graph

Sparse Graph

The following function creates a special sparse graph representation which has certain benefits and certain drawbacks. The benefits are that (a) it is much smaller w.r.t memory consumption and (b) it is also usually much faster. The drawbacks are that the sparse representation (a) cannot be modified after construction and (b) is forces a user to use vertex and edges that are integers starting from 0 in a continuous range. Since modification is not possible, a user needs to bulk-load the graph by providing both the number of vertices and all edges before hand.

jgrapht.create_sparse_graph

A helper function :pyjgrapht.copy_to_sparse_graph can help in order to create a sparse graph from another graph.

jgrapht.copy_to_sparse_graph

Building sparse graphs can be performed by using edge lists. See the section edge list importers <io/edgelist>.