Ejemplo n.º 1
0
        public Journey[] AvailableByMaxDistance(Node from, Node to, int distance)
        {
            if (from != null && to != null && distance > 0)
            {
                var journeys = new LinkedNode(this, from).GenerateRoutes(to, 16, true, true);

                var filteredJourneys = new List <Journey>();
                foreach (var journey in journeys)
                {
                    if (journey.LastNode == to && journey.Distance < distance)
                    {
                        filteredJourneys.Add(journey);
                    }
                }
                return(filteredJourneys.ToArray());
            }
            return(new Journey[0]);
        }
Ejemplo n.º 2
0
        private void GenerateRoutesRecursive(ICollection <LinkedNode> leafNodes, Node to, int depth, bool depthSearch)
        {
            _visited[RouteNode.Index] = true;
            var matrix = _manager.Matrix;

            for (var i = 0; i < matrix.Size; i++)
            {
                if (matrix.GetElementAt(RouteNode.Index, i) > 0)
                {
                    var edge     = _manager.FindEdge(RouteNode.Index, i);
                    var nextNode = new LinkedNode(_manager, edge, this);
                    Array.Copy(_visited, nextNode._visited, _visited.Length);

                    if (depthSearch)
                    {
                        if (depth > 0)
                        {
                            nextNode.GenerateRoutesRecursive(leafNodes, to, depth - 1, true);
                        }
                        else
                        {
                            leafNodes.Add(nextNode);
                        }
                    }
                    else
                    {
                        if (nextNode.RouteNode != to)
                        {
                            if (!_visited[edge.To.Index])
                            {
                                nextNode.GenerateRoutesRecursive(leafNodes, to, depth - 1, false);
                            }
                        }
                        else
                        {
                            leafNodes.Add(nextNode);
                        }
                    }
                }
            }
        }
Ejemplo n.º 3
0
        public Journey[] AvailableByMaxStops(Node from, Node to, int stops, bool equalOp)
        {
            if (from != null && to != null && stops > 0)
            {
                var journeys = new LinkedNode(this, from).GenerateRoutes(to, stops - 1, equalOp, false);

                var filteredJourneys = new List <Journey>();
                foreach (var journey in journeys)
                {
                    if (journey.LastNode == to)
                    {
                        if ((equalOp && journey.Stops == stops) || (!equalOp && journey.Stops <= stops))
                        {
                            filteredJourneys.Add(journey);
                        }
                    }
                }
                return(filteredJourneys.ToArray());
            }
            return(System.Array.Empty <Journey>());
        }
Ejemplo n.º 4
0
        public Journey FindShortestRoute(Node from, Node to)
        {
            Journey shortestJourney = null;

            if (from != null && to != null)
            {
                var journeys = new LinkedNode(this, from).GenerateRoutes(to, 0, false, false);

                var shortestDistance = int.MaxValue;
                foreach (var journey in journeys)
                {
                    var journeyDistance = journey.Distance;
                    if (journeyDistance < shortestDistance)
                    {
                        shortestDistance = journeyDistance;
                        shortestJourney  = journey;
                    }
                }
            }

            return(shortestJourney);
        }
Ejemplo n.º 5
0
 private LinkedNode(RouteManager rm, Edge routeEdge, LinkedNode parent) : this(rm, routeEdge.To)
 {
     RouteEdge  = routeEdge;
     ParentNode = parent;
 }