Search in sources :

Example 26 with ColumnField

use of core.column_field.ColumnField 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 27 with ColumnField

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

the class OnDemandBasicSolutionsFactoryTest method assertCache.

private void assertCache(SizedBit sizedBit, long expectedSolutions, long expectedSolutionItems) throws IOException {
    SeparableMinos separableMinos = createSeparableMinos(sizedBit);
    int minMemorizedBit = (int) (sizedBit.getMaxBitDigit() * 0.2);
    Predicate<ColumnField> memorizedPredicate = BasicSolutions.createBitCountPredicate(minMemorizedBit);
    OnDemandBasicSolutions solutions = new OnDemandBasicSolutions(separableMinos, sizedBit, memorizedPredicate);
    Stopwatch stopwatch1 = Stopwatch.createStartedStopwatch();
    LongStream.rangeClosed(0, sizedBit.getFillBoard()).parallel().boxed().sorted(Comparator.comparingLong(Long::bitCount).reversed()).map(ColumnFieldFactory::createField).forEach(solutions::parse);
    stopwatch1.stop();
    System.out.println("create only: " + stopwatch1.toMessage(TimeUnit.MILLISECONDS));
    assertThat(countValidKey(solutions)).isEqualTo(expectedSolutions);
    assertThat(countValidItem(solutions)).isEqualTo(expectedSolutionItems);
}
Also used : SeparableMinos(searcher.pack.SeparableMinos) ColumnField(core.column_field.ColumnField) Stopwatch(lib.Stopwatch)

Example 28 with ColumnField

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

the class OnDemandBasicSolutionsTest method get3x5.

@Test
void get3x5() throws Exception {
    assertTimeout(ofMinutes(1), () -> {
        SizedBit sizedBit = new SizedBit(3, 5);
        SeparableMinos separableMinos = createSeparableMinos(sizedBit);
        Predicate<ColumnField> memorizedPredicate = columnField -> true;
        OnDemandBasicSolutions solutions = new OnDemandBasicSolutions(separableMinos, sizedBit, memorizedPredicate);
        Stream<? extends MinoField> stream = solutions.parse(ColumnFieldFactory.createField()).stream();
        assertThat(stream.count()).isEqualTo(260179L);
    });
}
Also used : MinoShifter(core.mino.MinoShifter) Predicate(java.util.function.Predicate) Assertions.assertThat(org.assertj.core.api.Assertions.assertThat) ColumnField(core.column_field.ColumnField) Duration.ofSeconds(java.time.Duration.ofSeconds) ColumnFieldFactory(core.column_field.ColumnFieldFactory) Test(org.junit.jupiter.api.Test) SizedBit(searcher.pack.SizedBit) Stream(java.util.stream.Stream) MinoFactory(core.mino.MinoFactory) SeparableMinos(searcher.pack.SeparableMinos) Duration.ofMinutes(java.time.Duration.ofMinutes) MinoField(searcher.pack.mino_field.MinoField) Assertions.assertTimeout(org.junit.jupiter.api.Assertions.assertTimeout) SeparableMinos(searcher.pack.SeparableMinos) SizedBit(searcher.pack.SizedBit) ColumnField(core.column_field.ColumnField) Test(org.junit.jupiter.api.Test)

Example 29 with ColumnField

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

the class OnDemandBasicSolutionsTest method get2x5.

@Test
void get2x5() throws Exception {
    SizedBit sizedBit = new SizedBit(2, 5);
    SeparableMinos separableMinos = createSeparableMinos(sizedBit);
    Predicate<ColumnField> memorizedPredicate = columnField -> true;
    OnDemandBasicSolutions solutions = new OnDemandBasicSolutions(separableMinos, sizedBit, memorizedPredicate);
    Stream<? extends MinoField> stream = solutions.parse(ColumnFieldFactory.createField()).stream();
    assertThat(stream.count()).isEqualTo(19375L);
}
Also used : MinoShifter(core.mino.MinoShifter) Predicate(java.util.function.Predicate) Assertions.assertThat(org.assertj.core.api.Assertions.assertThat) ColumnField(core.column_field.ColumnField) Duration.ofSeconds(java.time.Duration.ofSeconds) ColumnFieldFactory(core.column_field.ColumnFieldFactory) Test(org.junit.jupiter.api.Test) SizedBit(searcher.pack.SizedBit) Stream(java.util.stream.Stream) MinoFactory(core.mino.MinoFactory) SeparableMinos(searcher.pack.SeparableMinos) Duration.ofMinutes(java.time.Duration.ofMinutes) MinoField(searcher.pack.mino_field.MinoField) Assertions.assertTimeout(org.junit.jupiter.api.Assertions.assertTimeout) SeparableMinos(searcher.pack.SeparableMinos) SizedBit(searcher.pack.SizedBit) ColumnField(core.column_field.ColumnField) Test(org.junit.jupiter.api.Test)

Example 30 with ColumnField

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

the class PackSearcherComparingParityBasedTest method compareCount.

private void compareCount(int width, int height, List<TestData> testDataList) throws InterruptedException, ExecutionException {
    SizedBit sizedBit = new SizedBit(width, height);
    SeparableMinos separableMinos = createSeparableMinos(sizedBit);
    BasicSolutionsCalculator calculator = new BasicSolutionsCalculator(separableMinos, sizedBit);
    Map<ColumnField, RecursiveMinoFields> calculate = calculator.calculate();
    for (TestData data : testDataList) {
        // 準備
        List<Piece> usingPieces = data.getPieces();
        int popCount = usingPieces.size();
        Field initField = createSquareEmptyField(height, popCount);
        // packで探索
        Set<PieceCounter> pieceCounters = Collections.singleton(new PieceCounter(usingPieces));
        SolutionFilter solutionFilter = createUsingBlockAndValidKeyMementoFilter(initField, sizedBit, pieceCounters);
        BasicSolutions basicSolutions = new MappedBasicSolutions(calculate, solutionFilter);
        long packCounter = calculateSRSValidCount(sizedBit, basicSolutions, initField, solutionFilter);
        System.out.println(usingPieces);
        assertThat(packCounter).isEqualTo(data.getCount());
    }
}
Also used : PieceCounter(common.datastore.PieceCounter) ColumnField(core.column_field.ColumnField) BasicSolutionsCalculator(searcher.pack.solutions.BasicSolutionsCalculator) MappedBasicSolutions(searcher.pack.solutions.MappedBasicSolutions) BasicSolutions(searcher.pack.calculator.BasicSolutions) ColumnField(core.column_field.ColumnField) InOutPairField(searcher.pack.InOutPairField) Field(core.field.Field) SeparableMinos(searcher.pack.SeparableMinos) SizedBit(searcher.pack.SizedBit) Piece(core.mino.Piece) UsingBlockAndValidKeySolutionFilter(searcher.pack.memento.UsingBlockAndValidKeySolutionFilter) SolutionFilter(searcher.pack.memento.SolutionFilter) MappedBasicSolutions(searcher.pack.solutions.MappedBasicSolutions) RecursiveMinoFields(searcher.pack.mino_fields.RecursiveMinoFields)

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