Search in sources :

Example 1 with MinoFieldMemento

use of searcher.pack.memento.MinoFieldMemento in project solution-finder by knewjade.

the class Field4x10MinoPackingHelper method fixResult.

// 高さが4・最後の1列がのこる場合で、パフェできるパターンは2つしか存在しない
@Override
public Stream<Result> fixResult(PackSearcher searcher, long innerFieldBoard, MinoFieldMemento nextMemento) {
    SizedBit sizedBit = searcher.getSizedBit();
    SolutionFilter solutionFilter = searcher.getSolutionFilter();
    if (innerFieldBoard == sizedBit.getFillBoard()) {
        if (solutionFilter.testLast(nextMemento))
            return Stream.of(createResult(nextMemento));
    } else {
        assert innerFieldBoard == 0b111111110000L;
        MinoFieldMemento concatILeft = nextMemento.concat(LEFT_I_ONLY);
        if (solutionFilter.testLast(concatILeft))
            return Stream.of(createResult(concatILeft));
    }
    return Stream.empty();
}
Also used : SizedBit(searcher.pack.SizedBit) SolutionFilter(searcher.pack.memento.SolutionFilter) MinoFieldMemento(searcher.pack.memento.MinoFieldMemento)

Example 2 with MinoFieldMemento

use of searcher.pack.memento.MinoFieldMemento in project solution-finder by knewjade.

the class MinoPackingTaskWidthForWidth2 method split.

private PackingTask split(MinoField minoField) {
    ColumnField minoOuterField = minoField.getOuterField();
    // 注目範囲外outerで重なりがないか確認
    if (outerField.canMerge(minoOuterField)) {
        // 有効なおきかた
        SizedBit sizedBit = searcher.getSizedBit();
        ColumnField mergedOuterField = outerField.freeze(sizedBit.getHeight());
        mergedOuterField.merge(minoOuterField);
        long innerFieldBoard = mergedOuterField.getBoard(0) >> sizedBit.getMaxBitDigit();
        MinoFieldMemento nextMemento = memento.concat(minoField);
        return checkAndCreateTask(innerFieldBoard, nextMemento, index + 1);
    }
    return EMPTY_TASK;
}
Also used : SizedBit(searcher.pack.SizedBit) ColumnField(core.column_field.ColumnField) MinoFieldMemento(searcher.pack.memento.MinoFieldMemento)

Example 3 with MinoFieldMemento

use of searcher.pack.memento.MinoFieldMemento in project solution-finder by knewjade.

the class MinoPackingTaskWidthForWidth2 method splitAndFixResult.

private Stream<Result> splitAndFixResult(MinoField minoField) {
    ColumnField minoOuterField = minoField.getOuterField();
    // 注目範囲外outerで重なりがないか確認
    if (outerField.canMerge(minoOuterField)) {
        // 有効なおきかた
        SizedBit sizedBit = searcher.getSizedBit();
        ColumnField mergedOuterField = outerField.freeze(searcher.getSizedBit().getHeight());
        mergedOuterField.merge(minoOuterField);
        long innerFieldBoard = mergedOuterField.getBoard(0) >> sizedBit.getMaxBitDigit();
        MinoFieldMemento nextMemento = memento.concat(minoField);
        return searcher.getTaskResultHelper().fixResult(searcher, innerFieldBoard, nextMemento);
    }
    return Stream.empty();
}
Also used : SizedBit(searcher.pack.SizedBit) ColumnField(core.column_field.ColumnField) MinoFieldMemento(searcher.pack.memento.MinoFieldMemento)

Example 4 with MinoFieldMemento

use of searcher.pack.memento.MinoFieldMemento 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 5 with MinoFieldMemento

use of searcher.pack.memento.MinoFieldMemento in project solution-finder by knewjade.

the class MinoPackingTaskWidthForWidth3 method split.

private PackingTask split(MinoField minoField) {
    ColumnField outerField = searcher.getInOutPairFields().get(index).getOuterField();
    ColumnField minoOuterField = minoField.getOuterField();
    // 注目範囲外outerで重なりがないか確認
    if (outerField.canMerge(minoOuterField)) {
        // 有効なおきかた
        SizedBit sizedBit = searcher.getSizedBit();
        ColumnField mergedOuterField = outerField.freeze(sizedBit.getHeight());
        mergedOuterField.merge(minoOuterField);
        ColumnSmallField nextInnerField = ColumnFieldFactory.createField(mergedOuterField.getBoard(0) >> sizedBit.getMaxBitDigit());
        MinoFieldMemento nextMemento = memento.concat(minoField);
        return checkAndCreateTask(nextInnerField, nextMemento, index + 1);
    }
    return EMPTY_TASK;
}
Also used : ColumnSmallField(core.column_field.ColumnSmallField) SizedBit(searcher.pack.SizedBit) ColumnField(core.column_field.ColumnField) MinoFieldMemento(searcher.pack.memento.MinoFieldMemento)

Aggregations

MinoFieldMemento (searcher.pack.memento.MinoFieldMemento)20 ColumnField (core.column_field.ColumnField)17 ForkJoinPool (java.util.concurrent.ForkJoinPool)12 SizedBit (searcher.pack.SizedBit)8 MinoFields (searcher.pack.mino_fields.MinoFields)3 ColumnSmallField (core.column_field.ColumnSmallField)2 List (java.util.List)2 Optional (java.util.Optional)2 SolutionFilter (searcher.pack.memento.SolutionFilter)2 ColumnFieldFactory (core.column_field.ColumnFieldFactory)1 Stream (java.util.stream.Stream)1 InOutPairField (searcher.pack.InOutPairField)1