|
||||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |
java.lang.Objectnet.xqhs.util.config.Config
net.xqhs.util.logging.Unit
net.xqhs.graphs.graph.SimpleGraph
public class SimpleGraph
Represents a directed graph, using Node
and Edge
elements.
Functions that modify the graph return the graph itself, so that chained calls are possible.
This class should only be used as a data structure. Visualization should happen elsewhere (for instance, in
LinearGraphRepresentation
.
Currently only supports adding of new nodes and edges, as well as reading from / writing to simple formats.
Warning: if a graph contains the edge, it does not necessarily contain any of the nodes of the edge. It may be that the nodes have not been added to the graph. This is because this graph may be a subgraph of a larger graph.
Nested Class Summary | |
---|---|
protected static class |
SimpleGraph.NodeData
Protected structure holding two sets of edges -- incoming and outgoing. |
Nested classes/interfaces inherited from class net.xqhs.util.config.Config |
---|
net.xqhs.util.config.Config.ConfigLockedException |
Field Summary | |
---|---|
static char |
EDGE_LINE
Character that marks the beginning and end of an edge. |
static char |
EDGE_SEPARATOR
Separator between edges. |
static char |
EDGE_TARGET
Character that marks the destination end of an oriented edge. |
protected java.util.Set<Edge> |
edges
The edges |
protected java.util.Map<Node,SimpleGraph.NodeData> |
nodes
The nodes |
Fields inherited from class net.xqhs.util.logging.Unit |
---|
DEFAULT_LEVEL, DEFAULT_UNIT_NAME |
Constructor Summary | |
---|---|
SimpleGraph()
Creates an empty graph. |
Method Summary | |
---|---|
SimpleGraph |
add(GraphComponent component)
This is the only method that actually adds a component to the graph. |
SimpleGraph |
addAll(java.util.Collection<? extends GraphComponent> components)
|
SimpleGraph |
addEdge(Edge edge)
Warning: the function will not add the nodes to the graph, only the edge between them. |
SimpleGraph |
addNode(Node node)
|
java.util.Map<Node,java.lang.Integer> |
computeDistancesFromUndirected(Node node)
Simple Dijkstra algorithm to compute the distance between one node and all others. |
boolean |
contains(GraphComponent component)
|
java.util.Collection<GraphComponent> |
getComponents()
|
java.util.Collection<Edge> |
getEdges()
|
java.util.Collection<Edge> |
getInEdges(Node node)
Retrieves the edges going into the specified node. |
java.util.Collection<Node> |
getNodes()
|
java.util.Collection<Node> |
getNodesNamed(java.lang.String name)
|
java.util.Collection<Edge> |
getOutEdges(Node node)
Retrieves the edges outgoing from the specified node. |
java.lang.String |
getUnitName()
|
int |
m()
|
int |
n()
|
SimpleGraph |
readFrom(java.io.InputStream input)
Reads the structure of the graph as list of edges, adding all nodes appearing in the definition of edges. |
SimpleGraph |
remove(GraphComponent component)
This is the only method that actually removes a component from the graph. |
Graph |
removeAll(java.util.Collection<? extends GraphComponent> components)
|
SimpleGraph |
removeEdge(Edge edge)
|
SimpleGraph |
removeNode(Node node)
|
int |
size()
|
java.lang.String |
toDot()
Creates a representation of the Graph in DOT format. |
java.lang.String |
toString()
Returns a display of the graph that shows the number of nodes and edges, the list of nodes and the list of edges. |
Methods inherited from class net.xqhs.util.logging.Unit |
---|
compose, dbg, doExit, getDefaultUnitName, l, le, lf, li, lock, lockedR, lr, lr, lw, setLink, setLink, setLogDisplay, setLogEnsureNew, setLoggerClass, setLoggerType, setLoggerTypeClass, setLogLevel, setLogReporter, setUnitName, setUnitName |
Methods inherited from class net.xqhs.util.config.Config |
---|
build, ensureLocked, locked, lockedEx, makeDefaults |
Methods inherited from class java.lang.Object |
---|
clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait |
Field Detail |
---|
public static char EDGE_SEPARATOR
public static char EDGE_LINE
EDGE_TARGET
. In case of bi-directional
unlabeled edges, the representation of an edge may contain only one character.
public static char EDGE_TARGET
protected java.util.Map<Node,SimpleGraph.NodeData> nodes
protected java.util.Set<Edge> edges
Constructor Detail |
---|
public SimpleGraph()
Method Detail |
---|
public java.lang.String getUnitName()
getUnitName
in class net.xqhs.util.logging.Unit
public SimpleGraph addNode(Node node)
addNode
in interface Graph
node
- - the Node
to add.
public SimpleGraph addEdge(Edge edge)
addEdge
in interface Graph
edge
- : the edge to add
public SimpleGraph add(GraphComponent component)
add
in interface Graph
component
- - the component to add. Must be an implementation of GraphComponent
that the implementing
class can recognize.
public SimpleGraph addAll(java.util.Collection<? extends GraphComponent> components)
addAll
in interface Graph
components
- - the components to add. Each must be an implementation of GraphComponent
that the
implementing class can recognize.
public SimpleGraph removeNode(Node node)
removeNode
in interface Graph
node
- - the Node
to remove.
public SimpleGraph removeEdge(Edge edge)
removeEdge
in interface Graph
edge
- - the Edge
to remove.
public SimpleGraph remove(GraphComponent component)
remove
in interface Graph
component
- - the component to remove. Must be an implementation of GraphComponent
that the implementing
class can recognize.
public Graph removeAll(java.util.Collection<? extends GraphComponent> components)
removeAll
in interface Graph
components
- - the components to remove. Each must be an implementation of GraphComponent
that the
implementing class can recognize.
public int n()
n
in interface Graph
public int m()
m
in interface Graph
public int size()
size
in interface Graph
public java.util.Collection<Node> getNodes()
getNodes
in interface Graph
Node
instances in the graph. May be an immutable collection.public java.util.Collection<Edge> getEdges()
getEdges
in interface Graph
Edge
instances in the graph. May be an immutable collection.public java.util.Collection<GraphComponent> getComponents()
getComponents
in interface Graph
GraphComponent
instances in the graph. May be an immutable collection.public java.util.Collection<Edge> getOutEdges(Node node)
Graph
getOutEdges
in interface Graph
node
- - the node.
public java.util.Collection<Edge> getInEdges(Node node)
Graph
getInEdges
in interface Graph
node
- - the node.
public boolean contains(GraphComponent component)
contains
in interface Graph
component
- - the component search for. Must be an implementation of GraphComponent
that the implementing
class can recognize.
true
if the component is contained; false
otherwise.public java.util.Collection<Node> getNodesNamed(java.lang.String name)
getNodesNamed
in interface Graph
name
- - the name to search for.
Collection
of Node
instances with the required label.public java.util.Map<Node,java.lang.Integer> computeDistancesFromUndirected(Node node)
node
- : the source node.
public java.lang.String toString()
toString
in class java.lang.Object
public java.lang.String toDot()
Graph
in DOT format.
See http://en.wikipedia.org/wiki/DOT_language
public SimpleGraph readFrom(java.io.InputStream input)
input
- - a stream to read from
SimpleGraph
instance
|
||||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |