introduce bitloops
This commit is contained in:
@@ -250,7 +250,7 @@ public final class Masker {
|
|||||||
}
|
}
|
||||||
if ((bitCount(rLo) + bitCount(rHi)) < MIN_LEN) penalty += 8000;
|
if ((bitCount(rLo) + bitCount(rHi)) < MIN_LEN) penalty += 8000;
|
||||||
int wordLen = bitCount(rLo) + bitCount(rHi);
|
int wordLen = bitCount(rLo) + bitCount(rHi);
|
||||||
if (wordLen > 5) penalty += (wordLen - 5) * 2000;
|
if (wordLen > 5) penalty += (wordLen - 5) * 1000L;
|
||||||
} else penalty += 25000;
|
} else penalty += 25000;
|
||||||
}
|
}
|
||||||
for (long bits = hi_cl; bits != X; bits &= bits - 1) {
|
for (long bits = hi_cl; bits != X; bits &= bits - 1) {
|
||||||
@@ -294,7 +294,7 @@ public final class Masker {
|
|||||||
}
|
}
|
||||||
if ((bitCount(rLo) + bitCount(rHi)) < MIN_LEN) penalty += 8000;
|
if ((bitCount(rLo) + bitCount(rHi)) < MIN_LEN) penalty += 8000;
|
||||||
int wordLen = bitCount(rLo) + bitCount(rHi);
|
int wordLen = bitCount(rLo) + bitCount(rHi);
|
||||||
if (wordLen > 5) penalty += (wordLen - 5) * 2000;
|
if (wordLen > 5) penalty += (wordLen - 5) * 1000L;
|
||||||
} else penalty += 25000;
|
} else penalty += 25000;
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -307,8 +307,8 @@ public final class Masker {
|
|||||||
rCount[idx & 7]++;
|
rCount[idx & 7]++;
|
||||||
cCount[idx >> 3]++;
|
cCount[idx >> 3]++;
|
||||||
}
|
}
|
||||||
for (int rc : rCount) if (rc < 2) penalty += (2 - rc) * 4000;
|
for (int rc : rCount) if (rc < 2) penalty += (2 - rc) * 4000L;
|
||||||
for (int cc : cCount) if (cc < 2) penalty += (2 - cc) * 4000;
|
for (int cc : cCount) if (cc < 2) penalty += (2 - cc) * 4000L;
|
||||||
|
|
||||||
// Connectiviteitscheck
|
// Connectiviteitscheck
|
||||||
for (int i = 0; i < numClues; i++) {
|
for (int i = 0; i < numClues; i++) {
|
||||||
@@ -368,7 +368,7 @@ public final class Masker {
|
|||||||
totalReachedHi |= currentReachedHi;
|
totalReachedHi |= currentReachedHi;
|
||||||
}
|
}
|
||||||
if (maxReached < numClues) {
|
if (maxReached < numClues) {
|
||||||
penalty += (numClues - maxReached) * 4000;
|
penalty += (numClues - maxReached) * 4000L;
|
||||||
penalty += 20000;
|
penalty += 20000;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -416,7 +416,7 @@ public final class Masker {
|
|||||||
compHi |= expandedHi & hi_cl;
|
compHi |= expandedHi & hi_cl;
|
||||||
} while (compLo != lastLo || compHi != lastHi);
|
} while (compLo != lastLo || compHi != lastHi);
|
||||||
int s = bitCount(compLo) + bitCount(compHi);
|
int s = bitCount(compLo) + bitCount(compHi);
|
||||||
if (s >= 2) penalty += (long) (s - 1) * 120;
|
if (s >= 2) penalty += (long) (s - 1) * 520;
|
||||||
remLo &= ~compLo;
|
remLo &= ~compLo;
|
||||||
remHi &= ~compHi;
|
remHi &= ~compHi;
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -40,7 +40,7 @@ public record SwedishGenerator() {
|
|||||||
public static final int MAX_WORD_LENGTH = Config.PUZZLE_ROWS;
|
public static final int MAX_WORD_LENGTH = Config.PUZZLE_ROWS;
|
||||||
public static final int MAX_WORD_LENGTH_PLUS_ONE = MAX_WORD_LENGTH + 1;
|
public static final int MAX_WORD_LENGTH_PLUS_ONE = MAX_WORD_LENGTH + 1;
|
||||||
public static final int MIN_LEN = 2;//Neighbors9x8.MIN_LEN;//Config.MIN_LEN;
|
public static final int MIN_LEN = 2;//Neighbors9x8.MIN_LEN;//Config.MIN_LEN;
|
||||||
public static final int MAX_TRIES_PER_SLOT = 400;//Config.MAX_TRIES_PER_SLOT;
|
public static final int MAX_TRIES_PER_SLOT = 500;//Config.MAX_TRIES_PER_SLOT;
|
||||||
public static final int STACK_SIZE = 128;
|
public static final int STACK_SIZE = 128;
|
||||||
public static final long RANGE_0_SIZE = Neighbors9x8.RANGE_0_SIZE;// (long) SIZE_MIN_1 - 0L + 1L
|
public static final long RANGE_0_SIZE = Neighbors9x8.RANGE_0_SIZE;// (long) SIZE_MIN_1 - 0L + 1L
|
||||||
public static final long RANGE_0_624 = Neighbors9x8.RANGE_0_624;//624L - 0L + 1L;
|
public static final long RANGE_0_624 = Neighbors9x8.RANGE_0_624;//624L - 0L + 1L;
|
||||||
|
|||||||
@@ -54,10 +54,22 @@ public class ConnectivityTest {
|
|||||||
clues.setClueLo(1L << Masker.offset(2, 1), (byte)1);
|
clues.setClueLo(1L << Masker.offset(2, 1), (byte)1);
|
||||||
|
|
||||||
long fitness = masker.maskFitness(clues, 2);
|
long fitness = masker.maskFitness(clues, 2);
|
||||||
|
// Als 8-naburigheid NIET MEER meetelt, moet de penalty hoog zijn.
|
||||||
// Als 8-naburigheid NIET MEER meetelt, moet de penalty hoog zijn.
|
System.out.println("[DEBUG_LOG] Fitness physically adjacent: " + fitness);
|
||||||
System.out.println("[DEBUG_LOG] Fitness physically adjacent: " + fitness);
|
assertTrue(fitness > 20000, "Should have island penalty even if physically adjacent");
|
||||||
assertTrue(fitness > 20000, "Should have island penalty even if physically adjacent");
|
Clues clues2 = Clues.createEmpty();
|
||||||
|
// Twee clues naast elkaar, maar slots kruisen niet.
|
||||||
|
// Clue 1: (1,1) Right. Slot (1,2), (1,3), (1,4)
|
||||||
|
// Clue 2: (2,1) Right. Slot (2,2), (2,3), (2,4)
|
||||||
|
clues2.setClueLo(1L << Masker.offset(1, 1), (byte)1);
|
||||||
|
clues2.setClueLo(1L << Masker.offset(3, 1), (byte)1);
|
||||||
|
long fitness2 = new Masker(rng, new int[STACK_SIZE], Clues.createEmpty()).maskFitness(clues2, 2);
|
||||||
|
// Als 8-naburigheid NIET MEER meetelt, moet de penalty hoog zijn.
|
||||||
|
System.out.println("[DEBUG_LOG] Fitness physically adjacent: " + fitness2);
|
||||||
|
assertTrue(fitness2 > 20000, "Should have island penalty even if physically adjacent");
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
|
|||||||
@@ -90,7 +90,6 @@ public class PerformanceTest {
|
|||||||
val subset = Arrays.copyOf(allSlots, 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);
|
System.out.printf("[DEBUG_LOG] Testing with first %d slots%n of %s", i, allSlots.length);
|
||||||
var grid = Slotinfo.grid(subset);
|
|
||||||
visualizeSlots(subset);
|
visualizeSlots(subset);
|
||||||
measureFill(new Rng(123 + i), subset, "Subset size " + i);
|
measureFill(new Rng(123 + i), subset, "Subset size " + i);
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user