1package aud.example.graph;
10 ((String)
null,
"aud.example.graph.TraversalExample");
17 super(
"aud.example.graph.TraversalExample");
30 "java aud.example.graph.TraversalExample "+
31 "[-g graphfile] [-m method] [-s s0] [-d s1] [-v N]\n"+
32 " -g FILE read graph from FILE\n"+
33 " -m METHOD traversal {dfs,idfs1,idfs2,bfs,dijkstra,prim,astar}\n"+
34 " -s START start node\n"+
35 " -n N show result of every n-th step\n"+
36 " -v V set verbose level (extra output)\n"+
37 " -d DESTINATION destination required for A* algorithm\n");
42 public static void main(String[] args) {
48 String destination=
null;
52 for (
int i=0;i<args.length;++i) {
53 if (args[i].compareTo(
"-g")==0)
54 graph=
new File(args[++i]);
55 else if (args[i].compareTo(
"-m")==0)
57 else if (args[i].compareTo(
"-s")==0)
59 else if (args[i].compareTo(
"-n")==0)
60 n=Integer.parseInt(args[++i]);
61 else if (args[i].compareTo(
"-v")==0)
62 verbose=Integer.parseInt(args[++i]);
63 else if (args[i].compareTo(
"-d")==0)
64 destination=args[++i];
72 g=
new GraphP88(method.compareTo(
"dfs")!=0 && method.compareTo(
"bfs")!=0);
79 if (method.compareTo(
"dfs")==0)
81 else if (method.compareTo(
"idfs1")==0)
83 else if (method.compareTo(
"idfs2")==0)
85 else if (method.compareTo(
"bfs")==0)
87 else if (method.compareTo(
"dijkstra")==0)
89 else if (method.compareTo(
"prim")==0)
91 else if (method.compareTo(
"astar")==0)
108 if (node.getLabel().compareTo(start)==0) {
113 System.err.println(
"could not find start node s0='"+start+
"'");
115 if (destination!=
null) {
117 if (node.getLabel().compareTo(destination)==0) {
122 System.err.println(
"could not find destination node s1='"+destination+
"'");
128 if (method.compareTo(
"astar")==0) {
134 app.
halt(algorithm.
name()+
" from "+s0+
" to "+s1);
140 app.
halt(
"shortest path");
143 app.
halt(algorithm.
name()+
" from "+s0);
155 System.out.println(app.
graph());
implementation of the A* algorithm
Standard recursive implementation of depth first search.
implements Dijkstra's algorithm by defining priority
undirected (weighted or unweighted )example graph (Sedgewick, Algorithms in Java.
Parse text to build graph.
void parse(String input)
parse input
Iterative implementation of DFS.
iterative implementation of DFS Traversal like DepthFirstSearch but as for IterativeDFS1 the order of...
graph based on aud.graph.GraphAM
GraphvizDecorator getDecorator()
AbstractGraph< AbstractNode, AbstractEdge > getAbstractGraph()
view this graph as an AbstractGraph
node with all possible attributes that we require ;-)
String color
color as string
implements Prim's algorithm by defining priority
MyGraph graph()
get graph (associated with traversal )
TraversalExample()
create instance
Traversal traversal
the particular traversal algorithm
static void main(String[] args)
example (see also usage)
interface for traversals of MyGraph
abstract String name()
get traversal name
SingleStepper singlestepper
may halt if single stepper was set
int verbose
set verbosity (extra output if >0)
int nsteps
halt every nsteps steps in time_
abstract void start(MyNode s0)
start traversal at node s0
Simple viewer for Graphvizable.
void display(String code)
display dot code
Example for a simple decorator.
Simple framework for single stepping code.
void halt(String text, int timeout)
display text and wait for user or timeout
utilities (not related to AuD lecture)
AuD lecture: Data structures, algorithms, examples.