use of searcher.pack.SizedBit in project solution-finder by knewjade.
the class UseCSVPathOutput method output.
@Override
public void output(List<PathPair> pathPairs, Field field, SizedBit sizedBit) throws FinderExecuteException {
this.lastException = null;
outputLog("Found path = " + pathPairs.size());
AtomicInteger allCounter = new AtomicInteger();
Map<PieceCounter, List<PathPair>> groupingByClockCounter = pathPairs.parallelStream().collect(Collectors.groupingBy(pathPair -> {
List<OperationWithKey> operations = pathPair.getSampleOperations();
return new PieceCounter(operations.stream().map(OperationWithKey::getPiece));
}));
List<PathPair> emptyValidList = Collections.emptyList();
try (AsyncBufferedFileWriter writer = outputBaseFile.newAsyncWriter()) {
writer.writeAndNewLine("使用ミノ,対応地形数,対応ツモ数 (対パターン),テト譜,ツモ (対パターン)");
generator.blockCountersStream().parallel().map(blockCounter -> {
// カウンターをインクリメント
allCounter.incrementAndGet();
// 組み合わせ名を取得
String blockCounterName = blockCounter.getBlockStream().map(Piece::getName).collect(Collectors.joining());
// パフェ可能な地形を抽出
List<PathPair> valid = groupingByClockCounter.getOrDefault(blockCounter, emptyValidList);
// パフェ可能な地形数
int possibleSize = valid.size();
// パフェ可能な地形のテト譜を連結
String fumens = valid.stream().sorted(Comparator.comparing(PathPair::getPatternSize).reversed()).map(pathPair -> "v115@" + pathPair.getFumen()).collect(Collectors.joining(";"));
// 対応できるパターンを重複なく抽出
Set<LongPieces> possiblePatternSet = valid.stream().flatMap(PathPair::blocksStreamForPattern).collect(Collectors.toSet());
// 対応できるパターン数
int possiblePatternSize = possiblePatternSet.size();
// パターンを連結
String patterns = possiblePatternSet.stream().map(LongPieces::getPieces).map(blocks -> blocks.stream().map(Piece::getName).collect(Collectors.joining(""))).collect(Collectors.joining(";"));
return String.format("%s,%d,%d,%s,%s", blockCounterName, possibleSize, possiblePatternSize, fumens, patterns);
}).forEach(writer::writeAndNewLine);
writer.flush();
} catch (IOException e) {
throw new FinderExecuteException("Failed to output file", e);
}
outputLog("Found piece combinations = " + allCounter.get());
if (lastException != null)
throw new FinderExecuteException("Error to output file", lastException);
}
use of searcher.pack.SizedBit 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.SizedBit 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.SizedBit in project solution-finder by knewjade.
the class OnDemandBasicSolutionsFactoryTest method create3x1.
@Test
void create3x1() throws Exception {
SizedBit sizedBit = new SizedBit(3, 1);
int expectedSolutions = 3;
int expectedSolutionItems = 3;
assertCache(sizedBit, expectedSolutions, expectedSolutionItems);
}
use of searcher.pack.SizedBit in project solution-finder by knewjade.
the class OnDemandBasicSolutionsFactoryTest method create3x4.
@Test
void create3x4() throws Exception {
SizedBit sizedBit = new SizedBit(3, 4);
int expectedSolutions = 2211;
int expectedSolutionItems = 228022;
assertCache(sizedBit, expectedSolutions, expectedSolutionItems);
}
Aggregations