Search in sources :

Example 6 with Operations

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

the class PathCSVCaseTest method none1.

@Test
void none1() throws Exception {
    // フォーマットをCSV
    /*
            comment: 4 -p I,*p6
            X_________
            XXXXX_____
            XXXXX_____
            XXXXX_____
             */
    String tetfu = "v115@9gA8IeE8EeE8EeE8OeAgWQA0no2ANI98AwN88AjPEN?B";
    int height = 4;
    ConfigFileHelper.createFieldFile(FieldFactory.createField(height), height);
    ConfigFileHelper.createPatternFile("*p2");
    String command = String.format("path -t %s -f csv -k none", tetfu);
    Log log = RunnerHelper.runnerCatchingLog(() -> EntryPointMain.main(command.split(" ")));
    assertThat(log.getOutput()).contains("I,*p6").contains(Messages.clearLine(4)).contains(Messages.uniqueCount(186)).contains(Messages.minimalCount(142)).contains(Messages.useHold());
    assertThat(log.getReturnCode()).isEqualTo(0);
    Field field = FieldFactory.createField("" + "X_________" + "XXXXX_____" + "XXXXX_____" + "XXXXX_____");
    // unique
    PathCSV uniqueCSV = OutputFileHelper.loadPathUniqueNoneCSV();
    assertThat(uniqueCSV.operations().stream().map(operations -> {
        Field freeze = field.freeze(height);
        for (Operation operation : operations.getOperations()) {
            freeze.put(new Mino(operation.getPiece(), operation.getRotate()), operation.getX(), operation.getY());
            freeze.clearLine();
        }
        return freeze;
    })).hasSize(186).allMatch(Field::isPerfect);
    // minimal
    PathCSV minimalCSV = OutputFileHelper.loadPathMinimalNoneCSV();
    assertThat(minimalCSV.operations().stream().map(operations -> {
        Field freeze = field.freeze(height);
        for (Operation operation : operations.getOperations()) {
            freeze.put(new Mino(operation.getPiece(), operation.getRotate()), operation.getX(), operation.getY());
            freeze.clearLine();
        }
        return freeze;
    })).hasSize(142).allMatch(Field::isPerfect);
}
Also used : SimpleOperation(common.datastore.SimpleOperation) CSVStore(helper.CSVStore) BeforeEach(org.junit.jupiter.api.BeforeEach) Piece(core.mino.Piece) Arrays(java.util.Arrays) Assertions.assertThat(org.assertj.core.api.Assertions.assertThat) IOException(java.io.IOException) Rotate(core.srs.Rotate) EntryPointMain(entry.EntryPointMain) Assertions.entry(org.assertj.core.api.Assertions.entry) Test(org.junit.jupiter.api.Test) Operations(common.datastore.Operations) Field(core.field.Field) _usecase(_usecase) Operation(common.datastore.Operation) FieldFactory(core.field.FieldFactory) Mino(core.mino.Mino) Field(core.field.Field) Mino(core.mino.Mino) SimpleOperation(common.datastore.SimpleOperation) Operation(common.datastore.Operation) Test(org.junit.jupiter.api.Test)

Example 7 with Operations

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

the class OperationInterpreterTest method parseToOperations.

@Test
void parseToOperations() throws Exception {
    String base = "T,0,1,0;L,2,1,2;I,L,3,1;J,2,1,3";
    Operations operations = OperationInterpreter.parseToOperations(base);
    String str = OperationInterpreter.parseToString(operations);
    assertThat(base).isEqualTo(str);
}
Also used : Operations(common.datastore.Operations) Test(org.junit.jupiter.api.Test)

Example 8 with Operations

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

the class OperationTransformTest method parseToOperationWithKeys2.

@Test
void parseToOperationWithKeys2() throws Exception {
    Field field = FieldFactory.createField(4);
    String base = "T,2,5,1;I,0,2,0;I,0,7,0;I,L,0,1";
    Operations operations = OperationInterpreter.parseToOperations(base);
    MinoFactory minoFactory = new MinoFactory();
    List<MinoOperationWithKey> operationWithKeys = OperationTransform.parseToOperationWithKeys(field, operations, minoFactory, 4);
    String line = OperationWithKeyInterpreter.parseToString(operationWithKeys);
    assertThat(line).isEqualTo("T,2,5,1,0,1025;I,0,2,0,0,1;I,0,7,0,0,1;I,L,0,1,0,1074791425");
}
Also used : ColumnField(core.column_field.ColumnField) InOutPairField(searcher.pack.InOutPairField) Field(core.field.Field) MinoOperationWithKey(common.datastore.MinoOperationWithKey) MinoFactory(core.mino.MinoFactory) Operations(common.datastore.Operations) Test(org.junit.jupiter.api.Test) LongTest(module.LongTest)

