![]() |
AuD
Lecture 'Algorithmen und Datenstrukturen' (code examples)
|
Interface to a graph. More...
Classes | |
class | Edges |
Defines iterator over all edges of anlink AbstractGraph}. More... | |
Public Member Functions | |
AbstractGraph (Node nodeGenerator, Edge edgeGenerator) | |
Constructor. More... | |
abstract boolean | isDirected () |
Is graph directed? More... | |
abstract Node | addNode () |
create and add new node More... | |
abstract Edge | addEdge (Node source, Node destination) |
Create and add new edge from source to . More... | |
abstract void | removeNode (Node node) |
Remove node and all its incident and excident edges. More... | |
abstract void | removeEdge (Edge edge) |
Remove edge. More... | |
abstract int | getNumNodes () |
get number of nodes More... | |
abstract Node | getSomeNode () |
Get some node. More... | |
abstract Edge | getEdge (Node source, Node destination) |
Get edge from source to destination . More... | |
Edge | ensureEdge (Node source, Node destination) |
Same as getEdge but throw if there is no such edge. More... | |
abstract Vector< Edge > | getInEdges (Node node) |
Get incident edges of node. More... | |
abstract Vector< Edge > | getOutEdges (Node node) |
Get incident edges of node. More... | |
int | getInDegree (Node node) |
get number of edges incident to node More... | |
int | getOutDegree (Node node) |
get number of edges emanating from node More... | |
int | getDegree (Node node) |
Get total degree. More... | |
abstract Iterator< Edge > | getEdgeIterator () |
Get iterator over all edges. More... | |
Edges | edges () |
Get Edges instance to obtain iterator. More... | |
String | toString () |
GraphvizDecorator | getDecorator () |
get decoration or null More... | |
String | toDot () |
Get dot representation. More... | |
String | toDot () |
Get dot representation. More... | |
GraphvizDecorator | getDecorator () |
get decoration or null More... | |
Protected Member Functions | |
Node | check (Node node) |
helper: check if node is valid More... | |
Edge | check (Edge edge) |
helper: check if edge is valid More... | |
Interface to a graph.
Methods throw an IllegalArgumentException
if a given node or edge is invalid, i.e., it equals null
, or it is not part of this graph.
<Node> | represents a node |
<Edge> | represents an e dge |
Definition at line 22 of file AbstractGraph.java.
aud.graph.AbstractGraph< Node extends AbstractNode, Edge extends AbstractEdge >.AbstractGraph | ( | Node | nodeGenerator, |
Edge | edgeGenerator | ||
) |
Constructor.
The constructor takes two objects that serve as "templates" for creating new Node (AbstractNode#create
) and Edge (AbstractEdge#create
) instances.
Note: The instances are required due to the way how Java generics work (see type erasure). This is different (indeed much simpler but weaker) than, e.g., C++ templates.
nodeGenerator | "template" for creating Node instances |
edgeGenerator | "template" for creating Edge instances |
Definition at line 46 of file AbstractGraph.java.
|
abstract |
Create and add new edge from source
to
.
destination
For undirected graphs, source
and destination
may be swapped such that always source.index()<=destination.index()
.
RuntimeException
is thrown if the edge already exists.
source | source node |
destination | destination node |
IllegalArgumentException | |
RuntimeException |
Referenced by aud.util.GraphDemo.main(), aud.test.GraphTest.testDirectedGraph(), and aud.test.GraphTest.testUndirectedGraph().
|
abstract |
create and add new node
Referenced by aud.util.GraphDemo.main(), aud.test.GraphTest.testDirectedGraph(), and aud.test.GraphTest.testUndirectedGraph().
|
protected |
helper: check if edge is valid
IllegalArgumentException |
Definition at line 179 of file AbstractGraph.java.
|
protected |
helper: check if node is valid
IllegalArgumentException |
Definition at line 167 of file AbstractGraph.java.
Edges aud.graph.AbstractGraph< Node extends AbstractNode, Edge extends AbstractEdge >.edges | ( | ) |
Get Edges instance to obtain iterator.
Provided for convenience.
Use as for (edge : graph.edges()) { ... }
Definition at line 203 of file AbstractGraph.java.
Referenced by aud.test.GraphTest.testDirectedGraph(), and aud.test.GraphTest.testUndirectedGraph().
Edge aud.graph.AbstractGraph< Node extends AbstractNode, Edge extends AbstractEdge >.ensureEdge | ( | Node | source, |
Node | destination | ||
) |
Same as getEdge
but throw if there is no such edge.
RuntimeException | if there is no such edge |
IllegalArgumentException |
Definition at line 115 of file AbstractGraph.java.
GraphvizDecorator aud.graph.AbstractGraph< Node extends AbstractNode, Edge extends AbstractEdge >.getDecorator | ( | ) |
get decoration or null
Implements aud.util.GraphvizDecorable.
Definition at line 215 of file AbstractGraph.java.
Referenced by aud.util.GraphDemo.main().
int aud.graph.AbstractGraph< Node extends AbstractNode, Edge extends AbstractEdge >.getDegree | ( | Node | node | ) |
Get total degree.
getInEdges
and getOutEdges
for directed graphs isDirected
getInEdges
(equals getOutEdges
} for undirected graphs Definition at line 151 of file AbstractGraph.java.
Referenced by aud.test.GraphTest.testDirectedGraph(), and aud.test.GraphTest.testUndirectedGraph().
|
abstract |
Get edge from source
to destination
.
Order of arguments is not relevant for undirected graphs.
IllegalArgumentException |
null
if there is no such edge Referenced by aud.test.GraphTest.testDirectedGraph(), and aud.test.GraphTest.testUndirectedGraph().
|
abstract |
Get iterator over all edges.
Edges are traversed in arbitrary order.
Referenced by aud.graph.AbstractGraph< Node extends AbstractNode, Edge extends AbstractEdge >.Edges.iterator().
int aud.graph.AbstractGraph< Node extends AbstractNode, Edge extends AbstractEdge >.getInDegree | ( | Node | node | ) |
get number of edges incident to node
Definition at line 139 of file AbstractGraph.java.
Referenced by aud.test.GraphTest.testDirectedGraph(), and aud.test.GraphTest.testUndirectedGraph().
|
abstract |
Get incident edges of node.
For undirected graphs same as getOutEdges
.
IllegalArgumentException |
Referenced by aud.test.GraphTest.testDirectedGraph(), and aud.test.GraphTest.testUndirectedGraph().
|
abstract |
get number of nodes
Referenced by aud.test.GraphTest.testDirectedGraph(), and aud.test.GraphTest.testUndirectedGraph().
int aud.graph.AbstractGraph< Node extends AbstractNode, Edge extends AbstractEdge >.getOutDegree | ( | Node | node | ) |
get number of edges emanating from node
Definition at line 142 of file AbstractGraph.java.
Referenced by aud.test.GraphTest.testDirectedGraph(), and aud.test.GraphTest.testUndirectedGraph().
|
abstract |
Get incident edges of node.
For undirected graphs same as getInEdges
.
IllegalArgumentException |
Referenced by aud.test.GraphTest.testDirectedGraph(), and aud.test.GraphTest.testUndirectedGraph().
|
abstract |
Get some node.
This may be any node of the graph.
NoSuchElementException | (for empty graph) |
Referenced by aud.test.GraphTest.testDirectedGraph(), and aud.test.GraphTest.testUndirectedGraph().
|
abstract |
Is graph directed?
Referenced by aud.test.GraphTest.testDirectedGraph(), and aud.test.GraphTest.testUndirectedGraph().
|
abstract |
Remove edge.
IllegalArgumentException |
Referenced by aud.test.GraphTest.testDirectedGraph(), and aud.test.GraphTest.testUndirectedGraph().
|
abstract |
Remove node and all its incident and excident edges.
IllegalArgumentException |
Referenced by aud.test.GraphTest.testDirectedGraph(), and aud.test.GraphTest.testUndirectedGraph().
String aud.graph.AbstractGraph< Node extends AbstractNode, Edge extends AbstractEdge >.toDot | ( | ) |
Get dot representation.
Implements aud.util.Graphvizable.
Definition at line 219 of file AbstractGraph.java.
References aud.util.GraphvizDecorator.getFullEdgeDecoration(), aud.util.GraphvizDecorator.getFullNodeDecoration(), aud.util.GraphvizDecorator.getGlobalStyle(), and aud.util.GraphvizDecorator.getGraphDecoration().
Referenced by aud.example.graph.GraphParser.main().
String aud.graph.AbstractGraph< Node extends AbstractNode, Edge extends AbstractEdge >.toString | ( | ) |
Definition at line 205 of file AbstractGraph.java.