Commit 09039f55 authored by trh010's avatar trh010
Browse files

progress

parent d7a68ee3
......@@ -2,5 +2,8 @@
<classpath>
<classpathentry kind="src" path="src"/>
<classpathentry kind="con" path="org.eclipse.jdt.launching.JRE_CONTAINER/org.eclipse.jdt.internal.debug.ui.launcher.StandardVMType/JavaSE-1.7"/>
<classpathentry kind="var" path="JUNIT_HOME/junit.jar"/>
<classpathentry kind="var" path="AGITAR_MOCK_OBJECTS"/>
<classpathentry kind="var" path="AGITAR_TEST_LIB"/>
<classpathentry kind="output" path="bin"/>
</classpath>
......@@ -101,7 +101,7 @@ public class AdjacencyList {
}
private void buildDijkstraGraph(int startingVertex){
Vertex start = getVertexFromHandle(startingVertex);
Vertex start = adjList.get(startingVertex);
//Initialize graph
Vertex temp;
for(int i = 0; i < adjList.size(); i++){
......@@ -138,7 +138,7 @@ public class AdjacencyList {
}
private ArrayList<Integer> findPathRev(Vertex start, Vertex end, ArrayList<Integer> path){
if(end.getPred() == -1)
if(end.equals(start))
return path;
Vertex next = adjList.get(end.getPred());
path.add(next.getAdjListIndex());
......@@ -146,23 +146,29 @@ public class AdjacencyList {
return findPathRev(start, next, path);
}
public String printPath(ArrayList<Integer> reversedPath){
private String pathToString(ArrayList<Integer> reversedPath){
StringBuffer out = new StringBuffer();
for (int i = reversedPath.size() - 1; i >= 0; i--){
out.append(" " + adjList.get(reversedPath.get(i)));
if((reversedPath.size() - i) % 10 == 0)
out.append("\n");
}
return out.toString();
}
public ArrayList<Integer> findMinimumPath(String s1, String s2){
int s1Handle = findStringHandle(s1);
int s2Handle = findStringHandle(s2);
public String outputToString(int s1, int s2){
ArrayList<Integer> revPath = findMinimumPath(s1,s2);
return pathToString(revPath);
}
public ArrayList<Integer> findMinimumPath(int s1, int s2){
System.out.println(s1);
buildDijkstraGraph(s1Handle);
buildDijkstraGraph(s1);
return findPathRev(adjList.get(s1Handle), adjList.get(s2Handle), new ArrayList<Integer>());
return findPathRev(adjList.get(s1), adjList.get(s2), new ArrayList<Integer>());
}
public int getDistance(String end){
......
......@@ -105,7 +105,8 @@ public class Main {
continue;
}
//output findings
System.out.println(adjList.toString());
System.out.println(adjList.outputToString(s1Handle, s2Handle));
boolean validResponse = false;
while (!validResponse) {
......@@ -141,7 +142,8 @@ public class Main {
//main.queryUserPart1();
main.queryUserPart2();
} catch (Exception e) {
System.err.println("Error! - " + e.toString());
System.err.println("Error! - ");
e.printStackTrace();
}
}
}
package test;
public class Test {
public static void main(String[] args){
}
}
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment