Search in sources :

Example 1 with MinoFields

use of searcher.pack.mino_fields.MinoFields in project solution-finder by knewjade.

the class MinoPackingTaskWidthForWidth2 method compute.

@Override
public Stream<Result> compute() {
    if (searcher.isFilled(innerField, index)) {
        // innerFieldが埋まっている
        if (index == searcher.getLastIndex()) {
            // 最後の計算
            SizedBit sizedBit = searcher.getSizedBit();
            long innerFieldBoard = outerField.getBoard(0) >> sizedBit.getMaxBitDigit();
            MinoFieldMemento nextMemento = memento.skip();
            return searcher.getTaskResultHelper().fixResult(searcher, innerFieldBoard, nextMemento);
        } else {
            // 途中の計算  // 自分で計算する
            MinoFieldMemento nextMemento = memento.skip();
            long innerFieldBoard = outerField.getBoard(0) >> searcher.getSizedBit().getMaxBitDigit();
            return createTask(searcher, innerFieldBoard, nextMemento, index + 1).compute();
        }
    } else {
        MinoFields minoFields = searcher.getSolutions(index).parse(innerField);
        // innerFieldが埋まっていない
        if (index == searcher.getLastIndex()) {
            // 最後の計算
            return minoFields.stream().parallel().flatMap(this::splitAndFixResult);
        } else {
            // 途中の計算
            return minoFields.stream().parallel().map(this::split).filter(this::isValidTask).flatMap(PackingTask::compute);
        }
    }
}
Also used : MinoFields(searcher.pack.mino_fields.MinoFields) SizedBit(searcher.pack.SizedBit) MinoFieldMemento(searcher.pack.memento.MinoFieldMemento)

Example 2 with MinoFields

use of searcher.pack.mino_fields.MinoFields in project solution-finder by knewjade.

the class MinoPackingTaskWidthForWidth3 method compute.

@Override
public Stream<Result> compute() {
    if (searcher.isFilled(innerField, index)) {
        // innerFieldが埋まっている
        List<InOutPairField> inOutPairFields = searcher.getInOutPairFields();
        if (index == searcher.getLastIndex()) {
            // 最後の計算
            SizedBit sizedBit = searcher.getSizedBit();
            ColumnField lastOuterField = inOutPairFields.get(index).getOuterField();
            long innerFieldBoard = lastOuterField.getBoard(0) >> sizedBit.getMaxBitDigit();
            MinoFieldMemento nextMemento = memento.skip();
            return searcher.getTaskResultHelper().fixResult(searcher, innerFieldBoard, nextMemento);
        } else {
            // 途中の計算  // 自分で計算する
            int nextIndex = index + 1;
            ColumnField nextInnerField = inOutPairFields.get(nextIndex).getInnerField();
            MinoFieldMemento nextMemento = memento.skip();
            return createTask(searcher, nextInnerField, nextMemento, nextIndex).compute();
        }
    } else {
        MinoFields minoFields = searcher.getSolutions(index).parse(innerField);
        // innerFieldが埋まっていない
        if (index == searcher.getLastIndex()) {
            // 最後の計算
            return minoFields.stream().parallel().flatMap(this::splitAndFixResult);
        } else {
            // 途中の計算
            return minoFields.stream().parallel().map(this::split).filter(this::isValidTask).flatMap(PackingTask::compute);
        }
    }
}
Also used : MinoFields(searcher.pack.mino_fields.MinoFields) InOutPairField(searcher.pack.InOutPairField) SizedBit(searcher.pack.SizedBit) ColumnField(core.column_field.ColumnField) MinoFieldMemento(searcher.pack.memento.MinoFieldMemento)

Example 3 with MinoFields

use of searcher.pack.mino_fields.MinoFields 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 MinoFields

use of searcher.pack.mino_fields.MinoFields 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 MinoFields

use of searcher.pack.mino_fields.MinoFields in project solution-finder by knewjade.

the class BasicMinoPackingHelper method fixResult.

@Override
public Stream<Result> fixResult(PackSearcher searcher, long innerFieldBoard, MinoFieldMemento nextMemento) {
    SizedBit sizedBit = searcher.getSizedBit();
    SolutionFilter solutionFilter = searcher.getSolutionFilter();
    long fillBoard = sizedBit.getFillBoard();
    long board = innerFieldBoard & fillBoard;
    int resultIndex = searcher.getLastIndex() + 1;
    ColumnSmallField nextInnerField = ColumnFieldFactory.createField(board);
    if (searcher.isFilled(nextInnerField, resultIndex)) {
        if (solutionFilter.testLast(nextMemento))
            return Stream.of(createResult(nextMemento));
        return Stream.empty();
    } else {
        ColumnSmallField over = ColumnFieldFactory.createField(innerFieldBoard & ~fillBoard);
        MinoFields minoFields = searcher.getSolutions(resultIndex).parse(nextInnerField);
        return minoFields.stream().filter(minoField -> over.canMerge(minoField.getOuterField())).map(nextMemento::concat).filter(solutionFilter::testLast).map(this::createResult);
    }
}
Also used : SolutionFilter(searcher.pack.memento.SolutionFilter) SizedBit(searcher.pack.SizedBit) Stream(java.util.stream.Stream) ColumnFieldFactory(core.column_field.ColumnFieldFactory) ColumnSmallField(core.column_field.ColumnSmallField) MinoFieldMemento(searcher.pack.memento.MinoFieldMemento) MinoFields(searcher.pack.mino_fields.MinoFields) ColumnSmallField(core.column_field.ColumnSmallField) MinoFields(searcher.pack.mino_fields.MinoFields) SizedBit(searcher.pack.SizedBit) SolutionFilter(searcher.pack.memento.SolutionFilter)

Aggregations

SizedBit (searcher.pack.SizedBit)9 MinoFields (searcher.pack.mino_fields.MinoFields)9 ColumnField (core.column_field.ColumnField)7 Test (org.junit.jupiter.api.Test)6 SeparableMinos (searcher.pack.SeparableMinos)6 BasicSolutions (searcher.pack.calculator.BasicSolutions)6 RecursiveMinoFields (searcher.pack.mino_fields.RecursiveMinoFields)6 MinoFieldMemento (searcher.pack.memento.MinoFieldMemento)3 ColumnFieldFactory (core.column_field.ColumnFieldFactory)1 ColumnSmallField (core.column_field.ColumnSmallField)1 Stream (java.util.stream.Stream)1 InOutPairField (searcher.pack.InOutPairField)1 SolutionFilter (searcher.pack.memento.SolutionFilter)1