aboutsummaryrefslogtreecommitdiff
path: root/src/dk.biks.bachelorizer/dk/biks/bachelorizer
diff options
context:
space:
mode:
authorIan Valentin Christensen <valentianchristensen@gmail.com>2025-04-29 14:28:15 +0200
committerIan Valentin Christensen <valentianchristensen@gmail.com>2025-04-29 14:28:15 +0200
commitfda1a0cf47f225211c34f2700fbd2fee119245a9 (patch)
tree9ab4d4a8fe60ccc5e548f227c8041e0e6bf45b1e /src/dk.biks.bachelorizer/dk/biks/bachelorizer
parentc8b9a67ac13d4cfc468aad28ef062fc64a72e2f6 (diff)
fix conflict
Diffstat (limited to 'src/dk.biks.bachelorizer/dk/biks/bachelorizer')
-rw-r--r--src/dk.biks.bachelorizer/dk/biks/bachelorizer/Graph.java28
1 files changed, 25 insertions, 3 deletions
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<Vertex> 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<Vertex> 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