|
|||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | ||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |
ObjectDomGraph
public class DomGraph
A dominance graph. Dominance graphs are directed graphs. Nodes are either labelled or unlabelled; edges are either dominance or tree edges. We say that a node is a root if it has no incoming tree edges; a leaf if it has no outgoing tree edges; and a hole if it is unlabelled.
Graph objects provide several basic methods for accessing nodes, edges, and node and edge data. In addition, they provide a number of methods for checking whether the graph belongs to one of the important graph classes, such as (weakly) normal and hypernormally connected graphs.
Several methods can take a subgraph of this graph as an argument. In this context, a subgraph is always a set of nodes.
While nodes are marked as labelled or unlabelled here, the actual node labels are not stored here, but in objects of the class NodeLabels.
Constructor Summary | |
---|---|
DomGraph()
|
Method Summary | |
---|---|
void |
addEdge(String src,
String tgt,
EdgeData data)
Adds an edge from "src" to "tgt" with the given edge data to the graph. |
void |
addNode(String name,
NodeData data)
Adds a node with the given node name and node data to the graph. |
void |
clear()
Removes all nodes and edges from this graph. |
Object |
clone()
|
DomGraph |
compactify()
Computes a compact version of this graph. |
Map<String,Integer> |
computeWccMap(List<Set<String>> wccs)
Computes a mapping of nodes to wcc indices from a list of wccs. |
List<Edge> |
getAdjacentEdges(String node)
Computes the set of all adjacent edges of a node. |
List<Edge> |
getAdjacentEdges(String node,
EdgeType type)
Computes the set of all adjacent edges of a node with a given type. |
List<DomEdge> |
getAllDomEdges()
|
Set<Edge> |
getAllEdges()
Computes the set of all edges in this graph. |
Set<String> |
getAllNodes()
Computes the set of all nodes in this graph. |
Set<String> |
getAllRoots()
Collects all roots in the graph. |
Set<String> |
getAllRoots(Collection<String> nodes)
Collects all nodes in a given subgraph which are roots. |
List<String> |
getChildren(String node,
EdgeType type)
Computes the set of children of a node via edges of a given type. |
EdgeData |
getData(Edge edge)
Gets the data associated with the given edge. |
NodeData |
getData(String node)
Gets the data associated with the given node. |
Set<String> |
getFragment(String node)
Computes the fragment of a given node. |
List<String> |
getHoles(Collection<String> fragment)
Computes the holes out of a given collection of nodes. |
List<String> |
getHoles(String node)
Computes the holes below the given node. |
List<Edge> |
getInEdges(String node,
EdgeType type)
Computes the set of all incoming edges of a node with a given type. |
List<String> |
getOpenHoles(String node)
Computes the open holes below a given node. |
List<Edge> |
getOutEdges(String node,
EdgeType type)
Computes the set of all outgoing edges of a node with a given type. |
List<String> |
getParents(String node,
EdgeType type)
Computes the set of parents of a node via edges of a given type. |
String |
getRoot(String node)
Computes the root of the fragment of the given node. |
boolean |
hasCycle(Set<String> subgraph,
EdgeType type)
Determines whether a subgraph has a directed cycle. |
boolean |
hasNode(String name)
Checks whether the graph has a node with the given name. |
int |
indeg(String node)
Computes the number of incoming edges of a given node. |
int |
indeg(String node,
EdgeType type)
Computes the number of incoming edges of a given node with a given type. |
int |
indegOfSubgraph(String node,
EdgeType type,
Set<String> subgraph)
Computes the number of incoming edges of a given node, with a given edge type, and whose source nodes are in the given subgraph. |
boolean |
isCompact()
Checks whether this graph is compact. |
boolean |
isCompactifiable()
Checks whether this graph can be compactified. |
static boolean |
isEqual(DomGraph graph1,
NodeLabels labels1,
DomGraph graph2,
NodeLabels labels2)
|
boolean |
isHypernormallyConnected()
Checks whether the graph is hypernormally connected. |
boolean |
isHypernormallyConnectedFast()
Checks whether the graph is hypernormally connected. |
boolean |
isHypernormallyConnectedSlow()
Checks whether the graph is hypernormally connected. |
boolean |
isHypernormallyReachable(String source,
String target)
Checks whether there is a hypernormal path between two nodes. |
boolean |
isHypernormallyReachable(String source,
String target,
Set<String> avoidThese)
Checks whether there is a hypernormal path between source and target which doesn't visit any of the nodes in avoidThese . |
boolean |
isLeaf(String node)
Checks whether a node is a leaf. |
boolean |
isLeafLabelled()
Checks whether the graph is leaf-labelled. |
boolean |
isNormal()
Checks whether this graph is normal. |
boolean |
isRoot(String node)
Checks whether a node is a root. |
boolean |
isSimpleSolvedForm()
Checks whether the graph is a simple solved form, i.e. |
boolean |
isWeaklyNormal()
Checks whether this graph is weakly normal. |
boolean |
isWellFormed()
Check whether the weakly normal graph is "well-formed" in the sense of Bodirsky et al. |
int |
outdeg(String node)
Computes the number of outgoing edges of a given node. |
int |
outdeg(String node,
EdgeType type)
Computes the number of outgoing edges of a given node with a given type. |
boolean |
reachable(String upper,
String lower)
Checks whether there is a directed path from "upper" to "lower" in the graph. |
void |
remove(Edge edge)
Removes a given edge from the graph. |
void |
remove(String node)
Removes a given node and all adjacent edges from the graph. |
String |
toString()
|
List<Set<String>> |
wccs()
Computes the weakly connected components of the graph. |
List<Set<String>> |
wccs(Set<String> nodes)
Computes the weakly connected components of a subgraph. |
DomGraph |
withDominanceEdges(Collection<DomEdge> domedges)
Returns a dominance graph that is just like the current graph, except that the dominance edges are replaced by those specified in domedges . |
Methods inherited from class Object |
---|
equals, getClass, hashCode, notify, notifyAll, wait, wait, wait |
Constructor Detail |
---|
public DomGraph()
Method Detail |
---|
public String getRoot(String node)
node
- a node in the graph
public List<String> getHoles(String node)
node
- a node in the graph
public List<String> getHoles(Collection<String> fragment)
fragment
- a collection of nodes in this graph
public List<String> getOpenHoles(String node)
node
- a node in this graph
public Set<String> getFragment(String node)
node
- a node of this graph
public boolean reachable(String upper, String lower)
upper
- a node in the graphlower
- a node in the graph
public void clear()
public void addNode(String name, NodeData data)
name
- the name of the new nodedata
- the data for the new nodepublic void addEdge(String src, String tgt, EdgeData data)
src
- an existing node in the graphtgt
- an existing node in the graphdata
- the data for the new edgepublic void remove(String node)
node
- a node in this graphpublic void remove(Edge edge)
edge
- an edge in this graphpublic Set<String> getAllNodes()
public boolean hasNode(String name)
name
- a node name
public Set<Edge> getAllEdges()
public List<Edge> getInEdges(String node, EdgeType type)
node
- a node in the graphtype
- an edge type, or null for edges of all types
public List<String> getParents(String node, EdgeType type)
node
- a node in the graphtype
- an edge type, or null for edges of all types
public List<Edge> getOutEdges(String node, EdgeType type)
node
- a node in the graphtype
- an edge type, or null for edges of all types
public List<Edge> getAdjacentEdges(String node, EdgeType type)
node
- a node in the graphtype
- an edge type, or null for edges of all types
public List<Edge> getAdjacentEdges(String node)
node
- a node in the graph
public List<String> getChildren(String node, EdgeType type)
node
- a node in this graphtype
- an edge type, or null for edges of all types
public NodeData getData(String node)
node
- a node in this graph
public EdgeData getData(Edge edge)
edge
- an edge in this graph
public int indeg(String node)
node
- a node in this graph
public int outdeg(String node)
node
- a node in this graph
public int indeg(String node, EdgeType type)
node
- a node in the graphtype
- the type of the in-edges you want to count, or null for edges of any type
public int indegOfSubgraph(String node, EdgeType type, Set<String> subgraph)
node
- a node in the graphtype
- an edge type, or null for edges of any typesubgraph
- the subgraph (i.e. set of nodes) in which the parents must be
public int outdeg(String node, EdgeType type)
node
- a node in the graphtype
- the type of the out-edges you want to count, or null for edges of any type
public boolean isRoot(String node)
node
- a node
public boolean isLeaf(String node)
node
- a node in the graph
public Set<String> getAllRoots(Collection<String> nodes)
nodes
- a collection of nodes (defining a subgraph)
public Set<String> getAllRoots()
public boolean hasCycle(Set<String> subgraph, EdgeType type)
null
for the complete graph) and the edge type which
can be used for the cycle (or pass null
for edges
of any type). The subgraph need not be (strongly) connected; the
method will restart the DFS at unvisited nodes of the
subgraph
while any exist.
subgraph
- the nodes which the DFS may visit, or null for the whole graphtype
- the edge types which the DFS may use, or null for any type
public List<Set<String>> wccs()
public List<Set<String>> wccs(Set<String> nodes)
nodes
- the subgraph whose wccs we want
public Map<String,Integer> computeWccMap(List<Set<String>> wccs)
wccs
- a list of WCCs, as computed by the wccs methods.
public List<DomEdge> getAllDomEdges()
public DomGraph withDominanceEdges(Collection<DomEdge> domedges)
domedges
. The original graph is not modified.
domedges
- the dominance edges of the new graph
public boolean isWeaklyNormal()
public boolean isNormal()
public boolean isCompact()
public boolean isCompactifiable()
public boolean isLeafLabelled()
public boolean isHypernormallyConnected()
This method checks whether the graph is solvable, and then
calls isHypernormallyConnectedFast
(if it is)
or isHypernormallyConnectedSlow
(if it isn't).
Its overall runtime is O(n(n+m)) for solvable graphs and
O(n^2 (n+m)) for unsolvable ones.
public boolean isHypernormallyConnectedSlow()
This method performs a depth-first search through the dominance
graph for each pair of nodes, and thus runs in time O((m+n) n^2).
This is ridiculously slow, although still efficient enough for many
practical purposes. However, unlike isHypernormallyConnectedFast
,
this method is also correct for unsolvable dominance graphs.
public boolean isHypernormallyConnectedFast()
This method performs a single depth-first search through the dominance graph, and thus runs in time O(m+n). However, it is only correct if the graph is solvable; if the graph is unsolvable, the method may claim that the graph is not hypernormally connect although it is.
public boolean isSimpleSolvedForm()
public boolean isWellFormed()
This method assumes that the graph is weakly normal and compact.
public boolean isHypernormallyReachable(String source, String target)
source
- one node in this graphtarget
- another node in this graph
public boolean isHypernormallyReachable(String source, String target, Set<String> avoidThese)
avoidThese
.
This method performs a modified depth-first search through the
dominance graph, and thus takes time O(m+n).
The method will modify the contents of avoidThese
; if
you don't want this, you should pass new HashSet
as third argument.
source
- one node in this graphtarget
- another node in this graphavoidThese
- nodes that must not be on a connecting hn path
public DomGraph compactify()
The compact graph and the original graph have corresponding solved forms.
The result is only guaranteed to be compact if the graph
is compactifiable according to the method isCompactifiable
.
public String toString()
toString
in class Object
public Object clone()
clone
in class Object
public static boolean isEqual(DomGraph graph1, NodeLabels labels1, DomGraph graph2, NodeLabels labels2)
|
|||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | ||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |