Example #1
0
 public JourneyPlanner(Map map, IDistanceCalculator distanceCalculator, IShortestPathFinder shortestPathFinder, IRouteFinder routeFinder)
 {
     Map = map;
     DistanceCalculationService = distanceCalculator;
     ShortestPathFinder         = shortestPathFinder;
     RouteFinder = routeFinder;
 }
 public ShortestEditPathLister(
     IShortestPathFinder shortestPathFinder,
     IGraphBuilder graphBuilder)
 {
     _shortestPathFinder = shortestPathFinder;
     _graphBuilder       = graphBuilder;
 }
Example #3
0
 public BestRouteService(
     IRouteRepository routeRepository,
     IAirportRepository airportRepository,
     IShortestPathFinder businessLogic)
 {
     _routeRepository   = routeRepository;
     _airportRepository = airportRepository;
     _businessLogic     = businessLogic;
     _airports          = new List <Airport>();
 }
Example #4
0
 public Runner(FileService fileService,
               RouteService routeService,
               IShortestPathFinder shortestPathFinder,
               CityService cityService,
               TextSerializer textSerializer,
               ILogger <Runner> logger)
 {
     _fileService        = fileService ?? throw new ArgumentNullException(nameof(fileService));
     _routeService       = routeService ?? throw new ArgumentNullException(nameof(routeService));
     _shortestPathFinder = shortestPathFinder ?? throw new ArgumentNullException(nameof(shortestPathFinder));
     _cityService        = cityService ?? throw new ArgumentNullException(nameof(cityService));
     _textSerializer     = textSerializer ?? throw new ArgumentNullException(nameof(textSerializer));
     _logger             = logger ?? throw new ArgumentNullException(nameof(logger));
 }
Example #5
0
        /// <summary>
        /// Process the files, load the RoadSystem then find the shortest path and put the result into ResultItem
        /// If there is any error then the ResultItem.HasError will be true and ResultItem.Result will be error message
        /// </summary>
        /// <param name="filePath"></param>
        /// <param name="finder"></param>
        /// <returns></returns>
        private ResultItem ProcessFile(string filePath, IShortestPathFinder finder)
        {
            ResultItem item = null;
            string filename = Path.GetFileName(filePath);
            try
            {
                // Load RoadSystem
                RoadSystem system = RoadSystem.LoadFromXml(filePath);

                // Find the shortest path
                var result = finder.FindShortestPath(system);

                // Create ResultItem from the result
                if (result.Count() == 0)
                {
                    item = new ResultItem
                    {
                        Filename = filename,
                        Result = "No path found"
                    };
                }
                else
                {
                    item = new ResultItem
                    {
                        Filename = filename,
                        Result = String.Join(", ", result.Select(node => node.ID.ToString()).ToArray())
                    };
                }
            }
            catch (LoadRoadSystemException ex)
            {
                // Create ResultItem from error
                item = new ResultItem
                {
                    Filename = filename,
                    HasError = true,
                    Result = ex.Message
                };
            }

            // Return ResultItem
            return item;
        }