Example #1
0
        private static void ExecuteFindDistanceOfRoute(TrainMap map, params string[] townNames)
        {
            var distance = map.FindDistanceOfRoute(townNames);

            Console.WriteLine("The distance of the route {0}: {1}",
                string.Join("-", townNames),
                DistanceToString(distance));
        }
Example #2
0
        static void Main(string[] args)
        {
            var currentDirectory = Path.GetDirectoryName(Assembly.GetExecutingAssembly().Location);
            var inputFiles = Directory.GetFiles(Path.Combine(currentDirectory, "Input"));
            foreach (var inputFile in inputFiles)
            {
                Console.WriteLine("Processing " + inputFile);
                Console.WriteLine();

                var input = ReadFromFile(inputFile);

                var map = new TrainMap();
                map.Parse(input);

                ExecuteFindDistanceOfRoute(map, "A", "B", "C");
                ExecuteFindDistanceOfRoute(map, "A", "D");
                ExecuteFindDistanceOfRoute(map, "A", "D", "C");
                ExecuteFindDistanceOfRoute(map, "A", "E", "B", "C", "D");
                ExecuteFindDistanceOfRoute(map, "A", "E", "C");

                var fromCToCWithMax3Stops = map.FindRoutesBetween("C", "C",
                        (routeLength, routeDistance) => routeLength <= 3,
                        (routeLength, routeDistance) => routeLength > 3);
                Console.WriteLine("The number of trips starting at C and ending at C with a maximum of 3 stops: " +
                    fromCToCWithMax3Stops.Count);

                var fromAToCWithExactly4Stops = map.FindRoutesBetween("A", "C",
                    (routeLength, routeDistance) => routeLength == 4,
                    (routeLength, routeDistance) => routeLength > 4);
                Console.WriteLine("The number of trips starting at A and ending at C with exactly 4 stops: " +
                    fromAToCWithExactly4Stops.Count);

                var shortestRouteFromAToC = map.FindShortestDistance("A", "C");
                Console.WriteLine("The length of the shortest route from A to C: " +
                    DistanceToString(shortestRouteFromAToC));

                var shortestRouteFromBToB = map.FindShortestDistance("B", "B");
                Console.WriteLine("The length of the shortest route from B to B: " +
                    DistanceToString(shortestRouteFromBToB));

                var fromCToCWithDistanceLessThan30 = map.FindRoutesBetween("C", "C",
                    (routeLength, routeDistance) => routeDistance < 30,
                    (routeLength, routeDistance) => routeDistance >= 30);
                Console.WriteLine("The number of different routes from C to C with a distance of less than 30: " +
                    fromCToCWithDistanceLessThan30.Count);

                Console.WriteLine("===============================");
            }
        }
Example #3
0
 public void SetUp()
 {
     _map = new TrainMap();
     _map.Parse("AB5, BC4, CD8, DC8, DE6, AD5, CE2, EB3, AE7");
 }
Example #4
0
 public void Setup()
 {
     _map = new TrainMap();
 }