Esempio n. 1
0
        public static void Main(string[] args)
        {
            string stopJSON;
            string transportAndScheduleJSON;

            using (WebClient webClient = new WebClient())
            {
                stopJSON = webClient.DownloadString("https://api.trafi.com/api/stops?userLocationId=kaunas");
                transportAndScheduleJSON = webClient.DownloadString("https://api.trafi.com/api/v3/schedules?userLocationId=kaunas");
            }

            ILocationParser locationParser   = new TrafiApiLocationParser(stopJSON);
            var             locationsWithIds = ((TrafiApiLocationParser)locationParser).ParseLocationsWithIds();

            ITransportParser transportParser = new TrafiApiTransportParser(transportAndScheduleJSON);
            var transports = transportParser.ParseTransports(locationsWithIds);

            IGraphFormer <AStarNode> graphFormer = new GraphFormer <AStarNode>();
            var stopGraph = graphFormer.FormGraph(locationsWithIds, transports);

            ITransitAdder pedestrianPathAdder = new PedestrianTransitAdder();

            stopGraph = pedestrianPathAdder.AddTransits(stopGraph);

            IWeightCalculator       weightCalculator    = new PenalisingWeightCalculator(new WeightCalculator());
            IWeightCalculator       heuristicCalculator = new HeuristicCalculator();
            IPathFinder <AStarNode> pathFinder          = new AStarPathFinder(stopGraph, weightCalculator, heuristicCalculator);

            IInputReader  inputReader  = new ConsoleInputReader();
            IOutputWriter outputWriter = new ConsoleOutputWriter();
            var           stopWatch    = new Stopwatch();

            var startingStopID = ((ConsoleInputReader)inputReader).ReadStopID(locationsWithIds);
            var endingStopID   = ((ConsoleInputReader)inputReader).ReadStopID(locationsWithIds);
            var departureTime  = inputReader.ReadTime();

            stopWatch.Reset();
            stopWatch.Start();
            var path = pathFinder.FindBestPath(stopGraph.Nodes[startingStopID], stopGraph.Nodes[endingStopID], departureTime);

            stopWatch.Stop();

            path.Squash();
            outputWriter.WriteElapsedTime(stopWatch.Elapsed);
            outputWriter.WritePath(path);
        }