Search in sources :

Example 46 with SizedBit

use of searcher.pack.SizedBit in project solution-finder by knewjade.

the class OnDemandBasicSolutionsTest method get3x3.

@Test
void get3x3() throws Exception {
    SizedBit sizedBit = new SizedBit(3, 3);
    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(278L);
}
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 47 with SizedBit

use of searcher.pack.SizedBit in project solution-finder by knewjade.

the class OnDemandBasicSolutionsTest method get2x4.

@Test
void get2x4() throws Exception {
    SizedBit sizedBit = new SizedBit(2, 4);
    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(1239L);
}
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 48 with SizedBit

use of searcher.pack.SizedBit in project solution-finder by knewjade.

the class PackSearcherComparingParityBasedOnDemandTest 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);
    Predicate<ColumnField> bitCountPredicate = BasicSolutions.createBitCountPredicate(1);
    OnDemandBasicSolutions onDemandBasicSolutions = new OnDemandBasicSolutions(separableMinos, sizedBit, bitCountPredicate);
    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 FilterWrappedBasicSolutions(onDemandBasicSolutions, solutionFilter);
        long packCounter = calculateSRSValidCount(sizedBit, basicSolutions, initField, solutionFilter);
        System.out.println(usingPieces);
        assertThat(packCounter).isEqualTo(data.getCount());
    }
}
Also used : OnDemandBasicSolutions(searcher.pack.solutions.OnDemandBasicSolutions) PieceCounter(common.datastore.PieceCounter) ColumnField(core.column_field.ColumnField) FilterWrappedBasicSolutions(searcher.pack.solutions.FilterWrappedBasicSolutions) BasicSolutions(searcher.pack.calculator.BasicSolutions) OnDemandBasicSolutions(searcher.pack.solutions.OnDemandBasicSolutions) 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) FilterWrappedBasicSolutions(searcher.pack.solutions.FilterWrappedBasicSolutions)

Example 49 with SizedBit

use of searcher.pack.SizedBit in project solution-finder by knewjade.

the class ColumnFieldViewTest method test.

@Test
void test() {
    int height = 4;
    int width = 3;
    SizedBit sizedBit = new SizedBit(width, height);
    ColumnSmallField field = new ColumnSmallField();
    field.setBlock(0, 0, height);
    field.setBlock(1, 1, height);
    field.setBlock(2, 2, height);
    field.setBlock(1, 3, height);
    String lineSeparator = System.lineSeparator();
    String expect = Stream.of("_X_", "__X", "_X_", "X__").collect(Collectors.joining(lineSeparator));
    assertThat(ColumnFieldView.toString(field, sizedBit)).isEqualTo(expect);
}
Also used : SizedBit(searcher.pack.SizedBit) Test(org.junit.jupiter.api.Test)

Example 50 with SizedBit

use of searcher.pack.SizedBit in project solution-finder by knewjade.

the class ColumnFieldViewTest method testRandom.

@Test
void testRandom() {
    Randoms randoms = new Randoms();
    String lineSeparator = System.lineSeparator();
    for (int count = 0; count < 10000; count++) {
        int width = randoms.nextIntClosed(1, 6);
        int height = randoms.nextIntClosed(1, 10);
        SizedBit sizedBit = new SizedBit(width, height);
        // create fields
        boolean[][] fields = new boolean[height][width];
        for (int y = 0; y < height; y++) for (int x = 0; x < width; x++) fields[y][x] = randoms.nextBoolean();
        // parse to long
        long board = 0L;
        for (int x = 0; x < width; x++) {
            for (int y = 0; y < height; y++) {
                boolean isEmpty = fields[y][x];
                board += isEmpty ? 0 : (1L << (x * height + y));
            }
        }
        ColumnSmallField field = ColumnFieldFactory.createField(board);
        // parse to strings
        StringBuilder builder = new StringBuilder();
        for (int y = height - 1; 0 <= y; y--) {
            for (int x = 0; x < width; x++) {
                boolean isEmpty = fields[y][x];
                builder.append(isEmpty ? '_' : 'X');
            }
            if (y != 0)
                builder.append(lineSeparator);
        }
        String expect = builder.toString();
        assertThat(ColumnFieldView.toString(field, sizedBit)).isEqualTo(expect);
    }
}
Also used : Randoms(lib.Randoms) SizedBit(searcher.pack.SizedBit) Test(org.junit.jupiter.api.Test)

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