Gather data

This commit is contained in:
mike
2026-01-06 02:57:17 +01:00
parent f031e97a58
commit effb1145d4
4 changed files with 89 additions and 51 deletions

View File

@@ -14,7 +14,6 @@ import java.util.concurrent.*;
import java.util.stream.Collectors;
import static puzzle.SwedishGenerator.*;
import static puzzle.SwedishGenerator.fillMask;
import static puzzle.SwedishGenerator.loadWords;
public class Main {
@@ -41,6 +40,8 @@ public class Main {
public boolean reindex = false;
public int fillTimeout = 20_000;
public boolean verbose = false;
public int W = 9;
public int H = 8;
}
public void main(String[] args) {
@@ -73,13 +74,13 @@ public class Main {
info(String.format(Locale.ROOT, "simplicity : %.2f", res.filled().simplicity()));
section("Mask");
System.out.print(indentLines(gridToString(res.mask()), " "));
System.out.print(indentLines(res.swe().gridToString(res.mask()), " "));
section("Grid (raw)");
System.out.print(indentLines(gridToString(res.filled().grid()), " "));
System.out.print(indentLines(res.swe().gridToString(res.filled().grid()), " "));
section("Grid (human)");
System.out.print(indentLines(renderHuman(res.filled().grid()), " "));
System.out.print(indentLines(res.swe().renderHuman(res.filled().grid()), " "));
var exported = ExportFormat.exportFormatFromFilled(res, 1, new ExportFormat.Rewards(50, 2, 1));
@@ -167,7 +168,7 @@ public class Main {
return s.substring(0, Math.max(0, max - 1)) + "";
}
private static String indentLines(String s, String indent) {
static String indentLines(String s, String indent) {
if (s == null || s.isEmpty()) return "";
var lines = s.split("\\R", -1);
var sb = new StringBuilder();
@@ -245,8 +246,7 @@ public class Main {
section("Search");
var deadline = System.currentTimeMillis() + 40_000;
var deadline = System.currentTimeMillis() + 40_000;
if (opts.threads > 1) {
info("mode : multi-threaded (" + opts.threads + ")");
@@ -258,7 +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(() -> attempt(new Rng(opts.seed + attempt), dict, opts ));
completionService.submit(() -> attempt(new Rng(opts.seed + attempt), dict, opts));
}
while (System.currentTimeMillis() < deadline) {
@@ -274,7 +274,7 @@ public class Main {
// Submit another task if we still have time
if (System.currentTimeMillis() < deadline) {
final int attempt = ++submitted;
completionService.submit(() -> attempt(new Rng(opts.seed + attempt), dict, opts ));
completionService.submit(() -> attempt(new Rng(opts.seed + attempt), dict, opts));
}
}
warn("status : UNSOLVED (timeout)");
@@ -310,12 +310,13 @@ 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);
static PuzzleResult attempt(Rng rng, Dict dict, Opts opts) {
var swe = new SwedishGenerator(opts.W, opts.H);
var mask = swe.generateMask(rng, dict.lenCounts(), opts.pop, opts.gens, opts.verbose);
var filled = swe.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);
return new PuzzleResult(swe, dict, mask, filled);
}
if (opts.verbose && filled.ok()) {