Fix GraphAlgorithm (hopefully)

This commit is contained in:
joachimschmidt557 2019-03-25 19:07:35 +01:00
parent d071187c79
commit c331208620
3 changed files with 98 additions and 17 deletions

View file

@ -15,7 +15,7 @@ public class GraphAlgoComplexityTest {
@Test
public void test() {
for (int i = 1; i < 1000; i+=10) {
for (int i = 30; i < 50; i+=1) {
Graph<Integer> g = generateGraph(i);
DumbGraphAlgorithm ga = new DumbGraphAlgorithm(g, g.getNodes().get(0));
@ -27,6 +27,19 @@ public class GraphAlgoComplexityTest {
double divN3 = (double)ga.getN() / ((double)i*i*i);
System.out.println(i + "," + ga.getN() + "," + divN + "," + divN2 + "," + divN3);
/////////////
Graph<Integer> g2 = generateGraph2(i);
DumbGraphAlgorithm ga2 = new DumbGraphAlgorithm(g2, g2.getNodes().get(4));
ga2.run();
List<Edge<Integer>> path = ga2.getPath(g2.getNodes().get(12));
for (Edge<Integer> edge : path) {
System.out.println(edge.getNodeA().getValue().toString() + " " + edge.getNodeB().getValue().toString());
}
//System.out.println();
}
@ -53,6 +66,23 @@ public class GraphAlgoComplexityTest {
}
public Graph<Integer> generateGraph2(int n) {
Graph<Integer> g = new Graph<Integer>();
List<Node<Integer>> nodes = new ArrayList<>();
for (int i = 0; i < n; i++)
nodes.add(g.addNode(i));
for (int i = 0; i < n - 1; i++) {
g.addEdge(nodes.get(i), nodes.get(i+1));
}
return g;
}
public class DumbGraphAlgorithm extends GraphAlgorithm<Integer> {
public DumbGraphAlgorithm(Graph<Integer> graph, Node<Integer> sourceNode) {