Ejemplo n.º 1
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);
            }
        }
Ejemplo n.º 2
0
        public void Disassemble()
        {
            var problem = ProblemSolutionFactory.LoadProblem("FD120");
            //var solver = new InvertorDisassembler(new DivideAndConquer(problem.SourceMatrix, true), problem.SourceMatrix);
            //var solver = new InvertorDisassembler(new GreedyPartialSolver(problem.SourceMatrix, new Matrix(problem.R), new ThrowableHelperFast(problem.SourceMatrix)), problem.SourceMatrix);
            var solver = new InvertorDisassembler(new HorizontalSlicer(problem.SourceMatrix, 6, 6, true), problem.SourceMatrix);
            //var solver = new HorizontalSlicer(problem.SourceMatrix, 6, 6, true);
            List <ICommand> commands = new List <ICommand>();

            try
            {
                commands.AddRange(solver.Solve());
            }
            catch (Exception e)
            {
                Log.For(this).Error($"Unhandled exception in solver for {problem.Name}", e);
                throw;
            }
            finally
            {
                var bytes = CommandSerializer.Save(commands.ToArray());
                File.WriteAllBytes(GetSolutionPath(FileHelper.SolutionsDir, problem.Name), bytes);
            }
            var state = new DeluxeState(problem.SourceMatrix, problem.TargetMatrix);

            new Interpreter(state).Run(commands);
        }
Ejemplo n.º 3
0
        public void DisassembleAndPost([Values(4)] int problemId)
        {
            var problem = ProblemSolutionFactory.LoadProblem($"FD{problemId:D3}");
            //var solution = ProblemSolutionFactory.blockDeconstructor;
            var solution = ProblemSolutionFactory.CreateInvertingDisassembler(ProblemSolutionFactory.CreateSlicerAssembler(6, 6));

            Evaluate(problem, solution, postToElastic: true);
        }
Ejemplo n.º 4
0
        public void Test2()
        {
            var problem = ProblemSolutionFactory.LoadProblem("FA001");
            var state   = new DeluxeState(problem.SourceMatrix, problem.TargetMatrix);
            var plan    = new GenPlanBuilder(state).CreateGenPlan();
            var sorted  = new GenPlanSorter(plan, state.R).Sort();

            sorted.ToHashSet().SetEquals(plan).Should().BeTrue();
        }
Ejemplo n.º 5
0
        public void AssembleAndPost([Values(11)] int problemId)
        {
            var problem  = ProblemSolutionFactory.LoadProblem($"FA{problemId:D3}");
            var solution = new Solution
            {
                Name   = "special",
                Solver = p =>
                {
                    var state = new DeluxeState(p.SourceMatrix, p.TargetMatrix);
                    return(new Solver(state, new AssembleFA11(state)));
                }
            };

            Evaluate(problem, solution, postToElastic: true);
        }
Ejemplo n.º 6
0
        public void Reassemble([Values(75)] 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(
                new InvertorDisassembler(ProblemSolutionFactory.CreateSlicer6x6(problem.SourceMatrix), problem.SourceMatrix),
                ProblemSolutionFactory.CreateSlicer6x6(problem.TargetMatrix),
                problem.SourceMatrix,
                problem.TargetMatrix
                );
            //var solver = new SmartReassembler(
            //    problem.SourceMatrix,
            //    problem.TargetMatrix,
            //    (s, t) => new InvertorDisassembler(new GreedyPartialSolver(s, t, new ThrowableHelperFast(t, s)), s, t),
            //    (s, t) => new GreedyPartialSolver(t, s, new ThrowableHelperFast(s, t))
            //    );
            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, problem.Name), bytes);
            }
            var state = new DeluxeState(problem.SourceMatrix, problem.TargetMatrix);

            new Interpreter(state).Run(commands);
        }
Ejemplo n.º 7
0
        //[Timeout(30000)]
        public void Assemble()
        {
            var problem = ProblemSolutionFactory.LoadProblem("FA011");
            //var solver = new DivideAndConquer(problem.SourceMatrix, false);
            var             state    = new DeluxeState(problem.SourceMatrix, problem.TargetMatrix);
            var             solver   = new Solver(state, new AssembleFA11(state));
            List <ICommand> commands = new List <ICommand>();

            try
            {
                commands.AddRange(solver.Solve());
            }
            catch (Exception e)
            {
                Log.For(this).Error($"Unhandled exception in solver for {problem.Name}", e);
                throw;
            }
            finally
            {
                var bytes = CommandSerializer.Save(commands.ToArray());
                File.WriteAllBytes(GetSolutionPath(FileHelper.SolutionsDir, problem.Name), bytes);
            }
        }
Ejemplo n.º 8
0
        public void AssembleKung()
        {
            var             problem  = ProblemSolutionFactory.LoadProblem("FA060");
            var             state    = new DeluxeState(problem.SourceMatrix, problem.TargetMatrix);
            var             solver   = new Solver(state, new ParallelGredyFill(state, state.Bots.First()));
            List <ICommand> commands = new List <ICommand>();

            try
            {
                commands.AddRange(solver.Solve());
            }
            catch (Exception e)
            {
                Log.For(this).Error($"Unhandled exception in solver for {problem.Name}", e);
                throw;
            }
            finally
            {
                var bytes = CommandSerializer.Save(commands.ToArray());
                File.WriteAllBytes(GetSolutionPath(FileHelper.SolutionsDir, problem.Name), bytes);
            }
            Console.Out.WriteLine(state.Energy);
        }