Search in sources :

Example 11 with LockedReachableThreadLocal

use of concurrent.LockedReachableThreadLocal 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)

Example 12 with LockedReachableThreadLocal

use of concurrent.LockedReachableThreadLocal in project solution-finder by knewjade.

the class PercentCoreTest method assertPercentCore.

private void assertPercentCore(Obj obj, double successPercent) throws Exception {
    PatternGenerator generator = new LoadedPatternGenerator(obj.patterns);
    NormalEnumeratePieces enumeratePieces = new NormalEnumeratePieces(generator, obj.maxDepth, obj.isUsingHold);
    Set<LongPieces> blocks = enumeratePieces.enumerate();
    Injector injector = Guice.createInjector(new BasicModule(obj.maxClearLine));
    Optional<ExecutorService> executorService = obj.isSingleThread ? Optional.empty() : Optional.of(injector.getInstance(ExecutorService.class));
    LockedCandidateThreadLocal candidateThreadLocal = injector.getInstance(LockedCandidateThreadLocal.class);
    LockedReachableThreadLocal reachableThreadLocal = injector.getInstance(LockedReachableThreadLocal.class);
    MinoFactory minoFactory = injector.getInstance(MinoFactory.class);
    PercentCore percentCore = getPercentCore(obj, executorService.orElse(null), candidateThreadLocal, reachableThreadLocal, minoFactory);
    Field field = FieldFactory.createField(obj.marks);
    percentCore.run(field, blocks, obj.maxClearLine, obj.maxDepth);
    executorService.ifPresent(ExecutorService::shutdown);
    assertThat(percentCore.getResultTree().getSuccessPercent()).isEqualTo(successPercent);
}
Also used : PatternGenerator(common.pattern.PatternGenerator) LoadedPatternGenerator(common.pattern.LoadedPatternGenerator) BasicModule(module.BasicModule) LoadedPatternGenerator(common.pattern.LoadedPatternGenerator) LockedReachableThreadLocal(concurrent.LockedReachableThreadLocal) Field(core.field.Field) LongPieces(common.datastore.blocks.LongPieces) Injector(com.google.inject.Injector) LockedCandidateThreadLocal(concurrent.LockedCandidateThreadLocal) NormalEnumeratePieces(entry.searching_pieces.NormalEnumeratePieces) ExecutorService(java.util.concurrent.ExecutorService) MinoFactory(core.mino.MinoFactory)

Aggregations

LockedReachableThreadLocal (concurrent.LockedReachableThreadLocal)12 Field (core.field.Field)10 MinoFactory (core.mino.MinoFactory)10 Piece (core.mino.Piece)10 Collectors (java.util.stream.Collectors)9 ColumnField (core.column_field.ColumnField)7 FieldFactory (core.field.FieldFactory)7 MinoShifter (core.mino.MinoShifter)7 Predicate (java.util.function.Predicate)7 InOutPairField (searcher.pack.InOutPairField)7 SeparableMinos (searcher.pack.SeparableMinos)7 SizedBit (searcher.pack.SizedBit)7 SolutionFilter (searcher.pack.memento.SolutionFilter)7 SeparableMino (searcher.pack.separable_mino.SeparableMino)7 Field4x10MinoPackingHelper (searcher.pack.task.Field4x10MinoPackingHelper)7 PerfectPackSearcher (searcher.pack.task.PerfectPackSearcher)7 Result (searcher.pack.task.Result)7 TaskResultHelper (searcher.pack.task.TaskResultHelper)7 FieldView (core.field.FieldView)6 MinoRotation (core.srs.MinoRotation)6