diff options
-rw-r--r-- | src/dk.biks.bachelorizer/dk/biks/bachelorizer/Graph.java | 23 |
1 files changed, 13 insertions, 10 deletions
diff --git a/src/dk.biks.bachelorizer/dk/biks/bachelorizer/Graph.java b/src/dk.biks.bachelorizer/dk/biks/bachelorizer/Graph.java index 487e4bf..d052258 100644 --- a/src/dk.biks.bachelorizer/dk/biks/bachelorizer/Graph.java +++ b/src/dk.biks.bachelorizer/dk/biks/bachelorizer/Graph.java @@ -277,33 +277,36 @@ public final class Graph { return h; } - /// groups of disjoint module choices + /// loop through random combinations of sets of modules /// /// @param g sets of disjoint choices as a graph - /// @return amount of students in consecutive slots + /// @return best path out of a hundred shuffles public static int goodSolution(final AbstractGraph g) { - int bestPathCost = Integer.MAX_VALUE; // number higher than total students - for (int i = 0; i < 100; i++) { + // number higher than total students + int bestPathCost = Integer.MAX_VALUE; + for (int i = 0; i < 10000; i++) { int cost = solution(g); if (cost < bestPathCost) { + // store shortest path bestPathCost = cost; } } return bestPathCost; } + /// finds lengh of random path through disjoint module choices + /// + /// @param g sets of disjoint choices as a graph + /// @return weight of final random path private static int solution(final AbstractGraph g) { List<Vertex> path = new ArrayList<>(g.vertices()); - Collections.shuffle(path); // order represents path + // order of list contents becomes path order + Collections.shuffle(path); int cost = 0; for (int i = 0; i < path.size() - 1; i++) { + // get weight between next vertices in module group graph 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 } |