N
- Node content typeE
- Edge content typepublic class ConcreteDGraph<N,E> extends AbstractDGraph<N,E> implements Cloneable
This class gives a standard representation for a directed graph by sets of successors and predecessors.
A directed graph is composed of
Node
; - a treemap of successors that associates to each node a treeset of successors, defined by class Edge
; - a treemap of predecessors that associates to each node a treeset of predecessors, defined by class Edge
.This class provides methods implementing classical operation on a directed graph:
This class also provides a static method randomly generating a directed graph.
Constructor and Description |
---|
ConcreteDGraph()
Constructs a new directed graph with an empty set of node.
|
ConcreteDGraph(DGraph<N,E> graph)
Constructs this component as a copy of the specified directed graph.
|
ConcreteDGraph(SortedSet<Node<N>> set)
Constructs a new directed graph source the specified set of nodes.
|
Modifier and Type | Method and Description |
---|---|
boolean |
addEdge(Edge<N,E> edge)
Adds the specified edge to this component in the successors of edge.getSource() and in the predecessors of edge.getTarget().
|
boolean |
addEdge(Node<N> source,
Node<N> target)
Adds an edge between the specified nodes to this component:
to is added as a successor of source . |
boolean |
addEdge(Node<N> source,
Node<N> target,
Object content)
Adds an edge between the specified nodes to this component:
to is added as a successor of source . |
boolean |
addNode(Node<N> node)
Adds the specified node to the set of node of this component.
|
ConcreteDGraph<N,E> |
clone()
Returns a clone of this component composed of a clone of each node and each edge.
|
void |
complementary()
Replaces this component by its complementary graph.
|
boolean |
containsEdge(Edge<N,E> edge)
Checks if the specified edge belong to this component.
|
boolean |
containsEdge(Node<N> source,
Node<N> target)
Checks if there exists an edge between the two specified nodes.
|
boolean |
containsNode(Node<N> node)
Checks if the specified node belong to this component.
|
Edge<N,E> |
getEdge(Node<N> source,
Node<N> target)
Returns, if it exists, the edge between node source and node to.
|
SortedSet<Edge<N,E>> |
getEdges()
Returns the set of edges of this component.
|
Node<N> |
getNode(Node<N> search)
Returns the node that is equal to the specified one.
|
Node<N> |
getNodeByContent(Object content)
Returns the node whose content is equal to the specified one.
|
Node<N> |
getNodeByIdentifier(int identifier)
Returns the node whose ident is equal to the specified one.
|
SortedSet<Node<N>> |
getNodes()
Returns the set of nodes of this component.
|
SortedSet<Edge<N,E>> |
getPredecessorEdges(Node<N> node)
Returns the set of edges predecessors of the specified node.
|
SortedSet<Node<N>> |
getPredecessorNodes(Node<N> node)
Returns the set of nodes predecessors of the specified node.
|
protected TreeMap<Node<N>,TreeSet<Edge<N,E>>> |
getPredecessors()
Returns the predecessors of this component.
|
DAGraph<SortedSet<Node<N>>,Object> |
getStronglyConnectedComponent()
Returns the directed acyclic graph where each node corresponds to a strongly connected component (SCC) of this component stored in a TreeSet of nodes.
|
ConcreteDGraph<N,E> |
getSubgraphByEdges(Set<Edge<N,E>> edges)
Returns the subgraph of this component induced by the specified set of edges.
|
ConcreteDGraph<N,E> |
getSubgraphByNodes(Set<Node<N>> nodes)
Returns the subgraph of this component induced by the specified set of nodes.
|
SortedSet<Edge<N,E>> |
getSuccessorEdges(Node<N> node)
Returns the set of edges successors of the specified node.
|
SortedSet<Node<N>> |
getSuccessorNodes(Node<N> node)
Returns the set of nodes successors of the specified node.
|
protected TreeMap<Node<N>,TreeSet<Edge<N,E>>> |
getSuccessors()
Returns the successors of this component.
|
int |
reflexiveClosure()
Computes the reflexive closure of this component.
|
int |
reflexiveReduction()
Computes the reflexive reduction of this component.
|
boolean |
removeEdge(Edge<N,E> edge)
Removes source this component the specified edge source the successors of edge.getSource() and source the predecessors of edge.getTarget().
|
boolean |
removeEdge(Node<N> source,
Node<N> target)
Removes source this component the edge between the specified node.
|
boolean |
removeNode(Node<N> node)
Removes the specified node from this component.
|
boolean |
removeNodes(Set<Node<N>> nodes)
Removes the specified set of nodes from this component.
|
protected ConcreteDGraph<N,E> |
setNodes(TreeSet<Node<N>> nodes)
Set the set of nodes of this component.
|
protected ConcreteDGraph<N,E> |
setPredecessors(TreeMap<Node<N>,TreeSet<Edge<N,E>>> predecessors)
Set the predecessors of this component.
|
protected ConcreteDGraph<N,E> |
setSuccessors(TreeMap<Node<N>,TreeSet<Edge<N,E>>> successors)
Set the successors of this component.
|
int |
sizeEdges()
Returns the number of edges of this component.
|
int |
sizeNodes()
Returns the number of nodes of this component.
|
int |
transitiveClosure()
Computes the transitive closure of this component.
|
void |
transpose()
Transposes this component by replacing for each node its successor set by its predecessor set, and its predecessor set by its successor set.
|
getSinks, getWells, isAcyclic, save, topologicalSort, toString
public ConcreteDGraph()
Constructs a new directed graph with an empty set of node.
public ConcreteDGraph(SortedSet<Node<N>> set)
Constructs a new directed graph source the specified set of nodes.
Successors and predecessors of each nodes are initialised by an empty set.
set
- the set of nodespublic ConcreteDGraph<N,E> clone() throws CloneNotSupportedException
Returns a clone of this component composed of a clone of each node and each edge.
clone
in class Object
CloneNotSupportedException
public final SortedSet<Edge<N,E>> getSuccessorEdges(Node<N> node)
Returns the set of edges successors of the specified node.
getSuccessorEdges
in interface DGraph<N,E>
node
- the node to search forpublic final SortedSet<Edge<N,E>> getPredecessorEdges(Node<N> node)
Returns the set of edges predecessors of the specified node.
getPredecessorEdges
in interface DGraph<N,E>
node
- the node to search forpublic final SortedSet<Node<N>> getSuccessorNodes(Node<N> node)
Returns the set of nodes successors of the specified node.
getSuccessorNodes
in interface DGraph<N,E>
node
- the node to search foruse iterator pattern (some changes in ArrowRelation.java and Lattice.java)
public final SortedSet<Node<N>> getPredecessorNodes(Node<N> node)
Returns the set of nodes predecessors of the specified node.
getPredecessorNodes
in interface DGraph<N,E>
node
- the node to search foruse iterator pattern (some changes in ArrowRelation.java and Lattice.java)
public final Edge<N,E> getEdge(Node<N> source, Node<N> target)
Returns, if it exists, the edge between node source and node to.
source
- The origin nodetarget
- The destination nodesee getNode
public final Node<N> getNode(Node<N> search)
Returns the node that is equal to the specified one.
search
- The node to search formaybe use try { return this.nodes.subSet(search, true, search, true).first(); } catch (NoSuchElementException e) { return null; }
public final Node<N> getNodeByContent(Object content)
Returns the node whose content is equal to the specified one.
content
- The content to search forthis method is not efficient. Do we remove it or add an index on DGraph using content field? Verify where it is called for migrating it if necessary.
public final Node<N> getNodeByIdentifier(int identifier)
Returns the node whose ident is equal to the specified one.
identifier
- node identifierpublic final int sizeNodes()
Returns the number of nodes of this component.
public final int sizeEdges()
Returns the number of edges of this component.
public final boolean containsNode(Node<N> node)
Checks if the specified node belong to this component.
node
- the node to insertpublic final boolean addNode(Node<N> node)
Adds the specified node to the set of node of this component.
node
- the node to insertpublic final boolean removeNode(Node<N> node)
Removes the specified node from this component.
node
- the node to removepublic final boolean removeNodes(Set<Node<N>> nodes)
Removes the specified set of nodes from this component.
nodes
- set of nodespublic final boolean containsEdge(Node<N> source, Node<N> target)
Checks if there exists an edge between the two specified nodes.
source
- the node origine of the edgetarget
- the node destination of the edgepublic final boolean containsEdge(Edge<N,E> edge)
Checks if the specified edge belong to this component.
edge
- the edge to be checkedpublic final boolean addEdge(Node<N> source, Node<N> target, Object content)
Adds an edge between the specified nodes to this component: to
is added as a successor of source
.
If the case where specified nodes don’t belongs to the node set, then the edge will not be added.
source
- the node origin of the edgetarget
- the node destination of the edgecontent
- the edge contentpublic final boolean addEdge(Node<N> source, Node<N> target)
Adds an edge between the specified nodes to this component: to
is added as a successor of source
.
If the case where specified nodes don’t belongs to the node set, then the edge will not be added.
source
- the node origin of the edgetarget
- the node destination of the edgepublic final boolean addEdge(Edge<N,E> edge)
Adds the specified edge to this component in the successors of edge.getSource() and in the predecessors of edge.getTarget().
If the case where nodes to and source of this edges don’t belongs to the node set, then the edge will not be added.
edge
- the edge to be addedpublic final boolean removeEdge(Node<N> source, Node<N> target)
Removes source this component the edge between the specified node.
to
is removed source the successors of source
and to
is removed source the predecessors of source
.
source
- the node origine of the edgetarget
- the node destination of the edgepublic final boolean removeEdge(Edge<N,E> edge)
Removes source this component the specified edge source the successors of edge.getSource() and source the predecessors of edge.getTarget().
edge
- the edge to be removed.public ConcreteDGraph<N,E> getSubgraphByNodes(Set<Node<N>> nodes)
Returns the subgraph of this component induced by the specified set of nodes.
The subgraph only contains nodes of the specified set that also are in this component.
nodes
- The set of nodesimplement a SubGraph class?
public ConcreteDGraph<N,E> getSubgraphByEdges(Set<Edge<N,E>> edges)
Returns the subgraph of this component induced by the specified set of edges.
The subgraph contains all nodes of this components, and only edges of the specified set that also are in this component.
edges
- The set of edgesimplement a SubGraph class?
public void complementary()
Replaces this component by its complementary graph.
There is an edge between to nodes in the complementary graph when there is no edges between the nodes in this component.
public final int reflexiveReduction()
Computes the reflexive reduction of this component.
public final int reflexiveClosure()
Computes the reflexive closure of this component.
public int transitiveClosure()
Computes the transitive closure of this component.
This treatment is performed in $O(nm+m_c)$, where $n$ corresponds to the number of nodes, $m$ to the number of edges, and $m_c$ to the number of edges in the closure. This treatment improves the Roy-Warshall algorithm that directly implements the definition in $O(log(m) n^3)$.
This treatment is overridden in class DAGraph
with a more efficient algorithm dedicated to directed acyclic graph.
public final void transpose()
Transposes this component by replacing for each node its successor set by its predecessor set, and its predecessor set by its successor set.
public DAGraph<SortedSet<Node<N>>,Object> getStronglyConnectedComponent()
Returns the directed acyclic graph where each node corresponds to a strongly connected component (SCC) of this component stored in a TreeSet of nodes.
When two nodes in two different SCC are in relation, the same is for the SCC they belongs to.
protected ConcreteDGraph<N,E> setNodes(TreeSet<Node<N>> nodes)
Set the set of nodes of this component.
nodes
- The nodesprotected TreeMap<Node<N>,TreeSet<Edge<N,E>>> getSuccessors()
Returns the successors of this component.
protected ConcreteDGraph<N,E> setSuccessors(TreeMap<Node<N>,TreeSet<Edge<N,E>>> successors)
Set the successors of this component.
successors
- The successorsprotected TreeMap<Node<N>,TreeSet<Edge<N,E>>> getPredecessors()
Returns the predecessors of this component.
Copyright © 2010–2016 The Galactic Organization. All rights reserved.