Search in sources :

Example 11 with InOutPairField

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

the class EasyPath method setUp.

public List<Result> setUp(String goalFieldMarks, Field initField, int width, int height) throws ExecutionException, InterruptedException {
    assert !initField.existsAbove(height);
    SizedBit sizedBit = new SizedBit(width, height);
    Field goalField = FieldFactory.createInverseField(goalFieldMarks);
    List<InOutPairField> inOutPairFields = InOutPairField.createInOutPairFields(sizedBit, goalField);
    // Create
    BasicSolutions basicSolutions = createMappedBasicSolutions(sizedBit);
    TaskResultHelper taskResultHelper = new Field4x10MinoPackingHelper();
    // Assert
    SolutionFilter solutionFilter = createSRSSolutionFilter(sizedBit, initField);
    // パフェ手順の列挙
    PerfectPackSearcher searcher = new PerfectPackSearcher(inOutPairFields, basicSolutions, sizedBit, solutionFilter, taskResultHelper);
    return searcher.toList();
}
Also used : ColumnField(core.column_field.ColumnField) InOutPairField(searcher.pack.InOutPairField) Field(core.field.Field) Field4x10MinoPackingHelper(searcher.pack.task.Field4x10MinoPackingHelper) SizedBit(searcher.pack.SizedBit) InOutPairField(searcher.pack.InOutPairField) SolutionFilter(searcher.pack.memento.SolutionFilter) SRSValidSolutionFilter(searcher.pack.memento.SRSValidSolutionFilter) PerfectPackSearcher(searcher.pack.task.PerfectPackSearcher) TaskResultHelper(searcher.pack.task.TaskResultHelper) MappedBasicSolutions(searcher.pack.solutions.MappedBasicSolutions) BasicSolutions(searcher.pack.calculator.BasicSolutions)

Example 12 with InOutPairField

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

the class EasyPath method buildUp.

