예제 #1
0
        private void BeginFind_Click(object sender, EventArgs e)
        {
            var       findway = ((dynamic)FindType.SelectedItem).Value;
            var       type    = Types.FirstOrDefault(t => t.Name == findway);
            WayFinder finder  = System.Activator.CreateInstance(type) as WayFinder;
            Stopwatch sw      = new Stopwatch();

            sw.Start();
            var str = finder.Execute(dict);

            sw.Stop();
            ResultText.Text = str;
            textBox1.Text   = sw.Elapsed.ToString();
            if (str == "成功")
            {
                ThreadPool.QueueUserWorkItem(o =>
                {
                    ResultText.Text = finder.WayResult.Count().ToString();
                    foreach (var i in finder.WayProcedure)
                    {
                        if (((CancellationToken)o).IsCancellationRequested)
                        {
                            break;
                        }
                        var container       = dict[i.X, i.Y] as LabelContainer;
                        container.BackColor = Color.Yellow;
                        //container.Text = container.StartDistance + "-" + container.EndDistance;
                        Thread.Sleep(5);
                    }
                    foreach (var i in finder.WayResult)
                    {
                        if (((CancellationToken)o).IsCancellationRequested)
                        {
                            break;
                        }
                        var container       = dict[i.X_, i.Y_] as LabelContainer;
                        container.BackColor = Color.Green;
                        Thread.Sleep(5);
                    }
                }, source.Token);
            }
        }
예제 #2
0
        static void Main(string[] args)
        {
            //var dict = halfParsed["Sections"]
            //  .ToDictionary(x => x["Id"], y => new TrackSection {
            //    Id = y["Id"].ToObject<int>(),
            //    SectionId = y["SectionId"].ToObject<int>(),
            //    Turnouts = y["Turnouts"].ToObject<List<TurnoutConfiguration>>()
            //  });
            //foreach(var section in halfParsed["Sections"]) {
            //  TrackSection trackSection = dict[section["Id"]];
            //  trackSection.ConnectedSections = section["ConnectedSections"]
            //    .Select(x => dict[x])
            //    .Where(x => x.SectionId != trackSection.SectionId)
            //    .ToList();
            //}

            //CreateLayoutV3json();
            var x  = ParseLayoutV3json();
            var sw = Stopwatch.StartNew();

            WayFinder.FindRoute(x, 1, 20).ForEach(x => Console.WriteLine(x));
            Console.WriteLine(sw.Elapsed);
        }