8import java.util.Iterator;
9import java.util.NoSuchElementException;
24 implements Iterable<Node>,
27 Node nodeGenerator_ =
null;
28 Edge edgeGenerator_ =
null;
47 nodeGenerator_=nodeGenerator;
48 edgeGenerator_=edgeGenerator;
79 public abstract Edge
addEdge(Node source,Node destination);
108 public abstract Edge
getEdge(Node source,Node destination);
116 Edge edge=getEdge(source,destination);
118 throw new RuntimeException(
"no such edge "+source.index()+
119 (isDirected() ?
"->" :
"--")+
120 destination.index());
139 public int getInDegree(Node node) {
return getInEdges(node).size(); }
142 public int getOutDegree(Node node) {
return getOutEdges(node).size(); }
153 return getInDegree(node)+getOutDegree(node);
155 return getInDegree(node);
169 throw new IllegalArgumentException(
"null node");
170 if (node.graph_!=
this)
171 throw new IllegalArgumentException(
"node is bound to other graph");
181 throw new IllegalArgumentException(
"null edge");
182 if (edge.graph_!=
this)
183 throw new IllegalArgumentException(
"edge is bound to other graph");
191 public class Edges implements Iterable<Edge> {
206 String rv=
"nodes:\n";
207 for (Node node :
this)
208 rv+=
" "+node.toString()+
"\n";
210 for (Edge edge : this.edges())
211 rv+=
" "+edge.toString()+
"\n";
220 String edgeOp=(isDirected() ?
" -> " :
" -- ");
221 String dot=(isDirected() ?
"digraph " :
"graph ")+
225 if (decorator!=
null) {
227 if (d!=
null) dot+=
" "+d+
";\n";
229 if (d!=
null) dot+=
" graph ["+d+
"];\n";
232 for (Node node :
this) {
233 decorator=node.getDecorator();
234 dot+=
" \""+node.index()+
"\" [label=\""+node.getLabel()+
"\",";
237 double[] p=node.getPosition();
239 dot+=
",pos=\""+p[0]+
","+p[1]+
"\",pin=true,";
247 for (Edge edge : this.edges()) {
248 decorator=edge.getDecorator();
249 dot+=
" \""+edge.source().index()+
"\""+edgeOp+
250 "\""+edge.destination().index()+
"\" ";
251 String label=edge.getLabel();
252 dot+=(label!=
null) ?
"[label=\""+label+
"\"," :
"[";
253 dot+=edge.hasWeight() ?
"weight="+edge.getWeight()+
"," :
"";
254 dot+=edge.hasWeight() ?
"len="+edge.getWeight()+
"," :
"";
Implementation of an array-based vector.
Defines iterator over all edges of anlink AbstractGraph}.
Iterator< Edge > iterator()
GraphvizDecorator getDecorator()
get decoration or null
int getOutDegree(Node node)
get number of edges emanating from node
int getDegree(Node node)
Get total degree.
abstract Iterator< Edge > getEdgeIterator()
Get iterator over all edges.
abstract Edge addEdge(Node source, Node destination)
Create and add new edge from source to destination.
abstract int getNumNodes()
get number of nodes
abstract boolean isDirected()
Is graph directed?
Edge check(Edge edge)
helper: check if edge is valid
AbstractGraph(Node nodeGenerator, Edge edgeGenerator)
Constructor.
abstract Vector< Edge > getInEdges(Node node)
Get incident edges of node.
int getInDegree(Node node)
get number of edges incident to node
abstract Node addNode()
create and add new node
String toDot()
Get dot representation.
abstract void removeNode(Node node)
Remove node and all its incident and excident edges.
Edge ensureEdge(Node source, Node destination)
Same as getEdge but throw if there is no such edge.
abstract Vector< Edge > getOutEdges(Node node)
Get incident edges of node.
abstract Node getSomeNode()
Get some node.
abstract void removeEdge(Edge edge)
Remove edge.
abstract Edge getEdge(Node source, Node destination)
Get edge from source to destination.
Node check(Node node)
helper: check if node is valid
Edges edges()
Get Edges instance to obtain iterator.
Decorator for items of Graphvizable objects.
String getFullNodeDecoration(GraphvizDecorable object)
concatenates getAllNodesDecoration and getNodeDecoration
String getFullEdgeDecoration(GraphvizDecorable object)
concatenates getAllEdgesDecoration and getEdgeDecoration
String getGlobalStyle()
get global style (returns same for all nodes/edges)
String getGraphDecoration(GraphvizDecorable object)
get graph decoration (returns same for all nodes/edges)
Interface for decorating items of Graphvizable objects.
Interface for GraphViz rendering.
utilities (not related to AuD lecture)
AuD lecture: Data structures, algorithms, examples.