Search in sources :

Example 11 with Pieces

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

the class SingleCheckerNoHoldInvoker method search.

@Override
public List<Pair<Pieces, Boolean>> search(Field field, List<Pieces> searchingPieces, int maxClearLine, int maxDepth) throws FinderExecuteException {
    ConcurrentVisitedTree visitedTree = new ConcurrentVisitedTree();
    Obj obj = new Obj(field, maxClearLine, maxDepth, visitedTree);
    try {
        ArrayList<Pair<Pieces, Boolean>> results = new ArrayList<>();
        for (Pieces target : searchingPieces) {
            Task task = new Task(obj, commonObj, target);
            results.add(task.call());
        }
        return results;
    } catch (Exception e) {
        throw new FinderExecuteException(e);
    }
}
Also used : CheckerCommonObj(concurrent.checker.invoker.CheckerCommonObj) ArrayList(java.util.ArrayList) FinderExecuteException(exceptions.FinderExecuteException) ConcurrentVisitedTree(common.tree.ConcurrentVisitedTree) FinderExecuteException(exceptions.FinderExecuteException) Pair(common.datastore.Pair) Pieces(common.datastore.blocks.Pieces)

Example 12 with Pieces

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

the class ConcurrentCheckerUsingHoldInvoker method search.

@Override
public List<Pair<Pieces, Boolean>> search(Field field, List<Pieces> searchingPieces, int maxClearLine, int maxDepth) throws FinderExecuteException {
    ConcurrentVisitedTree visitedTree = new ConcurrentVisitedTree();
    Obj obj = new Obj(field, maxClearLine, maxDepth, visitedTree);
    ArrayList<Task> tasks = new ArrayList<>();
    for (Pieces target : searchingPieces) tasks.add(new Task(obj, commonObj, target));
    try {
        return execute(tasks);
    } catch (InterruptedException | ExecutionException e) {
        throw new FinderExecuteException(e);
    }
}
Also used : CheckerCommonObj(concurrent.checker.invoker.CheckerCommonObj) ArrayList(java.util.ArrayList) ExecutionException(java.util.concurrent.ExecutionException) FinderExecuteException(exceptions.FinderExecuteException) ConcurrentVisitedTree(common.tree.ConcurrentVisitedTree) Pieces(common.datastore.blocks.Pieces)

Example 13 with Pieces

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

the class SingleCheckerUsingHoldInvoker method search.

@Override
public List<Pair<Pieces, Boolean>> search(Field field, List<Pieces> searchingPieces, int maxClearLine, int maxDepth) throws FinderExecuteException {
    ConcurrentVisitedTree visitedTree = new ConcurrentVisitedTree();
    Obj obj = new Obj(field, maxClearLine, maxDepth, visitedTree);
    ArrayList<Pair<Pieces, Boolean>> results = new ArrayList<>();
    try {
        for (Pieces target : searchingPieces) {
            Task task = new Task(obj, commonObj, target);
            Pair<Pieces, Boolean> call = task.call();
            results.add(call);
        }
    } catch (Exception e) {
        throw new FinderExecuteException(e);
    }
    // 結果をリストに追加する
    return results;
}
Also used : CheckerCommonObj(concurrent.checker.invoker.CheckerCommonObj) ArrayList(java.util.ArrayList) FinderExecuteException(exceptions.FinderExecuteException) ConcurrentVisitedTree(common.tree.ConcurrentVisitedTree) ExecutionException(java.util.concurrent.ExecutionException) FinderExecuteException(exceptions.FinderExecuteException) Pair(common.datastore.Pair) Pieces(common.datastore.blocks.Pieces)

Example 14 with Pieces

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

the class PackSearcherComparingParityBasedOnDemandTest method testAllSRSValidPacksHeight4.

