Search in sources :

Example 46 with ColumnField

use of core.column_field.ColumnField in project solution-finder by knewjade.

the class SetupPackSearcher method collect.

public <A, R> R collect(Collector<? super Result, A, R> callback) throws InterruptedException, ExecutionException {
    // 探索準備
    MinoFieldMemento emptyMemento = MinoFieldMementoFactory.create();
    ColumnField innerField = inOutPairFields.get(0).getInnerField();
    PackingTask task = createPackingTask(sizedBit, emptyMemento, innerField);
    // 探索
    ForkJoinPool forkJoinPool = new ForkJoinPool();
    ForkJoinTask<R> submitTask = forkJoinPool.submit(() -> {
        return task.compute().parallel().collect(callback);
    });
    // 結果を取得するまで待つ
    R result = submitTask.get();
    assert result != null;
    // 終了処理
    forkJoinPool.shutdown();
    return result;
}
Also used : ColumnField(core.column_field.ColumnField) MinoFieldMemento(searcher.pack.memento.MinoFieldMemento) ForkJoinPool(java.util.concurrent.ForkJoinPool)

Example 47 with ColumnField

use of core.column_field.ColumnField in project solution-finder by knewjade.

the class SetupPackSearcher method findAny.

public Optional<Result> findAny() throws InterruptedException, ExecutionException {
    // 探索準備
    MinoFieldMemento emptyMemento = MinoFieldMementoFactory.create();
    ColumnField innerField = inOutPairFields.get(0).getInnerField();
    PackingTask task = createPackingTask(sizedBit, emptyMemento, innerField);
    // 探索
    ForkJoinPool forkJoinPool = new ForkJoinPool();
    ForkJoinTask<Optional<Result>> submitTask = forkJoinPool.submit(() -> {
        return task.compute().parallel().findAny();
    });
    // 結果を取得するまで待つ
    Optional<Result> result = submitTask.get();
    assert result != null;
    // 終了処理
    forkJoinPool.shutdown();
    return result;
}
Also used : Optional(java.util.Optional) ColumnField(core.column_field.ColumnField) MinoFieldMemento(searcher.pack.memento.MinoFieldMemento) ForkJoinPool(java.util.concurrent.ForkJoinPool)

Example 48 with ColumnField

use of core.column_field.ColumnField in project solution-finder by knewjade.

the class StreamColumnFieldConnections method getConnectionStream.

@Override
public Stream<ColumnFieldConnection> getConnectionStream() {
    Stream.Builder<ColumnFieldConnection> builder = Stream.builder();
    for (SeparableMino mino : separableMinos) {
        ColumnField minoField = mino.getColumnField();
        if (columnField.canMerge(minoField)) {
            ColumnField freeze = columnField.freeze(sizedBit.getHeight());
            freeze.merge(minoField);
            ColumnFieldConnection connection = new ColumnFieldConnection(mino, freeze, sizedBit);
            builder.accept(connection);
        }
    }
    return builder.build();
}
Also used : SeparableMino(searcher.pack.separable_mino.SeparableMino) ColumnField(core.column_field.ColumnField) Stream(java.util.stream.Stream)

Example 49 with ColumnField

use of core.column_field.ColumnField in project solution-finder by knewjade.

the class ConnectionsToStreamCallable method parseConnectionToMinoField.

private Stream<? extends RecursiveMinoField> parseConnectionToMinoField(ColumnFieldConnection connection) {
    // outerで重なりがないか確認する
    ColumnField nextOuterField = connection.getOuterField();
    if (nextOuterField.canMerge(limitOuterField) && nextOuterField.canMerge(outerColumnField)) {
        ColumnField freeze = nextOuterField.freeze(calculator.getHeight());
        // フィールドとミノ順を進める
        SeparableMino currentMino = connection.getMino();
        freeze.merge(outerColumnField);
        // 新しいフィールドを基に探索
        ColumnField innerField = connection.getInnerField();
        return calculate(innerField, freeze, wallField, currentMino);
    }
    return Stream.empty();
}
Also used : SeparableMino(searcher.pack.separable_mino.SeparableMino) ColumnField(core.column_field.ColumnField)

Example 50 with ColumnField

use of core.column_field.ColumnField in project solution-finder by knewjade.

the class MappedBasicSolutionsTest method get3x5.

@Test
void get3x5() throws Exception {
    SizedBit sizedBit = new SizedBit(3, 5);
    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(260179L);
}
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)

Aggregations

ColumnField (core.column_field.ColumnField)62 SeparableMinos (searcher.pack.SeparableMinos)33 SizedBit (searcher.pack.SizedBit)26 Field (core.field.Field)19 Test (org.junit.jupiter.api.Test)19 MinoFieldMemento (searcher.pack.memento.MinoFieldMemento)17 MinoFactory (core.mino.MinoFactory)14 MinoShifter (core.mino.MinoShifter)14 ForkJoinPool (java.util.concurrent.ForkJoinPool)12 Predicate (java.util.function.Predicate)12 Assertions.assertThat (org.assertj.core.api.Assertions.assertThat)12 RecursiveMinoFields (searcher.pack.mino_fields.RecursiveMinoFields)12 SeparableMino (searcher.pack.separable_mino.SeparableMino)12 Stream (java.util.stream.Stream)11 ColumnSmallField (core.column_field.ColumnSmallField)10 InOutPairField (searcher.pack.InOutPairField)10 OnDemandBasicSolutions (searcher.pack.solutions.OnDemandBasicSolutions)10 BasicSolutions (searcher.pack.calculator.BasicSolutions)9 SolutionFilter (searcher.pack.memento.SolutionFilter)9 Piece (core.mino.Piece)7