introduce bitloops
This commit is contained in:
@@ -1,24 +1,22 @@
|
||||
package puzzle;
|
||||
|
||||
import lombok.val;
|
||||
import org.junit.jupiter.api.Disabled;
|
||||
import org.junit.jupiter.api.Test;
|
||||
import puzzle.Export.Clued;
|
||||
import puzzle.Export.Gridded;
|
||||
import puzzle.SwedishGenerator.DictEntry;
|
||||
import puzzle.SwedishGenerator.Rng;
|
||||
import puzzle.SwedishGenerator.Slotinfo;
|
||||
import puzzle.SwedishGenerator.Grid;
|
||||
|
||||
import java.util.Arrays;
|
||||
import java.util.Comparator;
|
||||
import java.util.Locale;
|
||||
import java.util.stream.IntStream;
|
||||
|
||||
import static org.junit.jupiter.api.Assertions.assertTrue;
|
||||
import static puzzle.SwedishGenerator.fillMask;
|
||||
|
||||
public class PerformanceTest {
|
||||
|
||||
final DictEntry[] EN = DictData.DICT.index();
|
||||
final DictEntry[] EN = DictData.DICT.index();
|
||||
@Test
|
||||
void testPerformance() {
|
||||
val rng = new Rng(42);
|
||||
@@ -45,7 +43,6 @@ public class PerformanceTest {
|
||||
val mask = masker.generateMask(size, 100, 50, 20);
|
||||
|
||||
val slotInfo = Masker.slots(mask, EN);
|
||||
val grid = mask.toGrid();
|
||||
|
||||
long t0 = System.currentTimeMillis();
|
||||
// Try to fill multiple times to get a better average
|
||||
@@ -54,7 +51,7 @@ public class PerformanceTest {
|
||||
long totalBacktracks = 0;
|
||||
int successCount = 0;
|
||||
for (int i = 0; i < iterations; i++) {
|
||||
val result = fillMask(rng, slotInfo, grid.copy(), false);
|
||||
val result = fillMask(rng, slotInfo, Slotinfo.grid(slotInfo));
|
||||
if (result.ok()) successCount++;
|
||||
totalNodes += result.nodes();
|
||||
totalBacktracks += result.backtracks();
|
||||
@@ -66,7 +63,7 @@ public class PerformanceTest {
|
||||
size, successCount, iterations, totalNodes / iterations, totalBacktracks / iterations, totalDuration);
|
||||
}
|
||||
}
|
||||
void main() {
|
||||
void main() {
|
||||
testIncrementalComplexity();
|
||||
}
|
||||
@Test
|
||||
@@ -81,7 +78,7 @@ public class PerformanceTest {
|
||||
" 2 1 \n" +
|
||||
" 1 \n" +
|
||||
"221 22\n";
|
||||
val mask = Masker.Clues.parse(maskStr);
|
||||
val mask = Clued.parse(maskStr);
|
||||
val allSlots = Masker.slots(mask.c(), EN);
|
||||
//mask.toGrid()
|
||||
System.out.println("[DEBUG_LOG] \n--- Incremental Complexity Test ---");
|
||||
@@ -90,11 +87,11 @@ public class PerformanceTest {
|
||||
|
||||
for (int i = 10; i <= allSlots.length; i++) {
|
||||
val subset = Arrays.copyOf(allSlots, i);
|
||||
// Arrays.sort(subset, Comparator.comparingInt(Slotinfo::score));
|
||||
// Arrays.sort(subset, Comparator.comparingInt(Slotinfo::score));
|
||||
System.out.printf("[DEBUG_LOG] Testing with first %d slots%n of %s", i, allSlots.length);
|
||||
var grid = Slotinfo.grid(subset);
|
||||
visualizeSlots(subset);
|
||||
measureFill(new Rng(123 + i), subset, grid, "Subset size " + i);
|
||||
measureFill(new Rng(123 + i), subset, "Subset size " + i);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -103,18 +100,18 @@ public class PerformanceTest {
|
||||
val rng = new Rng(42);
|
||||
|
||||
// A single horizontal slot at (0,0)
|
||||
val mask = Masker.Clues.parse("1 \n");
|
||||
val mask = Clued.parse("1 \n");
|
||||
val slots = Masker.slots(mask.c(), EN);
|
||||
|
||||
System.out.println("[DEBUG_LOG] \n--- Single Slot Resolution ---");
|
||||
if (slots.length > 0) {
|
||||
measureFill(rng, slots, mask.toGrid(), "Single Slot");
|
||||
measureFill(rng, slots, "Single Slot");
|
||||
} else {
|
||||
System.out.println("[DEBUG_LOG] Error: No slots found in mask.");
|
||||
}
|
||||
}
|
||||
|
||||
private void measureFill(Rng rng, Slotinfo[] slots, Grid grid, String label) {
|
||||
private void measureFill(Rng rng, Slotinfo[] slots, String label) {
|
||||
long t0 = System.currentTimeMillis();
|
||||
int iterations = 1;
|
||||
long totalNodes = 0;
|
||||
@@ -125,7 +122,7 @@ public class PerformanceTest {
|
||||
// Reset assignments for each iteration
|
||||
for (Slotinfo s : slots) s.assign().w = 0;
|
||||
|
||||
val result = fillMask(rng, slots, grid.copy(), false);
|
||||
val result = fillMask(rng, slots, Slotinfo.grid(slots));
|
||||
if (result.ok()) successCount++;
|
||||
totalNodes += result.nodes();
|
||||
totalBacktracks += result.backtracks();
|
||||
@@ -148,8 +145,8 @@ public class PerformanceTest {
|
||||
int dir = Masker.Slot.dir(key);
|
||||
int clueIdx = Masker.Slot.clueIndex(key);
|
||||
|
||||
int cr = SwedishGenerator.IT[clueIdx].r();
|
||||
int cc = SwedishGenerator.IT[clueIdx].c();
|
||||
int cr = Masker.IT[clueIdx].r();
|
||||
int cc = Masker.IT[clueIdx].c();
|
||||
|
||||
// User requested: aAAAA for a four letter to RIGHT clue slot.
|
||||
// SwedishGenerator: 1=RIGHT, 0=DOWN, 2=UP, 3=LEFT
|
||||
@@ -179,9 +176,9 @@ public class PerformanceTest {
|
||||
|
||||
display[cr][cc] = clueChar;
|
||||
|
||||
Masker.Slot.from(slot.key(), slot.lo(), slot.hi(), null).walk().forEach(idx -> {
|
||||
int r = SwedishGenerator.IT[idx].r();
|
||||
int c = SwedishGenerator.IT[idx].c();
|
||||
Gridded.cellWalk((byte) slot.key(), slot.lo(), slot.hi()).forEach(idx -> {
|
||||
int r = Masker.IT[idx].r();
|
||||
int c = Masker.IT[idx].c();
|
||||
if (display[r][c] == ' ' || (display[r][c] >= 'A' && display[r][c] <= 'D')) {
|
||||
if (display[r][c] != ' ' && display[r][c] != slotChar) {
|
||||
display[r][c] = '+'; // Intersection
|
||||
|
||||
Reference in New Issue
Block a user