public final class Graphs extends Object
Graph
instances. This class is modeled after the Collections
class.
Unless otherwise noted, all methods will throw an NullPointerException
if passed a null
graph.
Modifier and Type | Method and Description |
---|---|
static <E extends DirectedEdge> |
asDirectedGraph(Graph<E> g) |
static <T,E extends TypedEdge<T>> |
asMultigraph(Graph<E> g) |
static <E extends WeightedEdge> |
asWeightedGraph(Graph<E> g) |
static <E extends Edge> |
pack(Graph<E> g)
Creates a copy of the provided graph where all vertices are remapped to a
contiguous range from 0 to
g.order() -1. |
static <E extends Edge> |
shufflePreserve(Graph<E> g,
int shufflesPerEdge)
Shuffles the edges of
g while still preserving the degree
sequence of the graph. |
static <E extends Edge> |
shufflePreserve(Graph<E> g,
int shufflesPerEdge,
Random rnd)
Shuffles the edges of
g while still preserving the degree
sequence of the graph. |
static <T,E extends TypedEdge<T>> |
shufflePreserveType(Multigraph<T,E> g,
int shufflesPerEdge)
Shuffles the edges of
g while still preserving the degree
sequence of the graph and that edges are only swapped with those of
the same type. |
static <T,E extends TypedEdge<T>> |
shufflePreserveType(Multigraph<T,E> g,
int shufflesPerEdge,
Random rnd)
Shuffles the edges of
g while still preserving the degree
sequence of the graph and that edges are only swapped with those of
the same type. |
static <T extends Edge> |
synchronizedGraph(Graph<T> g)
To-do
|
static String |
toAdjacencyMatrixString(Graph<?> g)
Returns a pretty-print string version of the graph as an adjacency matrix
where a 1 indicates an edge and a 0 indicates no edge.
|
static <E extends Edge,G extends Graph<E>> |
toLineGraph(G graph)
Converts the provided graph into a line graph, where each
edge is mapped to a vertex and edges that share vertices are connected by
an edge in the line graph.
|
static <E extends Edge,G extends Graph<E>> |
toLineGraph(G graph,
Indexer<E> edgeIndices)
Converts the provided graph into a line graph, where each
edge is mapped to a vertex and edges that share vertices are connected by
an edge in the line graph, using
edgeIndices to specify the
mapping between edges in the input graph and their corresponding vertices
in the line graph. |
static <T extends Edge> |
unmodifiable(Graph<T> g)
To-do
|
public static <E extends DirectedEdge> DirectedGraph<E> asDirectedGraph(Graph<E> g)
public static <E extends WeightedEdge> WeightedGraph<E> asWeightedGraph(Graph<E> g)
public static <T,E extends TypedEdge<T>> Multigraph<T,E> asMultigraph(Graph<E> g)
public static <E extends Edge> Graph<E> pack(Graph<E> g)
g.order()
-1. If the graph's vertices
are already contiguous, returns the original graph.public static <E extends Edge> int shufflePreserve(Graph<E> g, int shufflesPerEdge)
g
while still preserving the degree
sequence of the graph. Each edge in the graph will attempted to be
conflated with another edge in the graph the specified number of times.
If the edge cannot be swapped (possible due to the new version of the
edge already existing), the attempt fails.g
- the graph whose elemets will be shuffledshufflesPerEdge
- the number of swaps to attempt per edge.shufflesPerEdge * g.size()
assuming that each swap was
successful. For dense graphs, this return value will be much
less.IllegalArgumentException
- if shufflesPerEdge
is
non-positivepublic static <E extends Edge> int shufflePreserve(Graph<E> g, int shufflesPerEdge, Random rnd)
g
while still preserving the degree
sequence of the graph. Each edge in the graph will attempted to be
conflated with another edge in the graph the specified number of times.
If the edge cannot be swapped (possible due to the new version of the
edge already existing), the attempt fails.g
- the graph whose elemets will be shuffledshufflesPerEdge
- the number of swaps to attempt per edge.rnd
- the source of randomness used to shuffle the graph's edgesshufflesPerEdge * g.size()
assuming that each swap was
successful. For dense graphs, this return value will be much
less.IllegalArgumentException
- if shufflesPerEdge
is
non-positivepublic static <T,E extends TypedEdge<T>> int shufflePreserveType(Multigraph<T,E> g, int shufflesPerEdge)
g
while still preserving the degree
sequence of the graph and that edges are only swapped with those of
the same type. Each edge in the graph will attempted to be conflated
with another edge in the graph the specified number of times. If the
edge cannot be swapped (possible due to the new version of the edge
already existing), the attempt fails.
Note that the Multigraph#subview(Set,Set)
method makes it
possilble to shuffle the edges for only a subset of the types in the
multigraph.
g
- the graph whose elemets will be shuffledshufflesPerEdge
- the number of swaps to attempt per edge.shufflesPerEdge * g.size()
assuming that each swap was
successful. For dense graphs, this return value will be much
less.IllegalArgumentException
- if shufflesPerEdge
is
non-positivepublic static <T,E extends TypedEdge<T>> int shufflePreserveType(Multigraph<T,E> g, int shufflesPerEdge, Random rnd)
g
while still preserving the degree
sequence of the graph and that edges are only swapped with those of
the same type. Each edge in the graph will attempted to be conflated
with another edge in the graph the specified number of times. If the
edge cannot be swapped (possible due to the new version of the edge
already existing), the attempt fails.
Note that the Multigraph#subview(Set,Set)
method makes it
possilble to shuffle the edges for only a subset of the types in the
multigraph.
g
- the graph whose elemets will be shuffledshufflesPerEdge
- the number of swaps to attempt per edge.rnd
- the source of randomness used to shuffle the graph's edgesshufflesPerEdge * g.size()
assuming that each swap was
successful. For dense graphs, this return value will be much
less.IllegalArgumentException
- if shufflesPerEdge
is
non-positivepublic static <E extends Edge,G extends Graph<E>> Graph<Edge> toLineGraph(G graph)
public static <E extends Edge,G extends Graph<E>> Graph<Edge> toLineGraph(G graph, Indexer<E> edgeIndices)
edgeIndices
to specify the
mapping between edges in the input graph and their corresponding vertices
in the line graph. If an edge is not mapped to a vertex in edgeIndices
, a new mapping will be added for it.public static String toAdjacencyMatrixString(Graph<?> g)
Copyright © 2012. All Rights Reserved.