From fda1a0cf47f225211c34f2700fbd2fee119245a9 Mon Sep 17 00:00:00 2001 From: Ian Valentin Christensen Date: Tue, 29 Apr 2025 14:28:15 +0200 Subject: fix conflict --- .../dk/biks/bachelorizer/Graph.java | 28 +++++++++++++++++++--- 1 file changed, 25 insertions(+), 3 deletions(-) (limited to 'src') diff --git a/src/dk.biks.bachelorizer/dk/biks/bachelorizer/Graph.java b/src/dk.biks.bachelorizer/dk/biks/bachelorizer/Graph.java index 8c528fa..1048fb4 100644 --- a/src/dk.biks.bachelorizer/dk/biks/bachelorizer/Graph.java +++ b/src/dk.biks.bachelorizer/dk/biks/bachelorizer/Graph.java @@ -262,13 +262,17 @@ public final class Graph { } } } + // ensure h is treated as undirected h.insertEdge( groupLabel.get(s), groupLabel.get(t), sum); + h.insertEdge( + groupLabel.get(t), + groupLabel.get(s), + sum); } } - return h; } @@ -277,11 +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 vertices = new ArrayList<>(g.vertices()); + 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); + if (cost < bestPathCost) { + bestPathCost = cost; + } + } + return bestPathCost; // pick a random vertice in the graph - Vertex v = g.vertices().iterator().next(); + // Vertex v = g.vertices().iterator().next(); - return solution(g, v); + // return solution(g, path); + } + + private static int pathCost(AbstractGraph g, List 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 -- cgit v1.2.3