diff options
Diffstat (limited to 'src/dk.biks.bachelorizer/dk/biks/bachelorizer/Graph.java')
-rw-r--r-- | src/dk.biks.bachelorizer/dk/biks/bachelorizer/Graph.java | 30 |
1 files changed, 9 insertions, 21 deletions
diff --git a/src/dk.biks.bachelorizer/dk/biks/bachelorizer/Graph.java b/src/dk.biks.bachelorizer/dk/biks/bachelorizer/Graph.java index bae011e..487e4bf 100644 --- a/src/dk.biks.bachelorizer/dk/biks/bachelorizer/Graph.java +++ b/src/dk.biks.bachelorizer/dk/biks/bachelorizer/Graph.java @@ -88,10 +88,10 @@ public final class Graph { GraphAlgorithms.printGraph(h); // find path through disjoint choice graph + System.out.print( + "\n\nSolution with disjoint choices found: "); System.out.println( - "\n\nSolution with disjoint choices found:"); - System.out.println( - solution(h)); + goodSolution(h)); // release temporary variables for garbage collection _g = null; @@ -281,41 +281,29 @@ public final class Graph { /// /// @param g sets of disjoint choices as a graph /// @return amount of students in consecutive slots - public static int solution(final AbstractGraph g) { - List<Vertex> vertices = new ArrayList<>(g.vertices()); + public static int goodSolution(final AbstractGraph g) { int bestPathCost = Integer.MAX_VALUE; // number higher than total students for (int i = 0; i < 100; i++) { - Collections.shuffle(vertices); // order represents path - int cost = pathCost(g, vertices); + int cost = solution(g); if (cost < bestPathCost) { bestPathCost = cost; - } } - return bestPathCost; - // pick a random vertice in the graph - // Vertex v = g.vertices().iterator().next(); - - // return solution(g, path); + return bestPathCost; } - private static int pathCost(AbstractGraph g, List<Vertex> path) { + private static int solution(final AbstractGraph g) { + List<Vertex> path = new ArrayList<>(g.vertices()); + Collections.shuffle(path); // order represents path int cost = 0; for (int i = 0; i < path.size() - 1; i++) { cost += g.getWeight(path.get(i), path.get(i + 1)); } return cost; } - /// groups of disjoint module choices seeded by start vertex /// /// @param g groups of disjoint choices as a graph /// @param v seed vertex within graph /// @return amount of students in consecutive slots - public static int solution( - final AbstractGraph g, final Vertex v - ) { - return GraphAlgorithms.pathLength( - GraphAlgorithms.dijkstra(g, v)); - } } |