当前位置: 首页>>代码示例>>C#>>正文


C# Route.First方法代码示例

本文整理汇总了C#中Route.First方法的典型用法代码示例。如果您正苦于以下问题:C# Route.First方法的具体用法?C# Route.First怎么用?C# Route.First使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在Route的用法示例。


在下文中一共展示了Route.First方法的1个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。

示例1: DrawTour

        public void DrawTour(Route route, int id)
        {
            this.lastFitnessValue.Text = Math.Round(route.Fitness, 2).ToString(CultureInfo.CurrentCulture);
            this.lastIterationValue.Text = id.ToString();

            if (this.cityImage == null)
            {
                this.cityImage = new Bitmap(tourDiagram.Width, tourDiagram.Height);
                this.cityGraphics = Graphics.FromImage(cityImage);
            }

            cityGraphics.FillRectangle(Brushes.White, 0, 0, cityImage.Width, cityImage.Height);

            Action<Node, Node> draw =
                (prev, curr) =>
                {
                    // Draw a circle for the city.
                    var xValue = Convert.ToInt32((curr.X + guiFactors.XOffset) / guiFactors.XFactor);
                    var yValue = Convert.ToInt32((curr.Y + guiFactors.YOffset) / guiFactors.YFactor);
                    cityGraphics.DrawEllipse(Pens.Black, xValue - 2, Math.Abs(400 - yValue) - 2, 5, 5);
                    if (curr.IsStart) { cityGraphics.DrawEllipse(Pens.Green, xValue - 2, Math.Abs(400 - yValue) - 2, 8, 8); }
                    if (curr.IsEnd) { cityGraphics.DrawEllipse(Pens.Red, xValue - 2, Math.Abs(400 - yValue) - 2, 9, 9); }

                    // Draw the line connecting the city.
                    var ptLastCity = new Point(
                        Convert.ToInt32((prev.X + guiFactors.XOffset) / guiFactors.XFactor),
                        Math.Abs(400 - Convert.ToInt32((prev.Y + guiFactors.YOffset) / guiFactors.YFactor))
                    );

                    var ptCurrentCity = new Point(
                        Convert.ToInt32((curr.X + guiFactors.XOffset) / guiFactors.XFactor),
                        Math.Abs(400 - Convert.ToInt32((curr.Y + guiFactors.YOffset) / guiFactors.YFactor))
                    );

                    cityGraphics.DrawLine(Pens.Black, ptLastCity, ptCurrentCity);
                };

            for(var i=0; i<route.Count; i++)
            {
                var current = this.nodes[route[i]];
                var previous = i > 0 ? this.nodes[route[i - 1]] : current;
                draw(previous, current);
            }
            if(route.IsCycle)
            {
                draw(this.nodes[route.Last()], this.nodes[route.First()]);
            }
            this.tourDiagram.Image = cityImage;
        }
开发者ID:jackfeichen,项目名称:Traveling-Salesman,代码行数:49,代码来源:TspForm.cs


注:本文中的Route.First方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。