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

progress

parent d7a68ee3
...@@ -2,5 +2,8 @@ ...@@ -2,5 +2,8 @@
<classpath> <classpath>
<classpathentry kind="src" path="src"/> <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="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"/> <classpathentry kind="output" path="bin"/>
</classpath> </classpath>
...@@ -101,7 +101,7 @@ public class AdjacencyList { ...@@ -101,7 +101,7 @@ public class AdjacencyList {
} }
private void buildDijkstraGraph(int startingVertex){ private void buildDijkstraGraph(int startingVertex){
Vertex start = getVertexFromHandle(startingVertex); Vertex start = adjList.get(startingVertex);
//Initialize graph //Initialize graph
Vertex temp; Vertex temp;
for(int i = 0; i < adjList.size(); i++){ for(int i = 0; i < adjList.size(); i++){
...@@ -138,7 +138,7 @@ public class AdjacencyList { ...@@ -138,7 +138,7 @@ public class AdjacencyList {
} }
private ArrayList<Integer> findPathRev(Vertex start, Vertex end, ArrayList<Integer> path){ private ArrayList<Integer> findPathRev(Vertex start, Vertex end, ArrayList<Integer> path){
if(end.getPred() == -1) if(end.equals(start))
return path; return path;
Vertex next = adjList.get(end.getPred()); Vertex next = adjList.get(end.getPred());
path.add(next.getAdjListIndex()); path.add(next.getAdjListIndex());
...@@ -146,23 +146,29 @@ public class AdjacencyList { ...@@ -146,23 +146,29 @@ public class AdjacencyList {
return findPathRev(start, next, path); return findPathRev(start, next, path);
} }
public String printPath(ArrayList<Integer> reversedPath){ private String pathToString(ArrayList<Integer> reversedPath){
StringBuffer out = new StringBuffer(); StringBuffer out = new StringBuffer();
for (int i = reversedPath.size() - 1; i >= 0; i--){ for (int i = reversedPath.size() - 1; i >= 0; i--){
out.append(" " + adjList.get(reversedPath.get(i))); out.append(" " + adjList.get(reversedPath.get(i)));
if((reversedPath.size() - i) % 10 == 0)
out.append("\n");
} }
return out.toString(); return out.toString();
} }
public ArrayList<Integer> findMinimumPath(String s1, String s2){ public String outputToString(int s1, int s2){
int s1Handle = findStringHandle(s1); ArrayList<Integer> revPath = findMinimumPath(s1,s2);
int s2Handle = findStringHandle(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){ public int getDistance(String end){
......
...@@ -105,7 +105,8 @@ public class Main { ...@@ -105,7 +105,8 @@ public class Main {
continue; continue;
} }
//output findings System.out.println(adjList.toString());
System.out.println(adjList.outputToString(s1Handle, s2Handle));
boolean validResponse = false; boolean validResponse = false;
while (!validResponse) { while (!validResponse) {
...@@ -141,7 +142,8 @@ public class Main { ...@@ -141,7 +142,8 @@ public class Main {
//main.queryUserPart1(); //main.queryUserPart1();
main.queryUserPart2(); main.queryUserPart2();
} catch (Exception e) { } 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