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


C# Route.Clone方法代码示例

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


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

示例1: MeasureTheDistance

 public virtual int MeasureTheDistance(List<Track> railRoad, Route route)
 {
     var traveledDistance = 0;
     var routeToBeMeasured = (Route) route.Clone();
     while (routeToBeMeasured.Cities.Count > 1)
     {
         EvaluateOriginAndDestination(routeToBeMeasured);
         var connection = GetTheNextTrack(railRoad);
         traveledDistance += connection.Distance;
     }
     return traveledDistance;
 }
开发者ID:blackbnu,项目名称:Trains,代码行数:12,代码来源:DistanceEvaluator.cs

示例2: FindNumberOfPossibleRoutes

        private void FindNumberOfPossibleRoutes(List<Track> railRoad, City origin, Route runningRoute)
        {
            var possibleTracks = railRoad.FindAll(track => track.Origin.Equals(origin));
            foreach (var track in possibleTracks)
            {
                var route = (Route)runningRoute.Clone();
                route.AppendCity(track.Destination);

                if (ThisRouteMatchWithTheRequisites(route))
                    possibleRoutesCounter++;

                if (ShouldKeepRunningInThisRoute(route))
                    FindNumberOfPossibleRoutes(railRoad, track.Destination, route);
            }
        }
开发者ID:blackbnu,项目名称:Trains,代码行数:15,代码来源:RouteFinder.cs

示例3: Crossover

        /// <summary>
        /// Applies crossover to 2 parents to create a child.
        /// </summary>
        /// <param name="first">
        /// The first parent of the crossover. 
        /// </param>
        /// <param name="second">
        /// The second parent of the crossover. 
        /// </param>
        /// <returns>
        /// If the operation is successful then the result is returned, otherwise null. 
        /// </returns>
        public Critter[] Crossover(Critter first, Critter second)
        {
            var random = Random.GetInstance();

            List<NodeWrapper<INetworkNode>> firstNodes = first.Route;
            List<NodeWrapper<INetworkNode>> secondNodes = second.Route;
            var crossoverPoints = new List<KeyValuePair<int, int>>();
            for (int i = 0; i < firstNodes.Count; i++)
            {
                for (int j = 0; j < secondNodes.Count; j++)
                {
                    if (firstNodes[i].Node.Equals(secondNodes[j].Node))
                    {
                        crossoverPoints.Add(new KeyValuePair<int, int>(i, j));
                        break;
                    }
                }
            }

            if (crossoverPoints.Count == 0)
            {
                // throw new Exception("StandardBreeder.cs: The crossover points are undefined.");
                // crossoverPoints.Add(new KeyValuePair<int, int>(random.Next(firstNodes.Count - 1), random.Next(secondNodes.Count - 1)));
                return null;
            }

            var firstChild = new Route(-1);
            var secondChild = new Route(-1);
            KeyValuePair<int, int> crossoverPoint = crossoverPoints[random.Next(crossoverPoints.Count - 1)];

            firstChild.AddRange(firstNodes.GetRange(0, crossoverPoint.Key));
            firstChild.AddRange(secondNodes.GetRange(crossoverPoint.Value, secondNodes.Count - crossoverPoint.Value));

            secondChild.AddRange(secondNodes.GetRange(0, crossoverPoint.Value));
            secondChild.AddRange(firstNodes.GetRange(crossoverPoint.Key, firstNodes.Count - crossoverPoint.Key));

            var output = new[]
                {
                    new Critter((Route)firstChild.Clone(), new Fitness()),
                    new Critter((Route)secondChild.Clone(), new Fitness())
                };

            output[0].DepartureTime = second.DepartureTime;
            output[1].DepartureTime = first.DepartureTime;

            Assert.That(output[0].DepartureTime != default(DateTime));
            Assert.That(output[1].DepartureTime != default(DateTime));

            if (output == null || output[0] == null || output[1] == null)
            {
                throw new Exception("StandardBreeder.cs: One or more decendants of crossover are null.");
            }

            return output;
        }
开发者ID:NoxHarmonium,项目名称:rmitjourneyplanner,代码行数:67,代码来源:StandardBreeder.cs