Example 9 with Operations

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

the class OperationTransformTest method parseToOperations.

@Test
void parseToOperations() throws Exception {
    Field field = FieldFactory.createField("" + "____XXXXXX" + "____XXXXXX" + "____XXXXXX" + "____XXXXXX" + "");
    String base = "J,2,2,1;I,0,1,2;J,R,0,1;S,0,2,0";
    Operations operations = OperationInterpreter.parseToOperations(base);
    MinoFactory minoFactory = new MinoFactory();
    List<MinoOperationWithKey> operationWithKeys = OperationTransform.parseToOperationWithKeys(field, operations, minoFactory, 4);
    Operations restoreOperations = OperationTransform.parseToOperations(field, operationWithKeys, 4);
    assertThat(restoreOperations).isEqualTo(operations);
}
Also used : ColumnField(core.column_field.ColumnField) InOutPairField(searcher.pack.InOutPairField) Field(core.field.Field) MinoOperationWithKey(common.datastore.MinoOperationWithKey) MinoFactory(core.mino.MinoFactory) Operations(common.datastore.Operations) Test(org.junit.jupiter.api.Test) LongTest(module.LongTest)

Example 10 with Operations

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

the class OperationTransformTest method randomParse.

@Test
@LongTest
void randomParse() throws Exception {
    // Initialize
    Randoms randoms = new Randoms();
    MinoFactory minoFactory = new MinoFactory();
    MinoShifter minoShifter = new MinoShifter();
    MinoRotation minoRotation = new MinoRotation();
    // Define size
    int height = 4;
    int basicWidth = 3;
    SizedBit sizedBit = new SizedBit(basicWidth, height);
    SeparableMinos separableMinos = SeparableMinos.createSeparableMinos(minoFactory, minoShifter, sizedBit);
    // Create basic solutions
    TaskResultHelper taskResultHelper = new Field4x10MinoPackingHelper();
    LockedReachableThreadLocal lockedReachableThreadLocal = new LockedReachableThreadLocal(minoFactory, minoShifter, minoRotation, height);
    Predicate<ColumnField> memorizedPredicate = (columnField) -> true;
    OnDemandBasicSolutions basicSolutions = new OnDemandBasicSolutions(separableMinos, sizedBit, memorizedPredicate);
    for (int count = 0; count < 100; count++) {
        // Create field
        int numOfMinos = randoms.nextInt(6, 10);
        Field field = randoms.field(height, numOfMinos);
        // Search
        List<InOutPairField> inOutPairFields = InOutPairField.createInOutPairFields(basicWidth, height, field);
        SolutionFilter solutionFilter = new SRSValidSolutionFilter(field, lockedReachableThreadLocal, sizedBit);
        PerfectPackSearcher searcher = new PerfectPackSearcher(inOutPairFields, basicSolutions, sizedBit, solutionFilter, taskResultHelper);
        Optional<Result> resultOptional = searcher.findAny();
        OperationWithKeyComparator<MinoOperationWithKey> operationWithKeyComparator = new OperationWithKeyComparator<>();
        ListComparator<MinoOperationWithKey> comparator = new ListComparator<>(operationWithKeyComparator);
        BuildUpStream buildUpStream = new BuildUpStream(lockedReachableThreadLocal.get(), height);
        // If found solution
        resultOptional.ifPresent(result -> {
            List<MinoOperationWithKey> list = result.getMemento().getSeparableMinoStream(basicWidth).map(SeparableMino::toMinoOperationWithKey).collect(Collectors.toList());
            Optional<List<MinoOperationWithKey>> validOption = buildUpStream.existsValidBuildPattern(field, list).findAny();
            validOption.ifPresent(operationWithKeys -> {
                Operations operations = OperationTransform.parseToOperations(field, operationWithKeys, height);
                List<MinoOperationWithKey> actual = OperationTransform.parseToOperationWithKeys(field, operations, minoFactory, height);
                assertThat(comparator.compare(operationWithKeys, actual)).as("%s%n%s%n %s", FieldView.toString(field, height), OperationWithKeyInterpreter.parseToString(operationWithKeys), OperationWithKeyInterpreter.parseToString(actual)).isEqualTo(0);
            });
        });
    }
}
Also used : TaskResultHelper(searcher.pack.task.TaskResultHelper) Randoms(lib.Randoms) ListComparator(lib.ListComparator) OperationWithKeyComparator(common.comparator.OperationWithKeyComparator) Assertions.assertThat(org.assertj.core.api.Assertions.assertThat) ColumnField(core.column_field.ColumnField) MinoOperationWithKey(common.datastore.MinoOperationWithKey) FieldView(core.field.FieldView) SizedBit(searcher.pack.SizedBit) MinoFactory(core.mino.MinoFactory) SeparableMinos(searcher.pack.SeparableMinos) FieldFactory(core.field.FieldFactory) Tag(org.junit.jupiter.api.Tag) MinoRotation(core.srs.MinoRotation) BuildUpStream(common.buildup.BuildUpStream) PerfectPackSearcher(searcher.pack.task.PerfectPackSearcher) Field4x10MinoPackingHelper(searcher.pack.task.Field4x10MinoPackingHelper) MinoShifter(core.mino.MinoShifter) Predicate(java.util.function.Predicate) Result(searcher.pack.task.Result) InOutPairField(searcher.pack.InOutPairField) Collectors(java.util.stream.Collectors) Test(org.junit.jupiter.api.Test) Operations(common.datastore.Operations) SolutionFilter(searcher.pack.memento.SolutionFilter) List(java.util.List) Field(core.field.Field) SeparableMino(searcher.pack.separable_mino.SeparableMino) SRSValidSolutionFilter(searcher.pack.memento.SRSValidSolutionFilter) Optional(java.util.Optional) OnDemandBasicSolutions(searcher.pack.solutions.OnDemandBasicSolutions) LockedReachableThreadLocal(concurrent.LockedReachableThreadLocal) LongTest(module.LongTest) OnDemandBasicSolutions(searcher.pack.solutions.OnDemandBasicSolutions) ListComparator(lib.ListComparator) TaskResultHelper(searcher.pack.task.TaskResultHelper) LockedReachableThreadLocal(concurrent.LockedReachableThreadLocal) Result(searcher.pack.task.Result) ColumnField(core.column_field.ColumnField) InOutPairField(searcher.pack.InOutPairField) Field(core.field.Field) MinoOperationWithKey(common.datastore.MinoOperationWithKey) SeparableMinos(searcher.pack.SeparableMinos) InOutPairField(searcher.pack.InOutPairField) PerfectPackSearcher(searcher.pack.task.PerfectPackSearcher) OperationWithKeyComparator(common.comparator.OperationWithKeyComparator) MinoFactory(core.mino.MinoFactory) List(java.util.List) BuildUpStream(common.buildup.BuildUpStream) Operations(common.datastore.Operations) Field4x10MinoPackingHelper(searcher.pack.task.Field4x10MinoPackingHelper) ColumnField(core.column_field.ColumnField) MinoRotation(core.srs.MinoRotation) Randoms(lib.Randoms) SizedBit(searcher.pack.SizedBit) SRSValidSolutionFilter(searcher.pack.memento.SRSValidSolutionFilter) SolutionFilter(searcher.pack.memento.SolutionFilter) SRSValidSolutionFilter(searcher.pack.memento.SRSValidSolutionFilter) MinoShifter(core.mino.MinoShifter) Test(org.junit.jupiter.api.Test) LongTest(module.LongTest) LongTest(module.LongTest)

Aggregations

Operations (common.datastore.Operations)13 Field (core.field.Field)11 MinoOperationWithKey (common.datastore.MinoOperationWithKey)10 Test (org.junit.jupiter.api.Test)10 MinoFactory (core.mino.MinoFactory)9 ColumnField (core.column_field.ColumnField)7 LongTest (module.LongTest)7 InOutPairField (searcher.pack.InOutPairField)7 Piece (core.mino.Piece)6 List (java.util.List)6 Collectors (java.util.stream.Collectors)6 OperationTransform (common.parser.OperationTransform)5 MinoShifter (core.mino.MinoShifter)5 MinoRotation (core.srs.MinoRotation)5 Randoms (lib.Randoms)5 Assertions.assertThat (org.assertj.core.api.Assertions.assertThat)5 SizedBit (searcher.pack.SizedBit)5 SeparableMino (searcher.pack.separable_mino.SeparableMino)5 Result (searcher.pack.task.Result)5 Operation (common.datastore.Operation)4