Beispiel #1
0
        private static void Solve(ProblemSpec problemSpec)
        {
            var originalities      = new[] { 0.5 };
            var mutex              = new object();
            var solutionFoundEvent = new ManualResetEvent(false);
            var threads            = originalities
                                     .Select(coeff =>
            {
                var thread = new Thread(() =>
                {
                    try
                    {
                        var solution = SolutionPacker.Pack(new ConstructorSolver(problemSpec).Work());
                        if (solution == null || solution.Size() > 5000 || !solution.AreFacetsValid())
                        {
                            return;
                        }
                        double ps;
                        lock (mutex)
                        {
                            Console.WriteLine(" posting... ");
                            ps = ProblemsSender.Post(solution, problemSpec.id);
                            Console.Write($" perfect score: {ps}");
                        }
                        if (ps == 1.0)
                        {
                            solutionFoundEvent.Set();
                        }
                    }
                    catch (Exception e)
                    {
                        if (e is ThreadAbortException)
                        {
                            return;
                        }
                        Console.WriteLine($"Exception in ProjectionSolverRunner: {e}");
                    }
                })
                {
                    IsBackground = true
                };
                thread.Start();
                return(thread);
            })
                                     .ToArray();

            solutionFoundEvent.WaitOne(TimeSpan.FromSeconds(10));

            foreach (var t in threads)
            {
                if (t.IsAlive)
                {
                    t.Abort();
                    t.Join();
                }
            }
        }
Beispiel #2
0
        static void Main2(string[] args)
        {
            var problem = File.ReadAllText("../../../problems/031.spec.txt");
            var spec    = ProblemSpec.Parse(problem);

            Application.EnableVisualStyles();
            Application.SetCompatibleTextRenderingDefault(false);
            var form1 = new PolygonsAndSegmentsForm();

            form1.SetData(spec.Polygons, spec.Segments);
            Task.Run(() => Application.Run(form1));

            var solver   = new ConstructorSolver(spec);
            var solution = SolutionPacker.Pack(solver.Work());

            var form = new PolygonsAndSegmentsForm();

            form.SetData(solution.Polygons, new Segment[0]);
            Application.Run(form);
        }