示例4: Mutate

        /// <summary>
        /// Mutates a critter
        /// </summary>
        /// <param name="child">
        /// The critter that is to be mutated. 
        /// </param>
        /// <returns>
        /// A mutated critter. 
        /// </returns>
        public Critter Mutate(Critter child)
        {
            var rand = Random.GetInstance();
            double u1 = rand.NextDouble(); // these are uniform(0,1) random doubles
            double u2 = rand.NextDouble();
            double randStdNormal = Math.Sqrt(-2.0 * Math.Log(u1)) * Math.Sin(2.0 * Math.PI * u2); // random no

            int crossoverWeight = (int)Tools.Clamp(10 * randStdNormal, -30, 30);

            child.DepartureTime = this.properties.DepartureTime.AddMinutes(crossoverWeight);
            Assert.That(child.DepartureTime != default(DateTime));

            var random = Random.GetInstance();
            List<NodeWrapper<INetworkNode>> nodes = child.Route;
            if (nodes.Count == 1)
            {
                return child;
            }

            int startIndex = random.Next(0, nodes.Count - 2);
            int endIndex = random.Next(startIndex + 1, nodes.Count - 1);
            NodeWrapper<INetworkNode> begin = nodes[startIndex];
            NodeWrapper<INetworkNode> end = nodes[endIndex];
            Route newSegment = this.properties.RouteGenerator.Generate(
                begin.Node, end.Node);
            var newRoute = new Route(Guid.NewGuid().GetHashCode());
            newRoute.AddRange(nodes.GetRange(0, startIndex));
            newRoute.AddRange(newSegment);
            newRoute.AddRange(nodes.GetRange(endIndex + 1, nodes.Count - 1 - endIndex));

            return new Critter((Route)newRoute.Clone(), new Fitness()) { DepartureTime = child.DepartureTime };

            // return child;
        }
开发者ID:NoxHarmonium,项目名称:rmitjourneyplanner,代码行数:43,代码来源:StandardMutator.cs

示例5: Crossover

        /// <summary>
        /// Applies crossover to 2 parents to create a child.
        /// </summary>
        /// <param name="first">
        /// The first parent of the crossover. 
        /// </param>
        /// <param name="second">
        /// The second parent of the crossover. 
        /// </param>
        /// <returns>
        /// If the operation is successful then the result is returned, otherwise null. 
        /// </returns>
        public Critter[] Crossover(Critter first, Critter second)
        {
            var random = Random.GetInstance();

            List<NodeWrapper<INetworkNode>> firstNodes = first.Route;
            List<NodeWrapper<INetworkNode>> secondNodes = second.Route;
            var crossoverPoints = new List<KeyValuePair<int, int>>();
            for (int i = 0; i < firstNodes.Count; i++)
            {
                for (int j = 0; j < secondNodes.Count; j++)
                {
                    if (firstNodes[i].Node.Equals(secondNodes[j].Node))
                    {
                        crossoverPoints.Add(new KeyValuePair<int, int>(i, j));
                        break;
                    }
                }
            }

            if (crossoverPoints.Count == 0)
            {
                // throw new Exception("StandardBreeder.cs: The crossover points are undefined.");
                // crossoverPoints.Add(new KeyValuePair<int, int>(random.Next(firstNodes.Count - 1), random.Next(secondNodes.Count - 1)));
                return null;
            }

            var firstChild = new Route(-1);
            var secondChild = new Route(-1);
            KeyValuePair<int, int> crossoverPoint = crossoverPoints[random.Next(crossoverPoints.Count - 1)];

            firstChild.AddRange(firstNodes.GetRange(0, crossoverPoint.Key));
            firstChild.AddRange(secondNodes.GetRange(crossoverPoint.Value, secondNodes.Count - crossoverPoint.Value));

            secondChild.AddRange(secondNodes.GetRange(0, crossoverPoint.Value));
            secondChild.AddRange(firstNodes.GetRange(crossoverPoint.Key, firstNodes.Count - crossoverPoint.Key));

            var output = new[]
                {
                    new Critter((Route)firstChild.Clone(), new Fitness()),
                    new Critter((Route)secondChild.Clone(), new Fitness())
                };

            var rand = Random.GetInstance();
            double u1 = rand.NextDouble(); // these are uniform(0,1) random doubles
            double u2 = rand.NextDouble();
            double randStdNormal = Math.Sqrt(-2.0 * Math.Log(u1)) * Math.Sin(2.0 * Math.PI * u2); // random no

            double crossOverWeight = Tools.Clamp(0.5 + (0.5 * randStdNormal));
            long difference = Math.Abs(first.DepartureTime.Ticks - second.DepartureTime.Ticks);
            long diffTime = (long)(difference * crossOverWeight);
            var newDepart = new DateTime(Math.Min(first.DepartureTime.Ticks, second.DepartureTime.Ticks) + diffTime);

            output[0].DepartureTime = newDepart;
            output[1].DepartureTime = newDepart;

            Assert.That(output[0].DepartureTime != default(DateTime));
            Assert.That(output[1].DepartureTime != default(DateTime));

            if (output == null || output[0] == null || output[1] == null)
            {
                throw new Exception("StandardBreeder.cs: One or more decendants of crossover are null.");
            }

            return output;
        }
开发者ID:NoxHarmonium,项目名称:rmitjourneyplanner,代码行数:77,代码来源:TimeBlendBreeder.cs


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