public IEnumerable <ICommand> Solve()
        {
            // disassembleSource = source
            // disassembleTarget = (source & target)
            // assembleSource = (source & target)
            // assembleTarget = target
            var commonPart = source.Intersect(target);

            commonPart = new ComponentTrackingMatrix(commonPart).GetGroundedVoxels();
            var d = disassembler(source, commonPart);
            var a = assembler(commonPart, target);

            foreach (var command in d.Solve())
            {
                if (command is Halt)
                {
                    continue;
                }
                yield return(command);
            }
            foreach (var command in a.Solve())
            {
                yield return(command);
            }
        }
Beispiel #2
0
        public void TrackComponents()
        {
            var componentTrackingMatrix = new ComponentTrackingMatrix(new Matrix("10|01", "00|00"));

            componentTrackingMatrix[0, 1, 0] = true;
            componentTrackingMatrix.HasNonGroundedVoxels.Should().BeFalse();
        }
Beispiel #3
0
        public void Temp([Values(3)] int problemId)
        {
            var problem = ProblemSolutionFactory.LoadProblem($"FR{problemId:D3}");
            //var assembler = new GreedyPartialSolver(problem.TargetMatrix, new ThrowableHelperFast(problem.TargetMatrix));
            //var disassembler = new InvertorDisassembler(new GreedyPartialSolver(problem.SourceMatrix, new ThrowableHelperFast(problem.SourceMatrix)), problem.SourceMatrix);
            //var solver = new SimpleReassembler(disassembler, assembler);
            var commonPart = problem.SourceMatrix.Intersect(problem.TargetMatrix);

            commonPart = new ComponentTrackingMatrix(commonPart).GetGroundedVoxels();

            File.WriteAllBytes(Path.Combine(FileHelper.ProblemsDir, "FR666_tgt.mdl"), commonPart.Save());
            File.WriteAllBytes(Path.Combine(FileHelper.ProblemsDir, "FR666_src.mdl"), commonPart.Save());
            var             solver   = new GreedyPartialSolver(problem.SourceMatrix, commonPart, new ThrowableHelperFast(commonPart, problem.SourceMatrix));
            List <ICommand> commands = new List <ICommand>();

            try
            {
                foreach (var command in solver.Solve())
                {
                    commands.Add(command);
                }
                //commands.AddRange(solver.Solve());
            }
            catch (Exception e)
            {
                Log.For(this).Error($"Unhandled exception in solver for {problem.Name}", e);
                throw;
            }
            finally
            {
                Console.WriteLine(commands.Take(5000).ToDelimitedString("\n"));
                var bytes = CommandSerializer.Save(commands.ToArray());
                File.WriteAllBytes(GetSolutionPath(FileHelper.SolutionsDir, "FR666"), bytes);
            }
        }
Beispiel #4
0
        public void HasNotGrounded(params string[] matrix)
        {
            var componentTrackingMatrix = new ComponentTrackingMatrix(new Matrix(matrix));

            componentTrackingMatrix.HasNonGroundedVoxels.Should().BeTrue();
        }