aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorJonas Smedegaard <dr@jones.dk>2025-05-01 19:12:43 +0200
committerJonas Smedegaard <dr@jones.dk>2025-05-01 19:12:43 +0200
commite960ad9a33782fcd83707a55a135f6eb74435b57 (patch)
treedbbab0086cbf0356cb23332c195500b4c066defd
parent89a5acad8deef14be01a5ccfba3d036d94e8a6d4 (diff)
include disjoint shuffle seed
-rw-r--r--src/dk.biks.bachelorizer/dk/biks/bachelorizer/Graph.java24
1 files changed, 16 insertions, 8 deletions
diff --git a/src/dk.biks.bachelorizer/dk/biks/bachelorizer/Graph.java b/src/dk.biks.bachelorizer/dk/biks/bachelorizer/Graph.java
index 2d36d14..f8bafcd 100644
--- a/src/dk.biks.bachelorizer/dk/biks/bachelorizer/Graph.java
+++ b/src/dk.biks.bachelorizer/dk/biks/bachelorizer/Graph.java
@@ -11,6 +11,7 @@ import java.util.HashSet;
import java.util.HashMap;
import java.util.Map;
import java.util.List;
+import java.util.Random;
import java.util.Set;
import java.util.stream.Collectors;
@@ -127,7 +128,11 @@ public final class Graph extends Storage {
//
// TODO: optionally seed this, to enable ranking control
List<Vertex> modules = new ArrayList<>(g.vertices());
- Collections.shuffle(modules);
+ long seed = System.currentTimeMillis();
+ Random random = new Random(seed);
+ System.out.println(
+ "Seed used for shuffling modules: " + seed);
+ Collections.shuffle(modules, random);
return disjoint(modules);
}
@@ -265,16 +270,18 @@ public final class Graph extends Storage {
/// find total weight of random path through disjoint choice sets
///
/// @param g sets of disjoint choices as a graph
- /// @return total weight of random path
+ /// @return total weight of random path and its seed as array
private static long[] solve(final AbstractGraph g) {
/// parameters for solution
- long[] solution = new long[] {0};
+ long[] solution = new long[] {0, 0};
List<Vertex> path = new ArrayList<>(g.vertices());
+ solution[1] = System.currentTimeMillis();
+ Random random = new Random(solution[1]);
// order of list contents becomes path order
- Collections.shuffle(path);
+ Collections.shuffle(path, random);
for (int i = 0; i < path.size() - 1; i++) {
solution[0] += g.getWeight(
@@ -318,9 +325,10 @@ public final class Graph extends Storage {
GraphAlgorithms.printGraph(h);
// find path through disjoint choice graph
- System.out.print(
- "\n\nSolution with disjoint choices found: ");
- System.out.println(
- solveManyTimes(h)[0]);
+ long[] solution = solveManyTimes(h);
+ System.out.printf(
+ "\n\nSolution with disjoint choices found: "
+ + "%d (disjoint shuffle seed: %d)%n",
+ solution[0], solution[1]);
}
}