コード例 #1
0
        public static void Main(string[] args)
        {
            if (args == null || args.Length < 2)
            {
                Console.WriteLine("Usage: " +
                                  "dotnet dll_file_location graph_edges_file_path jobs_file_path routes_file_path");
                Environment.Exit(0);
            }

            // We could implement a strategy/factory design pattern for both the graph and the job IO, which would
            // give the possibility to retrieve their respective data from elsewhere (for instance, from a web service).
            var graphIO = new GraphIO();
            var graph   = graphIO.ParseInput(args[0]);

            var jobIO       = new JobIO();
            var pendingJobs = jobIO.ParseInput(args[1]);

            var resultFile = "";

            if (args.Length == 3)
            {
                resultFile = args[2];
            }

            var jobsResults = new List <List <string> >();
            var dijkstra    = new Dijkstra();

            foreach (var pendingJob in pendingJobs)
            {
                validateJob(graph, pendingJob);
                jobsResults.Add(dijkstra.CalculateShortestPath(graph, pendingJob));
            }

            jobIO.WriteToFile(jobsResults, resultFile);
        }