1package aud.example.graph;
3import java.util.Comparator;
19 new Comparator<MyNode>() {
22 return (d<0.0) ? -1 : (d>0.0 ? +1 : 0);
39 double dx=b[0]-a[0], dy=b[1]-a[1];
40 return Math.sqrt(dx*dx+dy*dy);
43 @Override
public String
name() {
return "A*"; }
48 throw new RuntimeException(
"A* requires destination");
65 System.out.println(
"open="+open.
toString());
69 assert(!Double.isInfinite(s.
d));
75 System.out.println(
"reached destination '"+s.
getLabel()+
"'");
88 System.err.println(e);
96 double dt=s.
d+(e.hasWeight() ? e.getWeight() : 1.0);
99 boolean push=Double.isInfinite(t.
d);
116 System.out.println(
"open="+open.
toString());
124 System.out.println(
"backtracked path: ");
129 System.out.print(node.
toString()+
" ");
141 System.out.println(s0);
Implementation of an unordered map based on a hash table.
Value insert(Key key, Value value)
insert key-value pair
boolean contains(Key key)
Is key contained in map?
Priority queue based on binary min-heap.
boolean is_empty()
Is PQ empty?
void push(T x)
Add entry to PQ.
T pop()
Pop minimal element from PQ.
void lower(T x)
update heap after lowering priority of x
implementation of the A* algorithm
void start(MyNode s0, MyNode s1)
find shortest path from s0 to s1
String name()
get traversal name
double h(MyNode node)
heuristic that guides search
AStarShortestPath(MyGraph g)
AStarShortestPath(MyGraph g, MyNode s1)
create instance with destination s1
void start(MyNode s0)
find shortest path to destination
Comparator< MyNode > compareNodes
comparator for {#link aud.PriorityQueue}: compares f-values (in contrast to {#link DijkstraShortestPa...
edge with all possible attributes that we require ;-)
graph based on aud.graph.GraphAM
GraphvizDecorator getDecorator()
node with all possible attributes that we require ;-)
double f
priority for A*-algorithm
MyNode p
node from which node was reached (defines spanning tree)
String color
color as string
double d
distance to start node (sum of weighs or edge count if no weights defined)
int ord
time when node is (first marked/put into front)
interface for traversals of MyGraph
int verbose
set verbosity (extra output if >0)
void initialize()
initialize graph for traversal (reset all attributes), provided for convenience to be called by start
void showMark(MyNode node)
callback to give visual feedback on marking a node
Vector< Edge > getOutEdges(Node node)
Edge getEdge(Node source, Node destination)
String getLabel()
get text description
double[] getPosition()
helper for drawing the graph: return {x,y} as array or null
Example for a simple decorator.
utilities (not related to AuD lecture)
AuD lecture: Data structures, algorithms, examples.