Search in sources :

Example 16 with SizedBit

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);
}
Also used : OperationWithKey(common.datastore.OperationWithKey) Piece(core.mino.Piece) java.util(java.util) LongPieces(common.datastore.blocks.LongPieces) PatternGenerator(common.pattern.PatternGenerator) ReducePatternGenerator(entry.path.ReducePatternGenerator) IOException(java.io.IOException) FinderExecuteException(exceptions.FinderExecuteException) FinderInitializeException(exceptions.FinderInitializeException) Collectors(java.util.stream.Collectors) File(java.io.File) PieceCounter(common.datastore.PieceCounter) SizedBit(searcher.pack.SizedBit) Field(core.field.Field) AtomicInteger(java.util.concurrent.atomic.AtomicInteger) AsyncBufferedFileWriter(lib.AsyncBufferedFileWriter) PathPair(entry.path.PathPair) PathEntryPoint(entry.path.PathEntryPoint) PathSettings(entry.path.PathSettings) OperationWithKey(common.datastore.OperationWithKey) PieceCounter(common.datastore.PieceCounter) IOException(java.io.IOException) PathPair(entry.path.PathPair) AtomicInteger(java.util.concurrent.atomic.AtomicInteger) AsyncBufferedFileWriter(lib.AsyncBufferedFileWriter) Piece(core.mino.Piece) FinderExecuteException(exceptions.FinderExecuteException)

Example 17 with SizedBit

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

Example 18 with SizedBit

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

Example 19 with SizedBit

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);
}
Also used : SizedBit(searcher.pack.SizedBit) Test(org.junit.jupiter.api.Test) LongTest(module.LongTest)

Example 20 with SizedBit

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);
}
Also used : SizedBit(searcher.pack.SizedBit) Test(org.junit.jupiter.api.Test) LongTest(module.LongTest)

Aggregations

SizedBit (searcher.pack.SizedBit)53 Test (org.junit.jupiter.api.Test)32 ColumnField (core.column_field.ColumnField)29 SeparableMinos (searcher.pack.SeparableMinos)22 Field (core.field.Field)18 LongTest (module.LongTest)18 MinoFactory (core.mino.MinoFactory)15 MinoShifter (core.mino.MinoShifter)15 SolutionFilter (searcher.pack.memento.SolutionFilter)15 InOutPairField (searcher.pack.InOutPairField)14 Piece (core.mino.Piece)13 Collectors (java.util.stream.Collectors)13 BasicSolutions (searcher.pack.calculator.BasicSolutions)13 Predicate (java.util.function.Predicate)12 Assertions.assertThat (org.assertj.core.api.Assertions.assertThat)12 SeparableMino (searcher.pack.separable_mino.SeparableMino)11 PerfectPackSearcher (searcher.pack.task.PerfectPackSearcher)11 Result (searcher.pack.task.Result)11 TaskResultHelper (searcher.pack.task.TaskResultHelper)10 Stream (java.util.stream.Stream)9