Gather data

This commit is contained in:
mike
2026-01-06 02:22:26 +01:00
parent 42a69235d2
commit f031e97a58
5 changed files with 143 additions and 164 deletions

View File

@@ -13,8 +13,8 @@ import java.util.*;
import java.util.concurrent.*;
import java.util.stream.Collectors;
import static puzzle.SwedishGenerator.*;
import static puzzle.SwedishGenerator.fillMask;
import static puzzle.SwedishGenerator.generateMask;
import static puzzle.SwedishGenerator.loadWords;
public class Main {
@@ -39,6 +39,8 @@ public class Main {
public int threads = Math.max(1, Runtime.getRuntime().availableProcessors());
public int tries = threads;
public boolean reindex = false;
public int fillTimeout = 20_000;
public boolean verbose = false;
}
public void main(String[] args) {
@@ -68,16 +70,16 @@ public class Main {
}
section("Result");
info(String.format(Locale.ROOT, "simplicity : %.2f", res.filled().simplicity));
info(String.format(Locale.ROOT, "simplicity : %.2f", res.filled().simplicity()));
section("Mask");
System.out.print(indentLines(SwedishGenerator.gridToString(res.mask()), " "));
System.out.print(indentLines(gridToString(res.mask()), " "));
section("Grid (raw)");
System.out.print(indentLines(SwedishGenerator.gridToString(res.filled().grid), " "));
System.out.print(indentLines(gridToString(res.filled().grid()), " "));
section("Grid (human)");
System.out.print(indentLines(SwedishGenerator.renderHuman(res.filled().grid), " "));
System.out.print(indentLines(renderHuman(res.filled().grid()), " "));
var exported = ExportFormat.exportFormatFromFilled(res, 1, new ExportFormat.Rewards(50, 2, 1));
@@ -238,13 +240,13 @@ public class Main {
var tLoad1 = System.nanoTime();
section("Load");
info(String.format(Locale.ROOT, "words : %,d", dict.words().size()));
info(String.format(Locale.ROOT, "words : %,d", dict.wordz().length));
info(String.format(Locale.ROOT, "loadTime : %.3f s", (tLoad1 - tLoad0) / 1e9));
section("Search");
var deadline = System.currentTimeMillis() + 40_000;
var fillTimeout = 20_000;
if (opts.threads > 1) {
info("mode : multi-threaded (" + opts.threads + ")");
@@ -256,16 +258,7 @@ public class Main {
// Keep at least some tasks in flight
for (int i = 0; i < opts.threads; i++) {
final int attempt = ++submitted;
completionService.submit(() -> {
var threadRng = new Rng(opts.seed + attempt);
var mask = generateMask(threadRng, dict.lenCounts(), opts.pop, opts.gens, false);
var filled = fillMask(threadRng, mask, dict.index(), 200, fillTimeout, false);
if (filled.ok && (opts.minSimplicity <= 0 || filled.simplicity >= opts.minSimplicity)) {
return new PuzzleResult(dict, mask, filled);
}
return null;
});
completionService.submit(() -> attempt(new Rng(opts.seed + attempt), dict, opts ));
}
while (System.currentTimeMillis() < deadline) {
@@ -281,16 +274,7 @@ public class Main {
// Submit another task if we still have time
if (System.currentTimeMillis() < deadline) {
final int attempt = ++submitted;
completionService.submit(() -> {
var threadRng = new Rng(opts.seed + attempt);
var mask = generateMask(threadRng, dict.lenCounts(), opts.pop, opts.gens, false);
var filled = fillMask(threadRng, mask, dict.index(), 200, fillTimeout, false);
if (filled.ok && (opts.minSimplicity <= 0 || filled.simplicity >= opts.minSimplicity)) {
return new PuzzleResult(dict, mask, filled);
}
return null;
});
completionService.submit(() -> attempt(new Rng(opts.seed + attempt), dict, opts ));
}
}
warn("status : UNSOLVED (timeout)");
@@ -313,20 +297,11 @@ public class Main {
attempt++;
info("try : " + attempt + " (remaining: " + (deadline - System.currentTimeMillis()) / 1000 + "s)");
var mask = generateMask(rng, dict.lenCounts(), opts.pop, opts.gens, true);
var filled = fillMask(rng, mask, dict.index(), 200, fillTimeout, true);
if (filled.ok && (opts.minSimplicity <= 0 || filled.simplicity >= opts.minSimplicity)) {
var result = attempt(rng, dict, opts);
if (result != null) {
info("status : SOLVED");
info("foundAtTry : " + attempt);
return new PuzzleResult(dict, mask, filled);
}
if (filled.ok) {
warn(String.format(Locale.ROOT,
"simplicity : %.2f (below min %.2f)",
filled.simplicity, opts.minSimplicity
));
return result;
}
}
@@ -335,6 +310,23 @@ public class Main {
}
}
static PuzzleResult attempt(Rng rng, Dict dict, Opts opts ) {
var mask = SwedishGenerator.generateMask(rng, dict.lenCounts(), opts.pop, opts.gens, opts.verbose);
var filled = fillMask(rng, mask, dict.index(), 200, opts.fillTimeout, opts.verbose);
if (filled.ok() && (opts.minSimplicity <= 0 || filled.simplicity() >= opts.minSimplicity)) {
return new PuzzleResult(dict, mask, filled);
}
if (opts.verbose && filled.ok()) {
System.err.printf(Locale.ROOT,
"simplicity : %.2f (below min %.2f)%n",
filled.simplicity(), opts.minSimplicity
);
}
return null;
}
// ---------------- Export (unchanged logic) ----------------
private static String toJson(ExportFormat.ExportedPuzzle puzzle, String date, String theme) {