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