aboutsummaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authorIan Valentin Christensen <valentianchristensen@gmail.com>2025-04-29 15:09:26 +0200
committerIan Valentin Christensen <valentianchristensen@gmail.com>2025-04-29 15:09:39 +0200
commitc5efbd6ce076ee0dfaf507ce5bc6aa79c8872432 (patch)
treed34e1984ed364e147210a617331f598b9cdb8b0b /src
parentb14f67259c933e8a0af5027ae20bc4ab90113c7b (diff)
restructure solution function
Diffstat (limited to 'src')
-rw-r--r--src/dk.biks.bachelorizer/dk/biks/bachelorizer/Graph.java30
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));
- }
}