예제 #1
0
        /// <summary>
        /// Finds waypoint info for given waypoint ID, and creates it if it doesn't exist. This
        /// can be used to create "intermediate" waypoints that act as node between two edges.
        /// </summary>
        /// <param name="waypointId">waypoint ID to find</param>
        /// <returns>waypoint info</returns>
        internal WaypointInfo FindOrCreateWaypointInfo(string waypointId)
        {
            var waypointInfo = this.FindWaypointInfo(waypointId);

            if (waypointInfo == null)
            {
                // create an intermediate waypoint that isn't used as tour point
                waypointInfo = new WaypointInfo
                {
                    Id          = waypointId,
                    Description = string.Empty
                };

                this.tourGraph.AddVertex(waypointInfo);
            }

            return(waypointInfo);
        }
예제 #2
0
        /// <summary>
        /// Plans single tour step between two waypoints
        /// </summary>
        /// <param name="source">source waypoint</param>
        /// <param name="target">target waypoint</param>
        /// <param name="tour">planned tour object</param>
        /// <param name="descriptionText">description text string builder</param>
        /// <param name="totalDuration">reference to total duration</param>
        private void PlanSingleTourStep(WaypointInfo source, WaypointInfo target, PlannedTour tour, StringBuilder descriptionText, ref TimeSpan totalDuration)
        {
            Debug.WriteLine($"finding shortest path between {source} and {target}");

            Func <TrackInfo, double> edgeCost = GetEdgeWeightShortestTime;

            TryFunc <WaypointInfo, IEnumerable <TrackInfo> > tryGetPaths =
                this.tourGraph.ShortestPathsDijkstra(edgeCost, source);

            if (tryGetPaths(target, out IEnumerable <TrackInfo> path))
            {
                foreach (var edge in path)
                {
                    Debug.WriteLine(edge);

                    tour.TourEntriesList.Add(
                        new PlannedTourEntry
                    {
                        StartWaypointId = edge.Source.Id,
                        EndWaypointId   = edge.Target.Id,
                        TrackStartIndex = tour.MapPointList.Count,
                        Duration        = edge.Duration,
                    });

                    tour.MapPointList.AddRange(edge.MapPointList);

                    if (!string.IsNullOrEmpty(edge.Source.Description))
                    {
                        descriptionText.Append($"Wegpunkt: {edge.Source.Description} \n\n");
                    }

                    descriptionText.Append($"{edge.Description}\n\n");

                    totalDuration += edge.Duration;
                }
            }

            Debug.WriteLine("finished.");
            Debug.WriteLine(string.Empty);
        }
예제 #3
0
 /// <summary>
 /// Adds new waypoint to the graph. Used by the graph loader.
 /// </summary>
 /// <param name="waypointInfo">waypoint info to add</param>
 internal void AddWaypoint(WaypointInfo waypointInfo) => this.tourGraph.AddVertex(waypointInfo);