introduce bitloops
This commit is contained in:
@@ -2,6 +2,7 @@ package puzzle;
|
||||
|
||||
import lombok.AllArgsConstructor;
|
||||
import lombok.Getter;
|
||||
import lombok.NoArgsConstructor;
|
||||
import lombok.RequiredArgsConstructor;
|
||||
import lombok.experimental.Accessors;
|
||||
import lombok.experimental.Delegate;
|
||||
@@ -129,24 +130,19 @@ public record SwedishGenerator(Rng rng, int[] stack, Clues cache) {
|
||||
|
||||
public static record FillResult(boolean ok,
|
||||
Gridded grid,
|
||||
long[] clueMap,
|
||||
@Delegate FillStats stats) {
|
||||
|
||||
public void calcSimpel() {
|
||||
if (ok) {
|
||||
int k = 0;
|
||||
for (var n = 1; n < clueMap.length; n++) {
|
||||
if (clueMap[n] != X) {
|
||||
k++;
|
||||
stats.simplicity += Lemma.simpel(clueMap[n]);
|
||||
}
|
||||
static public long calcSimpel(Slotinfo[] slots) {
|
||||
int k = 0;
|
||||
long simpel = 0L;
|
||||
for (var n = 1; n < slots.length; n++) {
|
||||
if (slots[n].assign().w != X) {
|
||||
k++;
|
||||
simpel += Lemma.simpel(slots[n].assign().w);
|
||||
}
|
||||
stats.simplicity = k == 0 ? 0 : stats.simplicity / k;
|
||||
}
|
||||
}
|
||||
public int wordCount(int k) {
|
||||
for (var n = 1; n < clueMap.length; n++) if (clueMap[n] != X) k++;
|
||||
return k;
|
||||
simpel = k == 0 ? 0 : simpel / k;
|
||||
return simpel;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -335,12 +331,20 @@ public record SwedishGenerator(Rng rng, int[] stack, Clues cache) {
|
||||
}
|
||||
}
|
||||
|
||||
@AllArgsConstructor
|
||||
@NoArgsConstructor
|
||||
static class Assign {
|
||||
|
||||
long w;
|
||||
}
|
||||
|
||||
static record Slotinfo(int key, long lo, long hi, int score, Assign assign, DictEntry entry) { }
|
||||
static record Slotinfo(int key, long lo, long hi, int score, Assign assign, DictEntry entry) {
|
||||
|
||||
public static int wordCount(int k, Slotinfo[] arr) {
|
||||
for (var n = 1; n < arr.length; n++) if (arr[n].assign.w != X) k++;
|
||||
return k;
|
||||
}
|
||||
}
|
||||
|
||||
static record Slot(int key, long lo, long hi, DictEntry entry) {
|
||||
|
||||
@@ -849,6 +853,7 @@ public record SwedishGenerator(Rng rng, int[] stack, Clues cache) {
|
||||
return true;
|
||||
}
|
||||
|
||||
/// pattern cannot be X
|
||||
static int[] candidateInfoForPattern(long[] res, long pattern, long[][] posBitsets, int numLongs) {
|
||||
System.arraycopy(posBitsets[(int) (pattern & 0xFF) - 1], 0, res, 0, numLongs);
|
||||
for (long p = pattern >>> 8; p != X; p >>>= 8) {
|
||||
@@ -870,7 +875,7 @@ public record SwedishGenerator(Rng rng, int[] stack, Clues cache) {
|
||||
|
||||
return indices;
|
||||
}
|
||||
|
||||
/// pattern cannot be X
|
||||
static int candidateCountForPattern(final long[] res, final long pattern, final long[][] posBitsets, final int numLongs) {
|
||||
System.arraycopy(posBitsets[(int) (pattern & 0xFF) - 1], 0, res, 0, numLongs);
|
||||
for (long p = pattern >>> 8; p != X; p >>>= 8) {
|
||||
@@ -1093,9 +1098,7 @@ public record SwedishGenerator(Rng rng, int[] stack, Clues cache) {
|
||||
// final progress line
|
||||
grid.lo = solver.glo;
|
||||
grid.hi = solver.ghi;
|
||||
val assigned = new long[CLUE_INDEX_MAX_SIZE];
|
||||
Arrays.stream(slots).forEach(s -> assigned[s.key] = s.assign.w);
|
||||
var res = new FillResult(ok, new Gridded(grid), assigned,
|
||||
var res = new FillResult(ok, new Gridded(grid),
|
||||
new FillStats(solver.nodes, solver.backtracks, (System.currentTimeMillis() - t0) / 1000.0, solver.lastMRV));
|
||||
if (!multiThreaded) {
|
||||
System.out.print("\r" + Strings.padRight("", 120) + "\r");
|
||||
@@ -1106,7 +1109,7 @@ public record SwedishGenerator(Rng rng, int[] stack, Clues cache) {
|
||||
System.out.println(
|
||||
String.format(Locale.ROOT,
|
||||
"[######################] %d/%d slots | nodes=%d | backtracks=%d | mrv=%d | %.1fs",
|
||||
res.wordCount(0), TOTAL, res.nodes(), res.backtracks(), res.lastMRV(), res.seconds()
|
||||
Slotinfo.wordCount(0, slots), TOTAL, res.nodes(), res.backtracks(), res.lastMRV(), res.seconds()
|
||||
)
|
||||
);
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user