public Set<LongPieces> buildUp(String goalFieldMarks, Field initField, int width, int height) throws ExecutionException, InterruptedException {
    assert !initField.existsAbove(height);
    SizedBit sizedBit = new SizedBit(width, height);
    Field goalField = FieldFactory.createInverseField(goalFieldMarks);
    List<InOutPairField> inOutPairFields = InOutPairField.createInOutPairFields(sizedBit, goalField);
    // Create
    BasicSolutions basicSolutions = createMappedBasicSolutions(sizedBit);
    TaskResultHelper taskResultHelper = new Field4x10MinoPackingHelper();
    // Assert
    SolutionFilter solutionFilter = createSRSSolutionFilter(sizedBit, initField);
    // パフェ手順の列挙
    PerfectPackSearcher searcher = new PerfectPackSearcher(inOutPairFields, basicSolutions, sizedBit, solutionFilter, taskResultHelper);
    LockedReachableThreadLocal reachableThreadLocal = easyPool.getLockedReachableThreadLocal(height);
    List<Result> results = searcher.toList();
    return results.stream().map(Result::getMemento).map(memento -> {
        return memento.getSeparableMinoStream(width).map(SeparableMino::toMinoOperationWithKey).collect(Collectors.toList());
    }).map(operations -> new BuildUpStream(reachableThreadLocal.get(), height).existsValidBuildPattern(initField, operations)).flatMap(listStream -> {
        return listStream.map(operationWithKeys -> {
            Stream<Piece> blocks = operationWithKeys.stream().map(OperationWithKey::getPiece);
            return new LongPieces(blocks);
        });
    }).collect(Collectors.toSet());
}
Also used : TaskResultHelper(searcher.pack.task.TaskResultHelper) RecursiveMinoFields(searcher.pack.mino_fields.RecursiveMinoFields) BasicSolutionsCalculator(searcher.pack.solutions.BasicSolutionsCalculator) LongPieces(common.datastore.blocks.LongPieces) ColumnField(core.column_field.ColumnField) SizedBit(searcher.pack.SizedBit) MinoFactory(core.mino.MinoFactory) Map(java.util.Map) SeparableMinos(searcher.pack.SeparableMinos) FieldFactory(core.field.FieldFactory) BuildUpStream(common.buildup.BuildUpStream) PerfectPackSearcher(searcher.pack.task.PerfectPackSearcher) OperationWithKey(common.datastore.OperationWithKey) Field4x10MinoPackingHelper(searcher.pack.task.Field4x10MinoPackingHelper) MinoShifter(core.mino.MinoShifter) MappedBasicSolutions(searcher.pack.solutions.MappedBasicSolutions) Piece(core.mino.Piece) Result(searcher.pack.task.Result) InOutPairField(searcher.pack.InOutPairField) Set(java.util.Set) Collectors(java.util.stream.Collectors) ExecutionException(java.util.concurrent.ExecutionException) SolutionFilter(searcher.pack.memento.SolutionFilter) List(java.util.List) Field(core.field.Field) BasicSolutions(searcher.pack.calculator.BasicSolutions) Stream(java.util.stream.Stream) SeparableMino(searcher.pack.separable_mino.SeparableMino) SRSValidSolutionFilter(searcher.pack.memento.SRSValidSolutionFilter) LockedReachableThreadLocal(concurrent.LockedReachableThreadLocal) Field4x10MinoPackingHelper(searcher.pack.task.Field4x10MinoPackingHelper) SeparableMino(searcher.pack.separable_mino.SeparableMino) TaskResultHelper(searcher.pack.task.TaskResultHelper) LockedReachableThreadLocal(concurrent.LockedReachableThreadLocal) MappedBasicSolutions(searcher.pack.solutions.MappedBasicSolutions) BasicSolutions(searcher.pack.calculator.BasicSolutions) Result(searcher.pack.task.Result) ColumnField(core.column_field.ColumnField) InOutPairField(searcher.pack.InOutPairField) Field(core.field.Field) SizedBit(searcher.pack.SizedBit) InOutPairField(searcher.pack.InOutPairField) LongPieces(common.datastore.blocks.LongPieces) SolutionFilter(searcher.pack.memento.SolutionFilter) SRSValidSolutionFilter(searcher.pack.memento.SRSValidSolutionFilter) PerfectPackSearcher(searcher.pack.task.PerfectPackSearcher) BuildUpStream(common.buildup.BuildUpStream) Stream(java.util.stream.Stream) BuildUpStream(common.buildup.BuildUpStream)

Example 13 with InOutPairField

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

the class PackSearcherTest method assertHeight5.

