introduce bitloops
This commit is contained in:
@@ -44,16 +44,16 @@ public class Main {
|
||||
public static class Opts {
|
||||
|
||||
public int seed = (int) (System.nanoTime() ^ System.currentTimeMillis());
|
||||
public int clueSize = 24;
|
||||
public int clueSize = 20;
|
||||
public int pop = 40;
|
||||
public int offspring = 60;
|
||||
public int gens = 700;
|
||||
public int gens = 500;
|
||||
public String wordsPath = "nl_score_hints_v3.csv";
|
||||
public double minSimplicity = 0; // 0 means no limit
|
||||
public int threads = Math.max(1, Runtime.getRuntime().availableProcessors());
|
||||
public int tries = threads;
|
||||
public boolean reindex = false;
|
||||
public boolean verbose = false;
|
||||
public boolean verbose = true;
|
||||
|
||||
}
|
||||
|
||||
@@ -206,7 +206,7 @@ public class Main {
|
||||
--clues 18
|
||||
--pop 40
|
||||
--offspring 60
|
||||
--gens 700
|
||||
--gens 500
|
||||
--words nl_score_hints.csv
|
||||
--min-simplicity 0 (no limit)
|
||||
--threads %d
|
||||
@@ -286,9 +286,10 @@ public class Main {
|
||||
|
||||
try {
|
||||
// Keep at least some tasks in flight
|
||||
final var service = CsvIndexService.SC.get();
|
||||
for (int i = 0; i < opts.threads; i++) {
|
||||
final int attempt = ++submitted;
|
||||
completionService.submit(() -> attempt(new Rng(opts.seed + attempt), dict, opts));
|
||||
final int attemptIdx = ++submitted;
|
||||
completionService.submit(() -> ScopedValue.where(CsvIndexService.SC, service).call(() -> attempt(new Rng(opts.seed + attemptIdx), dict, opts)));
|
||||
}
|
||||
|
||||
while (System.currentTimeMillis() < deadline) {
|
||||
@@ -304,8 +305,8 @@ 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));
|
||||
final int attemptIdx = ++submitted;
|
||||
completionService.submit(() -> ScopedValue.where(CsvIndexService.SC, service).call(() -> attempt(new Rng(opts.seed + attemptIdx), dict, opts)));
|
||||
}
|
||||
}
|
||||
if (resFinal == null) warn("status : UNSOLVED (timeout)");
|
||||
@@ -316,6 +317,11 @@ public class Main {
|
||||
warn("status : ERROR (" + e.getMessage() + ")");
|
||||
} finally {
|
||||
executor.shutdownNow();
|
||||
try {
|
||||
executor.awaitTermination(5, TimeUnit.SECONDS);
|
||||
} catch (InterruptedException e) {
|
||||
Thread.currentThread().interrupt();
|
||||
}
|
||||
}
|
||||
|
||||
} else {
|
||||
@@ -369,9 +375,11 @@ public class Main {
|
||||
}
|
||||
}
|
||||
static PuzzleResult _attempt(Rng rng, Dict dict, Opts opts) {
|
||||
long t0 = System.currentTimeMillis();
|
||||
TOTAL_ATTEMPTS.incrementAndGet();
|
||||
var swe = new SwedishGenerator(rng, new int[STACK_SIZE], Clues.createEmpty());
|
||||
var mask = swe.generateMask(opts.clueSize, opts.pop, opts.gens, Math.max(opts.offspring, (int) Math.floor(1.5 * opts.pop)));
|
||||
var mask = swe.generateMask(opts.clueSize, opts.pop, opts.gens, opts.offspring);
|
||||
if (mask == null) return null;
|
||||
|
||||
var filled = fillMask(rng, extractSlots(mask, dict.index()), mask.toGrid());
|
||||
|
||||
@@ -387,10 +395,11 @@ public class Main {
|
||||
var status = filled.ok() ? "SUCCESS" : "FAILED";
|
||||
var simplicity = String.format(Locale.ROOT, "%.2f", filled.stats().simplicity);
|
||||
var nps = (int) (filled.stats().nodes / Math.max(0.001, filled.stats().seconds));
|
||||
var totalTime = (System.currentTimeMillis() - t0) / 1000.0;
|
||||
|
||||
System.out.printf(Locale.ROOT,
|
||||
"[ATTEMPT] thread=%s | status=%s | nodes=%d | backtracks=%d | nps=%d | simplicity=%s | time=%.1fs%n",
|
||||
name, status, filled.stats().nodes, filled.stats().backtracks, nps, simplicity, filled.stats().seconds
|
||||
name, status, filled.stats().nodes, filled.stats().backtracks, nps, simplicity, totalTime
|
||||
);
|
||||
|
||||
if (filled.ok() && (opts.minSimplicity <= 0 || filled.stats().simplicity >= opts.minSimplicity)) {
|
||||
|
||||
Reference in New Issue
Block a user