Example #1
0
        static void Main(string[] args)
        {
            string configurationFile = "StationMatrix.csv";
            string startStationName  = "A";
            string endStationName    = "F";
            string trainColor        = string.Empty;

            for (int i = 0; i < args.Length; i++)
            {
                if (!args[i].StartsWith('-'))
                {
                    continue;
                }

                switch (args[i].ToLower())
                {
                case "-p":
                case "--path":
                    configurationFile = args[i + 1];
                    break;

                case "-s":
                case "--start":
                    startStationName = args[i + 1];
                    break;

                case "-e":
                case "--end":
                    endStationName = args[i + 1];
                    break;

                case "-c":
                case "--color":
                    trainColor = args[i + 1];
                    break;
                }
            }

            IStationConfigurationProvider stationConfigurationProvider = new StationConfigurationProvider(configurationFile);
            IStationService      stationService      = new StationService(stationConfigurationProvider);
            IOptimizationService optimizationService = new OptimizationService(stationService);

            List <Station> stations = optimizationService.OptimizeRoute(trainColor, startStationName, endStationName);

            if (stations == null)
            {
                Console.WriteLine($"No optimal route found");
            }
            else
            {
                Console.WriteLine($"Optimal route found: {string.Join('>', stations.Select(s => s.Name).ToArray())}");
            }

            Console.WriteLine("Press a key to finish");
            Console.ReadLine();
        }
Example #2
0
        }//Session_End

        protected void Application_End()
        {
            OptimizationService.EndProcess();
            IUserService  service = _container.Resolve <IUserService>();
            LogoffCommand cmd     = new LogoffCommand {
                Users = lstUsers
            };

            service.Logoff(cmd);
        }
        public void OptimizeRoute_IsUnknownDestination_ShouldBeUnsolvable(string trainColor, string stationStart, string stationEnd)
        {
            //Arrange
            _stationServiceMock.GetStationByName(stationStart).Returns(_stationsRepository[stationStart]);
            _stationServiceMock.GetStationByName(stationEnd).ReturnsNull();
            _stationServiceMock.GetValidStationLinks(trainColor).Returns(_linksRepository["Unknown"]);
            IOptimizationService optimizer = new OptimizationService(_stationServiceMock);
            //Act
            List <Station> path = optimizer.OptimizeRoute(trainColor, stationStart, stationEnd);

            //Assert
            Assert.Null(path);
        }
        public void OptimizeRoute_IsNullColor_ShouldBeSolvable(string trainColor, string stationStart, string stationEnd)
        {
            //Arrange
            _stationServiceMock.GetStationByName(stationStart).Returns(_stationsRepository[stationStart]);
            _stationServiceMock.GetStationByName(stationEnd).Returns(_stationsRepository[stationEnd]);
            _stationServiceMock.GetValidStationLinks(trainColor).Returns(_linksRepository[string.Empty]);
            IOptimizationService optimizer = new OptimizationService(_stationServiceMock);
            //Act
            List <Station> path = optimizer.OptimizeRoute(trainColor, stationStart, stationEnd);

            //Assert
            Assert.NotNull(path);
            Assert.True(path.Count > 0);
        }
        public void OptimizeRoute_IsEnd_ShouldBeLast(string trainColor, string stationStart, string stationEnd)
        {
            //Arrange
            _stationServiceMock.GetStationByName(stationStart).Returns(_stationsRepository[stationStart]);
            _stationServiceMock.GetStationByName(stationEnd).Returns(_stationsRepository[stationEnd]);
            _stationServiceMock.GetValidStationLinks(trainColor).Returns(_linksRepository[trainColor]);
            IOptimizationService optimizer = new OptimizationService(_stationServiceMock);
            //Act
            List <Station> path = optimizer.OptimizeRoute(trainColor, stationStart, stationEnd);
            //Assert
            Station end = path.LastOrDefault();

            Assert.NotNull(end);
            Assert.Equal(stationEnd, end.Name);
        }
        public void OptimizeRoute_IsValidStations_ShouldBeValidStations(string trainColor, string stationStart, string stationEnd)
        {
            //Arrange
            _stationServiceMock.GetStationByName(stationStart).Returns(_stationsRepository[stationStart]);
            _stationServiceMock.GetStationByName(stationEnd).Returns(_stationsRepository[stationEnd]);
            _stationServiceMock.GetValidStationLinks(trainColor).Returns(_linksRepository[trainColor]);
            IOptimizationService optimizer = new OptimizationService(_stationServiceMock);
            //Act
            List <Station> path = optimizer.OptimizeRoute(trainColor, stationStart, stationEnd);

            //Assert
            foreach (var station in path)
            {
                Assert.True(station.IsValidStation(trainColor), "station is valid");
            }
        }
        public void OptimizeRoute_IsValidStations_ShouldBeValidRoute(string trainColor, string stationStart, string stationEnd)
        {
            //Arrange
            _stationServiceMock.GetStationByName(stationStart).Returns(_stationsRepository[stationStart]);
            _stationServiceMock.GetStationByName(stationEnd).Returns(_stationsRepository[stationEnd]);
            _stationServiceMock.GetValidStationLinks(trainColor).Returns(_linksRepository[trainColor]);
            IOptimizationService optimizer = new OptimizationService(_stationServiceMock);
            //Act
            List <Station> path = optimizer.OptimizeRoute(trainColor, stationStart, stationEnd);
            //Assert
            Station currentStation = path.First();

            foreach (Station nextStation in path.Skip(1))
            {
                bool isLinkExisting = _linksRepository[trainColor].Any(sl => sl.Origin == currentStation && sl.Destination == nextStation);
                Assert.True(isLinkExisting, "Link exist between current and next");
                currentStation = nextStation;
            }
        }
Example #8
0
 private static void StartProcess()
 {
     OptimizationService.StartProcess(HttpContext.Current.Server.MapPath("~/bin/TFI.CalculationEngine.exe"));
 }