void assertHeight5(SizedBit sizedBit, int maxCount, BiFunction<Field, SolutionFilter, BasicSolutions> basicSolutionSupplier) throws ExecutionException, InterruptedException, SyntaxException {
    assert sizedBit.getWidth() == 2;
    assert sizedBit.getHeight() == 5;
    int width = sizedBit.getWidth();
    int height = sizedBit.getHeight();
    Randoms randoms = new Randoms();
    Candidate<Action> candidate = new LockedCandidate(minoFactory, minoShifter, minoRotation, height);
    LockedReachable reachable = new LockedReachable(minoFactory, minoShifter, minoRotation, height);
    TaskResultHelper taskResultHelper = new BasicMinoPackingHelper();
    for (int count = 0; count < maxCount; count++) {
        // Field
        int maxDepth = randoms.nextIntClosed(3, 6);
        Field initField = randoms.field(height, maxDepth);
        List<InOutPairField> inOutPairFields = InOutPairField.createInOutPairFields(sizedBit, initField);
        SolutionFilter solutionFilter = createSRSSolutionFilter(sizedBit, initField);
        // Pack
        BasicSolutions basicSolutions = basicSolutionSupplier.apply(initField, solutionFilter);
        PerfectPackSearcher searcher = new PerfectPackSearcher(inOutPairFields, basicSolutions, sizedBit, solutionFilter, taskResultHelper);
        List<Result> results = searcher.toList();
        // Possible
        HashSet<Pieces> possiblePieces = new HashSet<>();
        for (Result result : results) {
            // result to possible pieces
            List<MinoOperationWithKey> operationWithKeys = result.getMemento().getSeparableMinoStream(width).map(SeparableMino::toMinoOperationWithKey).collect(Collectors.toList());
            Set<LongPieces> sets = new BuildUpStream(reachable, height).existsValidBuildPattern(initField, operationWithKeys).map(keys -> keys.stream().map(OperationWithKey::getPiece)).map(LongPieces::new).collect(Collectors.toSet());
            possiblePieces.addAll(sets);
        }
        // Checker
        PerfectValidator validator = new PerfectValidator();
        CheckerNoHold<Action> checker = new CheckerNoHold<>(minoFactory, validator);
        // Assert generator
        PatternGenerator generator = createPiecesGenerator(maxDepth);
        generator.blocksStream().forEach(blocks -> {
            List<Piece> pieceList = blocks.getPieces();
            boolean check = checker.check(initField, pieceList, candidate, height, maxDepth);
            assertThat(possiblePieces.contains(blocks)).as(pieceList.toString()).isEqualTo(check);
        });
    }
}
Also used : Action(common.datastore.action.Action) LockedCandidate(core.action.candidate.LockedCandidate) Field(core.field.Field) ColumnSmallField(core.column_field.ColumnSmallField) ColumnField(core.column_field.ColumnField) InOutPairField(searcher.pack.InOutPairField) MinoOperationWithKey(common.datastore.MinoOperationWithKey) InOutPairField(searcher.pack.InOutPairField) LongPieces(common.datastore.blocks.LongPieces) Piece(core.mino.Piece) PerfectValidator(searcher.common.validator.PerfectValidator) BuildUpStream(common.buildup.BuildUpStream) Pieces(common.datastore.blocks.Pieces) LongPieces(common.datastore.blocks.LongPieces) HashSet(java.util.HashSet) PatternGenerator(common.pattern.PatternGenerator) LoadedPatternGenerator(common.pattern.LoadedPatternGenerator) FilterOnDemandBasicSolutions(searcher.pack.solutions.FilterOnDemandBasicSolutions) MappedBasicSolutions(searcher.pack.solutions.MappedBasicSolutions) BasicSolutions(searcher.pack.calculator.BasicSolutions) OnDemandBasicSolutions(searcher.pack.solutions.OnDemandBasicSolutions) Randoms(lib.Randoms) CheckerNoHold(searcher.checker.CheckerNoHold) SRSValidSolutionFilter(searcher.pack.memento.SRSValidSolutionFilter) AllPassedSolutionFilter(searcher.pack.memento.AllPassedSolutionFilter) SolutionFilter(searcher.pack.memento.SolutionFilter) LockedReachable(core.action.reachable.LockedReachable)

Example 14 with InOutPairField

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

the class PackSearcherTest method assertHeight4.

