Search in sources :

Example 1 with RecursiveMinoFields

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);
}
Also used : OperationWithKey(common.datastore.OperationWithKey) StreamColumnFieldConnections(searcher.pack.connections.StreamColumnFieldConnections) RecursiveMinoFields(searcher.pack.mino_fields.RecursiveMinoFields) ColumnField(core.column_field.ColumnField) Callable(java.util.concurrent.Callable) RecursiveMinoField(searcher.pack.mino_field.RecursiveMinoField) Objects(java.util.Objects) List(java.util.List) Field(core.field.Field) Stream(java.util.stream.Stream) SeparableMino(searcher.pack.separable_mino.SeparableMino) SeparableMinos(searcher.pack.SeparableMinos) ColumnFieldConnection(searcher.pack.connections.ColumnFieldConnection) ColumnFieldConnections(searcher.pack.connections.ColumnFieldConnections) OperationWithKey(common.datastore.OperationWithKey) SeparableMinos(searcher.pack.SeparableMinos) ColumnField(core.column_field.ColumnField) RecursiveMinoField(searcher.pack.mino_field.RecursiveMinoField) Objects(java.util.Objects)

Example 2 with RecursiveMinoFields

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);
}
Also used : SeparableMinos(searcher.pack.SeparableMinos) ColumnField(core.column_field.ColumnField) Stopwatch(lib.Stopwatch) AllPassedSolutionFilter(searcher.pack.memento.AllPassedSolutionFilter) RecursiveMinoFields(searcher.pack.mino_fields.RecursiveMinoFields)

Example 3 with RecursiveMinoFields

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);
}
Also used : RecursiveMinoFields(searcher.pack.mino_fields.RecursiveMinoFields) MinoFields(searcher.pack.mino_fields.MinoFields) SeparableMinos(searcher.pack.SeparableMinos) SizedBit(searcher.pack.SizedBit) ColumnField(core.column_field.ColumnField) RecursiveMinoFields(searcher.pack.mino_fields.RecursiveMinoFields) BasicSolutions(searcher.pack.calculator.BasicSolutions) Test(org.junit.jupiter.api.Test)

Example 4 with RecursiveMinoFields

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);
}
Also used : RecursiveMinoFields(searcher.pack.mino_fields.RecursiveMinoFields) MinoFields(searcher.pack.mino_fields.MinoFields) SeparableMinos(searcher.pack.SeparableMinos) SizedBit(searcher.pack.SizedBit) ColumnField(core.column_field.ColumnField) RecursiveMinoFields(searcher.pack.mino_fields.RecursiveMinoFields) BasicSolutions(searcher.pack.calculator.BasicSolutions) Test(org.junit.jupiter.api.Test)

Example 5 with RecursiveMinoFields

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());
    }
}
Also used : PieceCounter(common.datastore.PieceCounter) ColumnField(core.column_field.ColumnField) BasicSolutionsCalculator(searcher.pack.solutions.BasicSolutionsCalculator) MappedBasicSolutions(searcher.pack.solutions.MappedBasicSolutions) BasicSolutions(searcher.pack.calculator.BasicSolutions) ColumnField(core.column_field.ColumnField) InOutPairField(searcher.pack.InOutPairField) Field(core.field.Field) SeparableMinos(searcher.pack.SeparableMinos) SizedBit(searcher.pack.SizedBit) Piece(core.mino.Piece) UsingBlockAndValidKeySolutionFilter(searcher.pack.memento.UsingBlockAndValidKeySolutionFilter) SolutionFilter(searcher.pack.memento.SolutionFilter) MappedBasicSolutions(searcher.pack.solutions.MappedBasicSolutions) RecursiveMinoFields(searcher.pack.mino_fields.RecursiveMinoFields)

Aggregations

ColumnField (core.column_field.ColumnField)12 RecursiveMinoFields (searcher.pack.mino_fields.RecursiveMinoFields)12 SeparableMinos (searcher.pack.SeparableMinos)11 SizedBit (searcher.pack.SizedBit)7 BasicSolutions (searcher.pack.calculator.BasicSolutions)7 Test (org.junit.jupiter.api.Test)6 MinoFields (searcher.pack.mino_fields.MinoFields)6 Field (core.field.Field)3 BasicSolutionsCalculator (searcher.pack.solutions.BasicSolutionsCalculator)3 MappedBasicSolutions (searcher.pack.solutions.MappedBasicSolutions)3 OperationWithKey (common.datastore.OperationWithKey)1 PieceCounter (common.datastore.PieceCounter)1 ColumnSmallField (core.column_field.ColumnSmallField)1 SmallField (core.field.SmallField)1 Piece (core.mino.Piece)1 List (java.util.List)1 Objects (java.util.Objects)1 Callable (java.util.concurrent.Callable)1 Stream (java.util.stream.Stream)1 Stopwatch (lib.Stopwatch)1