// 高さ4: パリティベースとの探索結果を比較する (同一ミノは2つまで)
@Test
@LongTest
void testAllSRSValidPacksHeight4() throws Exception {
    int width = 3;
    int height = 4;
    String resultPath = ClassLoader.getSystemResource("perfects/pack_height4.txt").getPath();
    List<TestData> testCases = Files.lines(Paths.get(resultPath)).map(line -> line.split("//")[0]).map(String::trim).filter(line -> !line.isEmpty()).map(line -> line.split("=")).map(split -> {
        Stream<Piece> blocks = BlockInterpreter.parse(split[0]);
        LongPieces pieces = new LongPieces(blocks);
        int count = Integer.valueOf(split[1]);
        return new TestData(pieces, count);
    }).collect(Collectors.toList());
    compareCount(width, height, testCases);
}
Also used : Pieces(common.datastore.blocks.Pieces) Assertions.assertThat(org.assertj.core.api.Assertions.assertThat) LongPieces(common.datastore.blocks.LongPieces) ColumnField(core.column_field.ColumnField) FilterWrappedBasicSolutions(searcher.pack.solutions.FilterWrappedBasicSolutions) HashSet(java.util.HashSet) PieceCounter(common.datastore.PieceCounter) SizedBit(searcher.pack.SizedBit) MinoFactory(core.mino.MinoFactory) SeparableMinos(searcher.pack.SeparableMinos) CombinationIterable(common.iterable.CombinationIterable) FieldFactory(core.field.FieldFactory) Tag(org.junit.jupiter.api.Tag) MinoShifter(core.mino.MinoShifter) Piece(core.mino.Piece) Files(java.nio.file.Files) Predicate(java.util.function.Predicate) InOutPairField(searcher.pack.InOutPairField) Set(java.util.Set) BlockInterpreter(common.parser.BlockInterpreter) Collectors(java.util.stream.Collectors) Test(org.junit.jupiter.api.Test) UsingBlockAndValidKeySolutionFilter(searcher.pack.memento.UsingBlockAndValidKeySolutionFilter) 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) Paths(java.nio.file.Paths) OnDemandBasicSolutions(searcher.pack.solutions.OnDemandBasicSolutions) LockedReachableThreadLocal(concurrent.LockedReachableThreadLocal) LongTest(module.LongTest) Collections(java.util.Collections) LongPieces(common.datastore.blocks.LongPieces) Stream(java.util.stream.Stream) Test(org.junit.jupiter.api.Test) LongTest(module.LongTest) LongTest(module.LongTest)

Example 15 with Pieces

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

the class PackSearcherComparingParityBasedOnDemandTest method testAllSRSValidPacksHeight5.

// 高さ5: パリティベースとの探索結果を比較する (同一ミノは2つまで)
@Test
void testAllSRSValidPacksHeight5() throws Exception {
    int width = 2;
    int height = 5;
    String resultPath = ClassLoader.getSystemResource("perfects/pack_height5.txt").getPath();
    List<TestData> testCases = Files.lines(Paths.get(resultPath)).map(line -> line.split("//")[0]).map(String::trim).filter(line -> !line.isEmpty()).map(line -> line.split("=")).map(split -> {
        Stream<Piece> blocks = BlockInterpreter.parse(split[0]);
        LongPieces pieces = new LongPieces(blocks);
        int count = Integer.valueOf(split[1]);
        return new TestData(pieces, count);
    }).collect(Collectors.toList());
    compareCount(width, height, testCases);
}
Also used : Pieces(common.datastore.blocks.Pieces) Assertions.assertThat(org.assertj.core.api.Assertions.assertThat) LongPieces(common.datastore.blocks.LongPieces) ColumnField(core.column_field.ColumnField) FilterWrappedBasicSolutions(searcher.pack.solutions.FilterWrappedBasicSolutions) HashSet(java.util.HashSet) PieceCounter(common.datastore.PieceCounter) SizedBit(searcher.pack.SizedBit) MinoFactory(core.mino.MinoFactory) SeparableMinos(searcher.pack.SeparableMinos) CombinationIterable(common.iterable.CombinationIterable) FieldFactory(core.field.FieldFactory) Tag(org.junit.jupiter.api.Tag) MinoShifter(core.mino.MinoShifter) Piece(core.mino.Piece) Files(java.nio.file.Files) Predicate(java.util.function.Predicate) InOutPairField(searcher.pack.InOutPairField) Set(java.util.Set) BlockInterpreter(common.parser.BlockInterpreter) Collectors(java.util.stream.Collectors) Test(org.junit.jupiter.api.Test) UsingBlockAndValidKeySolutionFilter(searcher.pack.memento.UsingBlockAndValidKeySolutionFilter) 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) Paths(java.nio.file.Paths) OnDemandBasicSolutions(searcher.pack.solutions.OnDemandBasicSolutions) LockedReachableThreadLocal(concurrent.LockedReachableThreadLocal) LongTest(module.LongTest) Collections(java.util.Collections) LongPieces(common.datastore.blocks.LongPieces) Stream(java.util.stream.Stream) Test(org.junit.jupiter.api.Test) LongTest(module.LongTest)

Aggregations

Pieces (common.datastore.blocks.Pieces)25 Field (core.field.Field)16 LongPieces (common.datastore.blocks.LongPieces)13 MinoFactory (core.mino.MinoFactory)12 Piece (core.mino.Piece)12 PatternGenerator (common.pattern.PatternGenerator)10 MinoShifter (core.mino.MinoShifter)10 ExecutionException (java.util.concurrent.ExecutionException)9 Test (org.junit.jupiter.api.Test)9 ColumnField (core.column_field.ColumnField)8 Collectors (java.util.stream.Collectors)8 LongTest (module.LongTest)8 PieceCounter (common.datastore.PieceCounter)7 BlockInterpreter (common.parser.BlockInterpreter)7 LoadedPatternGenerator (common.pattern.LoadedPatternGenerator)7 FieldFactory (core.field.FieldFactory)7 Files (java.nio.file.Files)7 Paths (java.nio.file.Paths)7 Stream (java.util.stream.Stream)7 SizedBit (searcher.pack.SizedBit)7