I have it setup now so that the shortest path and shortest distance methods just return a list (declared at the start of the class) and an int (also declared at the start of the class), respectively, so all of the work is supposed to be done in the 'public void doDijkstra(T start)' method.
Can someone give me any help on how to accomplish this (like pseudocode, examples, etc.) I really need help since this is due tonight!!!
Below is a skeleton of what my idea is, Thanks!
dij is a boolean variable I am using as a 'flag' for another method.
the graph could be something like ABC with weights given so that A to B is '12', B to C is '5' and C to A is '2'
something, processed, shortpath are hashsets (when i return shortpath in the shortpath method, i cast it to (List<T>)
temp is a T variable which I plan on using to store the current node I am at, processed is to keep track of nodes i have reached, and something is just the list with all the nodes.
I'm not sure if a map is needed for this, but I have one anyway......
I know this is a mess, but like I said, I could really use a good example or pseudocode, I just want to know how to do this.
public void doDijkstra(T start) {
dij = true;
something.addAll(graph.getAllElements());
processed.add(start);
valueMap.put(start, 0);
while(processed.containsAll(something)==false){
temp = something.iterator().next();//WRONG!!!!!!!!
processed.add(temp);
while(graph.getNeighbors(temp).hasNext())
if( ){
shortPath.add(temp);
}
}
}
Edited by sam199006, 11 December 2011 - 08:51 AM.


Sign In
Create Account

Back to top









