use of searcher.pack.mino_fields.RecursiveMinoFields in project solution-finder by knewjade.
the class ConnectionsToStreamCallable method parseWhenNext.
private Stream<RecursiveMinoField> parseWhenNext(ColumnField outerColumnField, SeparableMino currentMino, RecursiveMinoFields minoFields) {
SeparableMinos separableMinos = calculator.getSeparableMinos();
int index = separableMinos.toIndex(currentMino);
return minoFields.recursiveStream().filter(minoField -> minoField.getMaxIndex() <= index).map(minoField -> {
// outerで、最終的に使用されるブロック と すでに使っているブロックが重ならないことを確認
ColumnField lastOuterField = minoField.getOuterField();
if (!lastOuterField.canMerge(outerColumnField))
return null;
OperationWithKey currentOperations = currentMino.toMinoOperationWithKey();
long currentDeleteKey = currentOperations.getNeedDeletedKey();
long currentUsingKey = currentOperations.getUsingKey();
// いま置こうとしているミノと、それまでの結果に矛盾があるか確認
boolean isContradiction = currentDeleteKey != 0L && minoField.getOperationsStream().anyMatch(operationWithKey -> {
long deletedKey = operationWithKey.getNeedDeletedKey();
long usingKey = operationWithKey.getUsingKey();
return (currentUsingKey & deletedKey) != 0L && (usingKey & currentDeleteKey) != 0L;
});
// 矛盾があるときはスキップ
if (isContradiction)
return null;
// 使用されるブロックを算出
ColumnField usingBlock = lastOuterField.freeze(calculator.getHeight());
usingBlock.merge(outerColumnField);
return new RecursiveMinoField(currentMino, minoField, usingBlock, separableMinos);
}).filter(Objects::nonNull);
}
use of searcher.pack.mino_fields.RecursiveMinoFields in project solution-finder by knewjade.
the class MappedBasicSolutionsFactoryTest method assertCache.
private void assertCache(SizedBit sizedBit, long expectedSolutions, long expectedSolutionItems) throws IOException {
SeparableMinos separableMinos = createSeparableMinos(sizedBit);
BasicSolutionsCalculator calculator = new BasicSolutionsCalculator(separableMinos, sizedBit);
Stopwatch stopwatch1 = Stopwatch.createStartedStopwatch();
Map<ColumnField, RecursiveMinoFields> calculate = calculator.calculate();
stopwatch1.stop();
System.out.println("create only: " + stopwatch1.toMessage(TimeUnit.MILLISECONDS));
AllPassedSolutionFilter solutionFilter = new AllPassedSolutionFilter();
MappedBasicSolutions solutions = new MappedBasicSolutions(calculate, solutionFilter);
assertThat(countValidKey(solutions)).isEqualTo(expectedSolutions);
assertThat(countValidItem(solutions)).isEqualTo(expectedSolutionItems);
}
use of searcher.pack.mino_fields.RecursiveMinoFields in project solution-finder by knewjade.
the class MappedBasicSolutionsTest method get2x3.
@Test
void get2x3() throws Exception {
SizedBit sizedBit = new SizedBit(2, 3);
SeparableMinos separableMinos = createSeparableMinos(sizedBit);
BasicSolutionsCalculator calculator = new BasicSolutionsCalculator(separableMinos, sizedBit);
Map<ColumnField, RecursiveMinoFields> calculate = calculator.calculate();
BasicSolutions solutions = new MappedBasicSolutions(calculate);
MinoFields minoFields = solutions.parse(ColumnFieldFactory.createField());
Stream<? extends MinoField> stream = minoFields.stream();
assertThat(stream.count()).isEqualTo(78L);
}
use of searcher.pack.mino_fields.RecursiveMinoFields in project solution-finder by knewjade.
the class MappedBasicSolutionsTest method get3x4.
@Test
void get3x4() throws Exception {
SizedBit sizedBit = new SizedBit(3, 4);
SeparableMinos separableMinos = createSeparableMinos(sizedBit);
BasicSolutionsCalculator calculator = new BasicSolutionsCalculator(separableMinos, sizedBit);
Map<ColumnField, RecursiveMinoFields> calculate = calculator.calculate();
BasicSolutions solutions = new MappedBasicSolutions(calculate);
MinoFields minoFields = solutions.parse(ColumnFieldFactory.createField());
Stream<? extends MinoField> stream = minoFields.stream();
assertThat(stream.count()).isEqualTo(8516L);
}
use of searcher.pack.mino_fields.RecursiveMinoFields in project solution-finder by knewjade.
the class PackSearcherComparingParityBasedTest method compareCount.
private void compareCount(int width, int height, List<TestData> testDataList) throws InterruptedException, ExecutionException {
SizedBit sizedBit = new SizedBit(width, height);
SeparableMinos separableMinos = createSeparableMinos(sizedBit);
BasicSolutionsCalculator calculator = new BasicSolutionsCalculator(separableMinos, sizedBit);
Map<ColumnField, RecursiveMinoFields> calculate = calculator.calculate();
for (TestData data : testDataList) {
// 準備
List<Piece> usingPieces = data.getPieces();
int popCount = usingPieces.size();
Field initField = createSquareEmptyField(height, popCount);
// packで探索
Set<PieceCounter> pieceCounters = Collections.singleton(new PieceCounter(usingPieces));
SolutionFilter solutionFilter = createUsingBlockAndValidKeyMementoFilter(initField, sizedBit, pieceCounters);
BasicSolutions basicSolutions = new MappedBasicSolutions(calculate, solutionFilter);
long packCounter = calculateSRSValidCount(sizedBit, basicSolutions, initField, solutionFilter);
System.out.println(usingPieces);
assertThat(packCounter).isEqualTo(data.getCount());
}
}
Aggregations