From e960ad9a33782fcd83707a55a135f6eb74435b57 Mon Sep 17 00:00:00 2001
From: Jonas Smedegaard <dr@jones.dk>
Date: Thu, 1 May 2025 19:12:43 +0200
Subject: include disjoint shuffle seed

---
 .../dk/biks/bachelorizer/Graph.java                | 24 ++++++++++++++--------
 1 file changed, 16 insertions(+), 8 deletions(-)

(limited to 'src/dk.biks.bachelorizer')

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]);
 	}
 }
-- 
cgit v1.2.3