public IList<TransitPath> FindPaths(String originUnLocode, String destinationUnLocode, IList<TransitEdge> graphEdges, Constraints limitations)
 {         
    DateTime currentDate = DateTime.Now.Date;
    var result = new List<TransitPath>();
    var initialEdges = FindPossibleEdges(originUnLocode, currentDate, graphEdges, limitations);
    foreach (var edge in initialEdges)
    {
       BuildRoute(new List<TransitEdge>{edge}, destinationUnLocode, graphEdges, limitations, result);
    }
    return result;
 }
 private static void BuildRoute(IList<TransitEdge> currentPath, string destinationNode, IEnumerable<TransitEdge> edges, Constraints constraints, ICollection<TransitPath> paths)
 {
    var currentEdge = currentPath.Last();
    if (currentEdge.To == destinationNode)
    {
       var path = new TransitPath(currentPath);
       paths.Add(path);
       return;
    }
    var possibleEdges = FindPossibleEdges(currentEdge.To, currentEdge.ToDate, edges, constraints);
    foreach (var possibleEdge in possibleEdges)
    {
       var newPath = new List<TransitEdge>(currentPath) {possibleEdge};
       BuildRoute(newPath, destinationNode,edges, constraints, paths);
    }
 }
Exemplo n.º 3
0
        public IList <TransitPath> FindShortestPaths(String originUnLocode,
                                                     String destinationUnLocode,
                                                     Constraints limitations)
        {
            DateTime currentDate = NextDate(DateTime.Now);

            IList <String> allVertices = _dao.GetAllLocations();

            allVertices.Remove(originUnLocode);
            allVertices.Remove(destinationUnLocode);

            int candidateCount            = GetRandomNumberOfCandidates();
            List <TransitPath> candidates = new List <TransitPath>();

            for (int i = 0; i < candidateCount; i++)
            {
                allVertices = GetRandomChunkOfLocations(allVertices);
                List <TransitEdge> transitEdges = new List <TransitEdge>();
                String             firstLegTo   = allVertices.First();

                DateTime fromDate = NextDate(currentDate);
                DateTime toDate   = NextDate(fromDate);
                currentDate = NextDate(toDate);

                transitEdges.Add(new TransitEdge(originUnLocode, firstLegTo, fromDate, toDate));

                for (int j = 0; j < allVertices.Count - 1; j++)
                {
                    String curr = allVertices[j];
                    String next = allVertices[j + 1];
                    transitEdges.Add(GetNextEdge(ref currentDate, curr, next));
                }

                String lastLegFrom = allVertices.Last();
                transitEdges.Add(GetNextEdge(ref currentDate, lastLegFrom, destinationUnLocode));

                candidates.Add(new TransitPath(transitEdges));
            }

            return(candidates);
        }
      public IList<TransitPath> FindShortestPaths(String originUnLocode,
                                                    String destinationUnLocode,
                                                    Constraints limitations)
      {
         DateTime currentDate = NextDate(DateTime.Now);

         IList<String> allVertices = _dao.GetAllLocations();
         allVertices.Remove(originUnLocode);
         allVertices.Remove(destinationUnLocode);

         int candidateCount = GetRandomNumberOfCandidates();
         List<TransitPath> candidates = new List<TransitPath>();

         for (int i = 0; i < candidateCount; i++)
         {
            allVertices = GetRandomChunkOfLocations(allVertices);
            List<TransitEdge> transitEdges = new List<TransitEdge>();
            String firstLegTo = allVertices.First();

            DateTime fromDate = NextDate(currentDate);
            DateTime toDate = NextDate(fromDate);
            currentDate = NextDate(toDate);

            transitEdges.Add(new TransitEdge(originUnLocode, firstLegTo, fromDate, toDate));

            for (int j = 0; j < allVertices.Count - 1; j++)
            {
               String curr = allVertices[j];
               String next = allVertices[j + 1];
               transitEdges.Add(GetNextEdge(ref currentDate, curr, next));
            }

            String lastLegFrom = allVertices.Last();
            transitEdges.Add(GetNextEdge(ref currentDate, lastLegFrom, destinationUnLocode));

            candidates.Add(new TransitPath(transitEdges));
         }

         return candidates;
      }
 private static IEnumerable <TransitEdge> FindPossibleEdges(string currentNode, DateTime currentTime, IEnumerable <TransitEdge> edges, Constraints constraints)
 {
     return(edges.Where(x => x.From == currentNode &&
                        x.FromDate >= currentTime &&
                        x.ToDate <= constraints.ArrivalDeadline));
 }
        private static void BuildRoute(IList <TransitEdge> currentPath, string destinationNode, IEnumerable <TransitEdge> edges, Constraints constraints, ICollection <TransitPath> paths)
        {
            var currentEdge = currentPath.Last();

            if (currentEdge.To == destinationNode)
            {
                var path = new TransitPath(currentPath);
                paths.Add(path);
                return;
            }
            var possibleEdges = FindPossibleEdges(currentEdge.To, currentEdge.ToDate, edges, constraints);

            foreach (var possibleEdge in possibleEdges)
            {
                var newPath = new List <TransitEdge>(currentPath)
                {
                    possibleEdge
                };
                BuildRoute(newPath, destinationNode, edges, constraints, paths);
            }
        }
        public IList <TransitPath> FindPaths(String originUnLocode, String destinationUnLocode, IList <TransitEdge> graphEdges, Constraints limitations)
        {
            DateTime currentDate  = DateTime.Now.Date;
            var      result       = new List <TransitPath>();
            var      initialEdges = FindPossibleEdges(originUnLocode, currentDate, graphEdges, limitations);

            foreach (var edge in initialEdges)
            {
                BuildRoute(new List <TransitEdge> {
                    edge
                }, destinationUnLocode, graphEdges, limitations, result);
            }
            return(result);
        }
 private static IEnumerable<TransitEdge> FindPossibleEdges(string currentNode, DateTime currentTime, IEnumerable<TransitEdge> edges, Constraints constraints)
 {
    return edges.Where(x => x.From == currentNode &&
                            x.FromDate >= currentTime &&
                            x.ToDate <= constraints.ArrivalDeadline);
 }