Gather data

This commit is contained in:
mike
2026-01-09 21:24:52 +01:00
parent dc331fc96b
commit 95891d9efe
10 changed files with 572 additions and 584 deletions

View File

@@ -14,30 +14,27 @@ import java.util.concurrent.*;
import java.util.concurrent.atomic.AtomicLong;
import java.util.stream.Collectors;
import static puzzle.ExportFormat.*;
import static puzzle.Export.*;
import static puzzle.SwedishGenerator.*;
import static puzzle.SwedishGenerator.loadWords;
public class Main {
// ---------------- Top-level generatePuzzle ----------------
public record PuzzleResult(SwedishGenerator swe, Dict dict, Gridded mask, FillResult filled) { }
final static String OUT_DIR = envOrDefault("OUT_DIR", "/data/puzzle");
final static Path PUZZLE_DIR = Paths.get(OUT_DIR, "puzzles");
static final Path INDEX_FILE = PUZZLE_DIR.resolve("index.json");
static final OffsetDateTime now = OffsetDateTime.now(ZoneOffset.UTC);
static final String CREATED_AT = now.format(DateTimeFormatter.ofPattern("yyyy-MM-dd'T'HH:mm:ss'Z'"));
static final String FILE_ID = CREATED_AT.replace(":", "-") + "_" + System.currentTimeMillis() / 1000;
static final String FILE_NAME = FILE_ID + ".json";
static final Path OUTPUT_PATH = PUZZLE_DIR.resolve(FILE_NAME);
static final String DATE_STRING = now.toLocalDate().toString();
static final AtomicLong TOTAL_NODES = new AtomicLong(0);
static final AtomicLong TOTAL_BACKTRACKS = new AtomicLong(0);
static final AtomicLong TOTAL_ATTEMPTS = new AtomicLong(0);
static final AtomicLong TOTAL_SUCCESS = new AtomicLong(0);
static final AtomicLong TOTAL_SIMPLICITY = new AtomicLong(0); // Scaled by 100 for precision
final static String OUT_DIR = envOrDefault("OUT_DIR", "/data/puzzle");
final static Path PUZZLE_DIR = Paths.get(OUT_DIR, "puzzles");
static final Path INDEX_FILE = PUZZLE_DIR.resolve("index.json");
static final OffsetDateTime now = OffsetDateTime.now(ZoneOffset.UTC);
static final String CREATED_AT = now.format(DateTimeFormatter.ofPattern("yyyy-MM-dd'T'HH:mm:ss'Z'"));
static final String FILE_ID = CREATED_AT.replace(":", "-") + "_" + System.currentTimeMillis() / 1000;
static final String FILE_NAME = FILE_ID + ".json";
static final Path OUTPUT_PATH = PUZZLE_DIR.resolve(FILE_NAME);
static final String DATE_STRING = now.toLocalDate().toString();
static final boolean VERBOSE = false;
static final AtomicLong TOTAL_NODES = new AtomicLong(0);
static final AtomicLong TOTAL_BACKTRACKS = new AtomicLong(0);
static final AtomicLong TOTAL_ATTEMPTS = new AtomicLong(0);
static final AtomicLong TOTAL_SUCCESS = new AtomicLong(0);
static final AtomicLong TOTAL_SIMPLICITY = new AtomicLong(0); // Scaled by 100 for precision
@Data
public static class Opts {
@@ -52,6 +49,7 @@ public class Main {
public boolean reindex = false;
public int fillTimeout = 20_000;
public boolean verbose = false;
}
public void main(String[] args) {
@@ -92,7 +90,7 @@ public class Main {
section("Grid (human)");
System.out.print(indentLines(res.filled().grid().renderHuman(), " "));
var exported = exportFormatFromFilled(res, 1, new Rewards(50, 2, 1));
var exported = res.exportFormatFromFilled(1, new Rewards(50, 2, 1));
section("Clues");
info("status : generating...");
@@ -233,8 +231,6 @@ public class Main {
i++;
} else if (a.equals("--reindex")) {
out.reindex = true;
} else if (a.equals("--verbose")) {
out.verbose = true;
} else {
throw new IllegalArgumentException("Unknown arg: " + a);
}
@@ -344,8 +340,8 @@ public class Main {
static PuzzleResult attempt(Rng rng, Dict dict, Opts opts) {
TOTAL_ATTEMPTS.incrementAndGet();
var swe = new SwedishGenerator();
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);
var mask = swe.generateMask(rng, dict.lenCounts(), opts.pop, opts.gens);
var filled = new CSP(rng).fillMask(mask, dict.index(), 200, opts.fillTimeout);
TOTAL_NODES.addAndGet(filled.stats().nodes);
TOTAL_BACKTRACKS.addAndGet(filled.stats().backtracks);
@@ -399,7 +395,7 @@ public class Main {
sb.append(" ],\n");
sb.append(" \"words\": [\n");
for (var i = 0; i < puzzle.words().length; i++) {
var w = puzzle.words()[i];
var w = puzzle.words()[i];
sb.append(" {\n");
sb.append(" \"word\": \"").append(escapeJson(w.word())).append("\",\n");
sb.append(" \"clue\": [").append(Arrays.stream(w.clue()).map(ss -> "\"" + escapeJson(ss) + "\"").collect(Collectors.joining(","))).append("],\n");