private void assertHeight4(SizedBit sizedBit, int maxCount, BiFunction<Field, SolutionFilter, BasicSolutions> basicSolutionSupplier) throws ExecutionException, InterruptedException, SyntaxException {
    assert sizedBit.getWidth() == 3;
    assert sizedBit.getHeight() == 4;
    int width = sizedBit.getWidth();
    int height = sizedBit.getHeight();
    Randoms randoms = new Randoms();
    Candidate<Action> candidate = new LockedCandidate(minoFactory, minoShifter, minoRotation, height);
    LockedReachable reachable = new LockedReachable(minoFactory, minoShifter, minoRotation, height);
    TaskResultHelper taskResultHelper = new Field4x10MinoPackingHelper();
    for (int count = 0; count < maxCount; count++) {
        // Field
        int maxDepth = randoms.nextIntClosed(3, 6);
        Field initField = randoms.field(height, maxDepth);
        List<InOutPairField> inOutPairFields = InOutPairField.createInOutPairFields(sizedBit, initField);
        SolutionFilter solutionFilter = createSRSSolutionFilter(sizedBit, initField);
        // Pack
        BasicSolutions basicSolutions = basicSolutionSupplier.apply(initField, solutionFilter);
        PerfectPackSearcher searcher = new PerfectPackSearcher(inOutPairFields, basicSolutions, sizedBit, solutionFilter, taskResultHelper);
        List<Result> results = searcher.toList();
        // Possible
        HashSet<Pieces> possiblePieces = new HashSet<>();
        for (Result result : results) {
            // result to possible pieces
            List<MinoOperationWithKey> operationWithKeys = result.getMemento().getSeparableMinoStream(width).map(SeparableMino::toMinoOperationWithKey).collect(Collectors.toList());
            Set<LongPieces> sets = new BuildUpStream(reachable, height).existsValidBuildPattern(initField, operationWithKeys).map(keys -> keys.stream().map(OperationWithKey::getPiece)).map(LongPieces::new).collect(Collectors.toSet());
            possiblePieces.addAll(sets);
        }
        // Checker
        PerfectValidator validator = new PerfectValidator();
        CheckerNoHold<Action> checker = new CheckerNoHold<>(minoFactory, validator);
        // Assert generator
        PatternGenerator generator = createPiecesGenerator(maxDepth);
        generator.blocksStream().forEach(blocks -> {
            List<Piece> pieceList = blocks.getPieces();
            boolean check = checker.check(initField, pieceList, candidate, height, maxDepth);
            assertThat(possiblePieces.contains(blocks)).as(pieceList.toString()).isEqualTo(check);
        });
    }
}
Also used : Action(common.datastore.action.Action) LockedCandidate(core.action.candidate.LockedCandidate) Field(core.field.Field) ColumnSmallField(core.column_field.ColumnSmallField) ColumnField(core.column_field.ColumnField) InOutPairField(searcher.pack.InOutPairField) MinoOperationWithKey(common.datastore.MinoOperationWithKey) InOutPairField(searcher.pack.InOutPairField) LongPieces(common.datastore.blocks.LongPieces) Piece(core.mino.Piece) PerfectValidator(searcher.common.validator.PerfectValidator) BuildUpStream(common.buildup.BuildUpStream) Pieces(common.datastore.blocks.Pieces) LongPieces(common.datastore.blocks.LongPieces) HashSet(java.util.HashSet) PatternGenerator(common.pattern.PatternGenerator) LoadedPatternGenerator(common.pattern.LoadedPatternGenerator) FilterOnDemandBasicSolutions(searcher.pack.solutions.FilterOnDemandBasicSolutions) MappedBasicSolutions(searcher.pack.solutions.MappedBasicSolutions) BasicSolutions(searcher.pack.calculator.BasicSolutions) OnDemandBasicSolutions(searcher.pack.solutions.OnDemandBasicSolutions) Randoms(lib.Randoms) CheckerNoHold(searcher.checker.CheckerNoHold) SRSValidSolutionFilter(searcher.pack.memento.SRSValidSolutionFilter) AllPassedSolutionFilter(searcher.pack.memento.AllPassedSolutionFilter) SolutionFilter(searcher.pack.memento.SolutionFilter) LockedReachable(core.action.reachable.LockedReachable)

Aggregations

InOutPairField (searcher.pack.InOutPairField)14 ColumnField (core.column_field.ColumnField)12 SolutionFilter (searcher.pack.memento.SolutionFilter)12 Field (core.field.Field)11 SizedBit (searcher.pack.SizedBit)11 TaskResultHelper (searcher.pack.task.TaskResultHelper)11 PerfectPackSearcher (searcher.pack.task.PerfectPackSearcher)10 SRSValidSolutionFilter (searcher.pack.memento.SRSValidSolutionFilter)9 OnDemandBasicSolutions (searcher.pack.solutions.OnDemandBasicSolutions)9 Field4x10MinoPackingHelper (searcher.pack.task.Field4x10MinoPackingHelper)9 MinoFactory (core.mino.MinoFactory)8 MinoShifter (core.mino.MinoShifter)8 Piece (core.mino.Piece)8 Randoms (lib.Randoms)8 SeparableMinos (searcher.pack.SeparableMinos)8 SeparableMino (searcher.pack.separable_mino.SeparableMino)8 Result (searcher.pack.task.Result)8 BuildUpStream (common.buildup.BuildUpStream)7 LockedReachableThreadLocal (concurrent.LockedReachableThreadLocal)7 Collectors (java.util.stream.Collectors)7