Пример #1
0
 public void Solve(int problemId)
 {
     var problemsRepo = new ProblemsRepo();
     var problem      = problemsRepo.Get(problemId);
     var poly         = problem.Polygons.Single();
     //			var dx = (int) problem.Polygons.SelectMany(p => p.Vertices).Select(x => x.X.Denomerator).Max();
     //			var dy = (int) problem.Polygons.SelectMany(p => p.Vertices).Select(x => x.Y.Denomerator).Max();
     //			foreach (var x in Enumerable.Range(0, dx).Select(x => new Rational(x, dx)))
     //				foreach (var y in Enumerable.Range(0, dy).Select(y => new Rational(y, dy)))
     {
         //					var shift = new Vector(x, y);
         var shift              = new Vector(0, 0);
         var initialSolution    = SolutionSpec.CreateTrivial(v => v + shift);
         var solution           = ConvexPolygonSolver.Solve(poly.GetConvexBoundary(), initialSolution);
         var packedSolution     = solution.Pack();
         var packedSolutionSize = packedSolution.Size();
         var solutionSize       = solution.Size();
         Console.WriteLine($"{shift}: {solutionSize}; packed: {packedSolutionSize}");
         if (packedSolutionSize <= 5000)
         {
             ProblemsSender.Post(packedSolution, problemId, false);
             //						return;
         }
     }
 }
Пример #2
0
        public void GetInitialSolutionAlongRationalEdge_82()
        {
            var solution = ConvexPolygonSolver.GetInitialSolutionAlongRationalEdge("41/68,58/71 27/68,58/71");

            //solution.CreateVisualizerForm(true).ShowDialog();
            solution.DestPoints.Should().Equal("41/68,58/71|109/68,58/71|109/68,-13/71|41/68,-13/71".Split('|').Select(Vector.Parse).ToArray());
        }
Пример #3
0
        public void GetInitialSolutionAlongRationalEdge()
        {
            var solution = ConvexPolygonSolver.GetInitialSolutionAlongRationalEdge("1,2 1,3");

            //solution.CreateVisualizerForm(true).ShowDialog();
            solution.DestPoints.Should().Equal("1,2|1,3|0,3|0,2".Split('|').Select(Vector.Parse).ToArray());
        }
Пример #4
0
        public void GetInitialSolutionAlongRationalEdge_6()
        {
            var solution = ConvexPolygonSolver.GetInitialSolutionAlongRationalEdge("15/29,-6/29 35/29,15/29");

            //solution.CreateVisualizerForm(true).ShowDialog();
            solution.DestPoints.Should().Equal("15/29,-6/29|35/29,15/29|14/29,35/29|-6/29,14/29".Split('|').Select(Vector.Parse).ToArray());
        }
Пример #5
0
        public void DoSomething_WhenSomething()
        {
            var repo      = new ProblemsRepo();
            var apiClient = new ApiClient();

            foreach (var problemSpec in repo.GetAll()
                     .Where(x => repo.GetProblemResemblance(x.id) == 1.0)
                     .Reverse().Take(3))
            {
                Console.Out.WriteLine(problemSpec.id);
                var solutionSpec = ConvexPolygonSolver.TrySolveSingleProblem(problemSpec);
                if (solutionSpec != null)
                {
                    var response = apiClient.PostSolution(problemSpec.id, solutionSpec.Normalize().Pack());
                    Console.Out.WriteLine(response);
                }
            }
        }