Search in sources :

Example 11 with ColumnField

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

the class PerfectPackSearcher method forEach.

public void forEach(Consumer<Result> 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<Boolean> submitTask = forkJoinPool.submit(() -> {
        // Streamは終端操作を実行するまで実際には計算を行わない
        // そのため、終端操作をPool内でしなければ、Pool外のスレッド場で動くため注意が必要
        // (終端操作をしなかった場合、Pool内ではStream自体の作成をして終了する)
        Stream<Result> compute = toStream(task);
        compute.forEach(callback);
        // 計算を最後まで行ったことを伝えるため true を返却
        return true;
    });
    // 結果を取得するまで待つ
    Boolean result = submitTask.get();
    assert result;
    // 終了処理
    forkJoinPool.shutdown();
}
Also used : ColumnField(core.column_field.ColumnField) MinoFieldMemento(searcher.pack.memento.MinoFieldMemento) ForkJoinPool(java.util.concurrent.ForkJoinPool)

Example 12 with ColumnField

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

the class PerfectPackSearcher method count.

public Long count() throws InterruptedException, ExecutionException {
    // 探索準備
    MinoFieldMemento emptyMemento = MinoFieldMementoFactory.create();
    ColumnField innerField = inOutPairFields.get(0).getInnerField();
    PackingTask task = createPackingTask(sizedBit, emptyMemento, innerField);
    // 探索
    ForkJoinPool forkJoinPool = new ForkJoinPool();
    ForkJoinTask<Long> submitTask = forkJoinPool.submit(() -> {
        // Streamは終端操作を実行するまで実際には計算を行わない
        // そのため、終端操作をPool内でしなければ、Pool外のスレッド場で動くため注意が必要
        // (終端操作をしなかった場合、Pool内ではStream自体の作成をして終了する)
        Stream<Result> compute = toStream(task);
        return compute.count();
    });
    // 結果を取得するまで待つ
    Long 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 13 with ColumnField

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

the class SetupPackSearcher method stream.

public <T> T stream(Function<Stream<Result>, T> 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<T> submitTask = forkJoinPool.submit(() -> {
        return callback.apply(task.compute().parallel());
    });
    // 結果を取得するまで待つ
    T 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 14 with ColumnField

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

the class SetupPackSearcher method toList.

public List<Result> toList() throws InterruptedException, ExecutionException {
    // 探索準備
    MinoFieldMemento emptyMemento = MinoFieldMementoFactory.create();
    ColumnField innerField = inOutPairFields.get(0).getInnerField();
    PackingTask task = createPackingTask(sizedBit, emptyMemento, innerField);
    // 探索
    ForkJoinPool forkJoinPool = new ForkJoinPool();
    ForkJoinTask<List<Result>> submitTask = forkJoinPool.submit(() -> {
        // (終端操作をしなかった場合、Pool内ではStream自体の作成をして終了する)
        return task.compute().parallel().collect(Collectors.toList());
    });
    // 結果を取得するまで待つ
    List<Result> results = submitTask.get();
    // 終了処理
    forkJoinPool.shutdown();
    return results;
}
Also used : ColumnField(core.column_field.ColumnField) List(java.util.List) MinoFieldMemento(searcher.pack.memento.MinoFieldMemento) ForkJoinPool(java.util.concurrent.ForkJoinPool)

Example 15 with ColumnField

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

the class SetupPackSearcher method isFilled.

@Override
public boolean isFilled(ColumnField columnField, int index) {
    ColumnField innerField = needFillFields.get(index);
    long needFillBoard = innerField.getBoard(0);
    return (columnField.getBoard(0) & needFillBoard) == needFillBoard;
}
Also used : ColumnField(core.column_field.ColumnField)

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