public class WeightedDirectedMultigraph<T> extends Object implements Multigraph<T,WeightedDirectedTypedEdge<T>>, DirectedGraph<WeightedDirectedTypedEdge<T>>, WeightedGraph<WeightedDirectedTypedEdge<T>>, Serializable
| Constructor and Description |
|---|
WeightedDirectedMultigraph()
Creates an empty graph with node edges
|
WeightedDirectedMultigraph(Graph<? extends WeightedDirectedTypedEdge<T>> g)
Creates a directed multigraph with a copy of all the vertices and edges
in
g. |
| Modifier and Type | Method and Description |
|---|---|
boolean |
add(int vertex)
Adds a vertex with the provided index to the graph, returning
true if the vertex was not previously present (optional operation). |
boolean |
add(WeightedDirectedTypedEdge<T> e)
Adds an edge between the two vertices, returning
true if the edge
was not previously present (optional operation). |
void |
clear()
Removes all the edges and vertices from this graph (optional operation).
|
void |
clearEdges()
Removes all the edges in this graph, retaining all the vertices (optional
operation).
|
void |
clearEdges(T edgeType)
Removes all the edges in the graph with the specified edge type.
|
boolean |
contains(Edge e)
Returns
true if this graph contains an edge of the specific type
between vertex1 and vertex2. |
boolean |
contains(int vertex)
Returns
true if this graph a vertex with the specified index |
boolean |
contains(int vertex1,
int vertex2)
Returns
true if this graph contains an edge between from
and to. |
boolean |
contains(int vertex1,
int vertex2,
T edgeType)
Returns
true if there exists an edge between vertex1 and
vertex2 of the specified type. |
WeightedDirectedMultigraph<T> |
copy(Set<Integer> toCopy)
Creates a copy of this graph containing only the specified number of
vertices and all edges between those vertices.
|
int |
degree(int vertex)
Returns the number of edges that connect this vertex to other vertices in
this graph.
|
Set<WeightedDirectedTypedEdge<T>> |
edges()
Returns the set of typed edges in the graph
|
Set<WeightedDirectedTypedEdge<T>> |
edges(T t)
Returns the set of edges with the corresponding type or the empty set if
no edges of that exist.
|
Set<T> |
edgeTypes()
Returns the set of edge types currently present in this graph.
|
boolean |
equals(Object o) |
Set<WeightedDirectedTypedEdge<T>> |
getAdjacencyList(int vertex)
Returns the set of typed edges connected to the vertex.
|
Set<WeightedDirectedTypedEdge<T>> |
getEdges(int vertex1,
int vertex2)
Returns the set of
TypedEdge instances that connect the two
vertices. |
Set<WeightedDirectedTypedEdge<T>> |
getEdges(int vertex1,
int vertex2,
Set<T> types) |
IntSet |
getNeighbors(int vertex)
Returns the set of vertices that are connected to the specified vertex,
or an empty set if the vertex is not in this graph.
|
boolean |
hasCycles()
Computes whether this graph is acyclic with its current set of edges, and
returns
true if this graph contains cycles, false if
acyclic. |
int |
hashCode() |
int |
inDegree(int vertex)
Returns the number of directed edges where
vertex is the head of
the edge, i.e. |
Set<WeightedDirectedTypedEdge<T>> |
inEdges(int vertex)
Returns the set of directed edges where
vertex is the head of the
edge |
int |
order()
Returns the number of vertices in this graph.
|
int |
outDegree(int vertex)
Returns the number of directed edges where
vertex is the tail of
the edge, i.e. |
Set<WeightedDirectedTypedEdge<T>> |
outEdges(int vertex)
Returns the set of directed edges where
vertex is the tail of the
edge, i.e. |
IntSet |
predecessors(int vertex)
Returns the set of vertices that point to this vertex.
|
boolean |
remove(int vertex)
Removes the vertex and all of its connected edges from the graph
(optional operation).
|
boolean |
remove(WeightedDirectedTypedEdge<T> edge)
Removes the edge from
vertex1 to vertex2, returning
true if the edge existed and was removed (optional operation). |
int |
size()
Returns the number of edges in this graph.
|
double |
strength(int vertex)
Returns the sum of the weights for all edges connected to this vertex.
|
WeightedDirectedMultigraph<T> |
subgraph(Set<Integer> subset)
Returns a view of this graph containing only the specified vertices where
the returned graph's vertinces are renamed (0, ..., n).
|
WeightedDirectedMultigraph<T> |
subgraph(Set<Integer> subset,
Set<T> edgeTypes)
Returns a subgraph of this graph containing only the specified vertices
and edges of the specified types.
|
IntSet |
successors(int vertex)
Returns the set of vertices that can be reached by following the outgoing
edges from this vertex.
|
String |
toString()
Returns a description of the graph as the sequence of its edges.
|
IntSet |
vertices()
Returns the set of vertices in this graph.
|
public WeightedDirectedMultigraph()
public WeightedDirectedMultigraph(Graph<? extends WeightedDirectedTypedEdge<T>> g)
g.public boolean add(int vertex)
true if the vertex was not previously present (optional operation).add in interface Graph<WeightedDirectedTypedEdge<T>>vertex - a non-negative index for a vertex. If the graph has size bounds
(i.e. a limited number of vertices), the implementation may throw
an exception if this index exceeds those bounds.public boolean add(WeightedDirectedTypedEdge<T> e)
true if the edge
was not previously present (optional operation).
If adding this edge would violate some structural constraints on the
graph, implementations may return false or throw a GraphConstructionException. If false is returned, the called
may check whether the edge was added using containsEdge
Implemenations are free to decide the behavior for cases where one or
both of the vertices are not currently in the graph, and whether
self-edges are allowed (i.e. vertex1 == vertex2).
add in interface Graph<WeightedDirectedTypedEdge<T>>add in interface WeightedGraph<WeightedDirectedTypedEdge<T>>true if the edge was added, false if the edge was
not added, or if the edge was aready present#containsEdge(int, int)public void clear()
clear in interface Graph<WeightedDirectedTypedEdge<T>>public void clearEdges()
clearEdges in interface Graph<WeightedDirectedTypedEdge<T>>public void clearEdges(T edgeType)
clearEdges in interface Multigraph<T,WeightedDirectedTypedEdge<T>>public boolean contains(int vertex)
true if this graph a vertex with the specified indexcontains in interface Graph<WeightedDirectedTypedEdge<T>>public boolean contains(Edge e)
true if this graph contains an edge of the specific type
between vertex1 and vertex2.contains in interface Graph<WeightedDirectedTypedEdge<T>>public boolean contains(int vertex1,
int vertex2)
true if this graph contains an edge between from
and to. Imeplementations are free to define whether the ordering
of the vertices matters.contains in interface Graph<WeightedDirectedTypedEdge<T>>public boolean contains(int vertex1,
int vertex2,
T edgeType)
true if there exists an edge between vertex1 and
vertex2 of the specified type.contains in interface Multigraph<T,WeightedDirectedTypedEdge<T>>public WeightedDirectedMultigraph<T> copy(Set<Integer> toCopy)
vertices is
empty a new, empty graph of this instance's type is returned. Any
changes made to this graph will not be reflected in returned copy or
vice-versa.copy in interface DirectedGraph<WeightedDirectedTypedEdge<T>>copy in interface Graph<WeightedDirectedTypedEdge<T>>copy in interface Multigraph<T,WeightedDirectedTypedEdge<T>>copy in interface WeightedGraph<WeightedDirectedTypedEdge<T>>public int degree(int vertex)
0.degree in interface Graph<WeightedDirectedTypedEdge<T>>public Set<WeightedDirectedTypedEdge<T>> edges()
edges in interface Graph<WeightedDirectedTypedEdge<T>>edges in interface Multigraph<T,WeightedDirectedTypedEdge<T>>edges in interface WeightedGraph<WeightedDirectedTypedEdge<T>>public Set<WeightedDirectedTypedEdge<T>> edges(T t)
edges in interface Multigraph<T,WeightedDirectedTypedEdge<T>>public Set<T> edgeTypes()
edgeTypes in interface Multigraph<T,WeightedDirectedTypedEdge<T>>public Set<WeightedDirectedTypedEdge<T>> getAdjacencyList(int vertex)
getAdjacencyList in interface Graph<WeightedDirectedTypedEdge<T>>getAdjacencyList in interface Multigraph<T,WeightedDirectedTypedEdge<T>>getAdjacencyList in interface WeightedGraph<WeightedDirectedTypedEdge<T>>public Set<WeightedDirectedTypedEdge<T>> getEdges(int vertex1, int vertex2)
TypedEdge instances that connect the two
vertices. If no edges connect the vertices, the set will be empty but
non-null.getEdges in interface DirectedGraph<WeightedDirectedTypedEdge<T>>getEdges in interface Graph<WeightedDirectedTypedEdge<T>>getEdges in interface Multigraph<T,WeightedDirectedTypedEdge<T>>getEdges in interface WeightedGraph<WeightedDirectedTypedEdge<T>>public Set<WeightedDirectedTypedEdge<T>> getEdges(int vertex1, int vertex2, Set<T> types)
public IntSet getNeighbors(int vertex)
getNeighbors in interface Graph<WeightedDirectedTypedEdge<T>>public boolean hasCycles()
true if this graph contains cycles, false if
acyclic.hasCycles in interface Graph<WeightedDirectedTypedEdge<T>>public int inDegree(int vertex)
vertex is the head of
the edge, i.e. the edge points to vertex.inDegree in interface DirectedGraph<WeightedDirectedTypedEdge<T>>public Set<WeightedDirectedTypedEdge<T>> inEdges(int vertex)
vertex is the head of the
edgeinEdges in interface DirectedGraph<WeightedDirectedTypedEdge<T>>public int order()
order in interface Graph<WeightedDirectedTypedEdge<T>>public int outDegree(int vertex)
vertex is the tail of
the edge, i.e. the edge originates at vertexoutDegree in interface DirectedGraph<WeightedDirectedTypedEdge<T>>public Set<WeightedDirectedTypedEdge<T>> outEdges(int vertex)
vertex is the tail of the
edge, i.e. the edge originates at vertexoutEdges in interface DirectedGraph<WeightedDirectedTypedEdge<T>>public IntSet predecessors(int vertex)
predecessors in interface DirectedGraph<WeightedDirectedTypedEdge<T>>public boolean remove(int vertex)
remove in interface Graph<WeightedDirectedTypedEdge<T>>public boolean remove(WeightedDirectedTypedEdge<T> edge)
vertex1 to vertex2, returning
true if the edge existed and was removed (optional operation).remove in interface Graph<WeightedDirectedTypedEdge<T>>public int size()
size in interface Graph<WeightedDirectedTypedEdge<T>>public double strength(int vertex)
0 is returned.strength in interface WeightedGraph<WeightedDirectedTypedEdge<T>>public IntSet successors(int vertex)
successors in interface DirectedGraph<WeightedDirectedTypedEdge<T>>public WeightedDirectedMultigraph<T> subgraph(Set<Integer> subset)
Only edges connecting two vertices in the provided set will be viewable in the subgraph. Any changes to the subgraph will be reflected in this graph and vice versa.
This view allows for direct manipulation of a part of the graph. For example, clearing this subgraph will remove all of its corresponding vertices and edges from the backing graph.
subgraph in interface DirectedGraph<WeightedDirectedTypedEdge<T>>subgraph in interface Graph<WeightedDirectedTypedEdge<T>>subgraph in interface Multigraph<T,WeightedDirectedTypedEdge<T>>subgraph in interface WeightedGraph<WeightedDirectedTypedEdge<T>>subset - the vertices to include in the subgraphpublic WeightedDirectedMultigraph<T> subgraph(Set<Integer> subset, Set<T> edgeTypes)
subgraph in interface Multigraph<T,WeightedDirectedTypedEdge<T>>public String toString()
public IntSet vertices()
vertices in interface Graph<WeightedDirectedTypedEdge<T>>Copyright © 2012. All Rights Reserved.