Exemplo n.º 1
0
        public static CalculatedRoute CalculateInternalRoute(Category category, float weight, string from, string to, bool fastest)
        {
            var cachedSections = FetchSections.FetchInternCachedSections(weight, category);
            var cities         = DbHelper.GetAllCities().Select(x => x.Name).ToList();
            var routes         = ShortestPath.calculateKRoutes(from, to, cities, cachedSections, fastest, 1);

            // Calculate total price and just do start/finish in response. Convert it to Json

            if (routes.Count == 0)
            {
                throw new NoPathFoundException();
            }

            return(routes[0]);
        }
Exemplo n.º 2
0
        public static CalculatedRoute Calculate(Category category, float weight, City from, City to, Boolean fastest = true)
        {
            from.Name = from.Name.ToUpper();
            to.Name   = to.Name.ToUpper();
            var cityNames = DbHelper.GetAllCities().Select(x => x.Name).ToList();

            List <CachedSection> cachedSections = DbCachedSectionLoader.Load(category);

            if (cachedSections.Count == 0)
            {
                DbRouteUpdater.UpdateExternal();
                DbRouteUpdater.UpdateInternal();
                cachedSections = DbCachedSectionLoader.Load(category);
            }
            cachedSections = removeCityRuleViolations(cachedSections, category);

            List <CalculatedRoute> approximatedcalculatedRoutes =
                ShortestPath.calculateKRoutes(from.Name, to.Name, cityNames, cachedSections, fastest, kEstimates);

            if (approximatedcalculatedRoutes.Count == 0)
            {
                throw new NoPathFoundException();
            }
            List <SectionRequest> sections = CalculatedRouteToSectionRequests(approximatedcalculatedRoutes, weight);

            List <CachedSection> upToDateSections = FetchSections.FetchInternCachedSections(weight, category);

            upToDateSections.AddRange(FetchSections.FetchExternCachedSections(sections, mock: true));

            List <CalculatedRoute> exactCalculatedRoutes = ShortestPath.calculateKRoutes(from.Name, to.Name, cityNames, upToDateSections, fastest, 1);

            if (exactCalculatedRoutes.Count == 0)
            {
                List <SectionRequest> sectionRequests     = ExternalCachedSectionToSectionRequests(cachedSections, weight);
                List <CachedSection>  allUpToDateSections = FetchSections.FetchInternCachedSections(weight, category);
                allUpToDateSections.AddRange(FetchSections.FetchExternCachedSections(sectionRequests, mock: true));
                allUpToDateSections = removeCityRuleViolations(allUpToDateSections, category);
                var slowExactCalculatedRoutes =
                    ShortestPath.calculateKRoutes(from.Name, to.Name, cityNames, allUpToDateSections, fastest, 1);
                if (slowExactCalculatedRoutes.Count == 0)
                {
                    throw new NoPathFoundException();
                }
                return(slowExactCalculatedRoutes[0]);
            }
            return(exactCalculatedRoutes[0]);
        }