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;
}
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;
}
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();
}
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();
}
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);
}
Aggregations