Search in sources :

Example 6 with PieceCounter

use of common.datastore.PieceCounter 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 7 with PieceCounter

use of common.datastore.PieceCounter in project solution-finder by knewjade.

the class PackSearcherComparingParityBasedOnDemandTest method createUsingBlockAndValidKeyMementoFilter.

// パフェするまでに有効なブロック数を列挙する
private SolutionFilter createUsingBlockAndValidKeyMementoFilter(Field initField, SizedBit sizedBit, Set<PieceCounter> counters) {
    HashSet<Long> validBlockCounters = new HashSet<>();
    for (PieceCounter counter : counters) {
        List<Piece> usingPieces = counter.getBlocks();
        for (int size = 1; size <= usingPieces.size(); size++) {
            CombinationIterable<Piece> combinationIterable = new CombinationIterable<>(usingPieces, size);
            for (List<Piece> pieces : combinationIterable) {
                PieceCounter newCounter = new PieceCounter(pieces);
                validBlockCounters.add(newCounter.getCounter());
            }
        }
    }
    LockedReachableThreadLocal reachableThreadLocal = new LockedReachableThreadLocal(sizedBit.getHeight());
    return new UsingBlockAndValidKeySolutionFilter(initField, validBlockCounters, reachableThreadLocal, sizedBit);
}
Also used : CombinationIterable(common.iterable.CombinationIterable) PieceCounter(common.datastore.PieceCounter) Piece(core.mino.Piece) UsingBlockAndValidKeySolutionFilter(searcher.pack.memento.UsingBlockAndValidKeySolutionFilter) LockedReachableThreadLocal(concurrent.LockedReachableThreadLocal) HashSet(java.util.HashSet)

Example 8 with PieceCounter

use of common.datastore.PieceCounter in project solution-finder by knewjade.

the class PackSearcherComparingParityBasedTest method createUsingBlockAndValidKeyMementoFilter.

// パフェするまでに有効なブロック数を列挙する
private SolutionFilter createUsingBlockAndValidKeyMementoFilter(Field initField, SizedBit sizedBit, Set<PieceCounter> counters) {
    HashSet<Long> validBlockCounters = new HashSet<>();
    for (PieceCounter counter : counters) {
        List<Piece> usingPieces = counter.getBlocks();
        for (int size = 1; size <= usingPieces.size(); size++) {
            CombinationIterable<Piece> combinationIterable = new CombinationIterable<>(usingPieces, size);
            for (List<Piece> pieces : combinationIterable) {
                PieceCounter newCounter = new PieceCounter(pieces);
                validBlockCounters.add(newCounter.getCounter());
            }
        }
    }
    LockedReachableThreadLocal reachableThreadLocal = new LockedReachableThreadLocal(sizedBit.getHeight());
    return new UsingBlockAndValidKeySolutionFilter(initField, validBlockCounters, reachableThreadLocal, sizedBit);
}
Also used : CombinationIterable(common.iterable.CombinationIterable) PieceCounter(common.datastore.PieceCounter) Piece(core.mino.Piece) UsingBlockAndValidKeySolutionFilter(searcher.pack.memento.UsingBlockAndValidKeySolutionFilter) LockedReachableThreadLocal(concurrent.LockedReachableThreadLocal)

Aggregations

PieceCounter (common.datastore.PieceCounter)8 Piece (core.mino.Piece)8 Field (core.field.Field)5 SizedBit (searcher.pack.SizedBit)4 UsingBlockAndValidKeySolutionFilter (searcher.pack.memento.UsingBlockAndValidKeySolutionFilter)4 LockedReachableThreadLocal (concurrent.LockedReachableThreadLocal)3 Collectors (java.util.stream.Collectors)3 CombinationIterable (common.iterable.CombinationIterable)2 PatternGenerator (common.pattern.PatternGenerator)2 ColumnField (core.column_field.ColumnField)2 PathEntryPoint (entry.path.PathEntryPoint)2 PathPair (entry.path.PathPair)2 PathSettings (entry.path.PathSettings)2 ReducePatternGenerator (entry.path.ReducePatternGenerator)2 FinderExecuteException (exceptions.FinderExecuteException)2 FinderInitializeException (exceptions.FinderInitializeException)2 File (java.io.File)2 IOException (java.io.IOException)2 Comparator (java.util.Comparator)2 HashSet (java.util.HashSet)2