public SearchResultDTO ClickCalculate(Parcel parcel, City source, City destination) { List <Edge> edges; List <City> cities; cities = MappingService.GetCities(); edges = MappingService.GetEdges(cities); //context.GetAllEdges(); Graph <City, string> graphPrice = GraphFabric.CreateGraphPrice(cities, edges, "priceCost", parcel); Graph <City, string> graphTime = GraphFabric.CreateGraphTime(cities, edges, "timeCost"); Graph <City, string> graphPriceTime = GraphFabric.CreateGraphTime(cities, edges, "price times cost"); RouteCalculatorService routeCalcPrice = new RouteCalculatorService(graphPrice); ShortestPathResult resultPrice = routeCalcPrice.CalculateShortestPath(source, destination); List <City> pathPrice = routeCalcPrice.GetCityPath(resultPrice); RouteCalculatorService routeCalcTime = new RouteCalculatorService(graphTime); ShortestPathResult resultTime = routeCalcPrice.CalculateShortestPath(source, destination); List <City> pathTime = routeCalcTime.GetCityPath(resultTime); RouteCalculatorService routePriceTime = new RouteCalculatorService(graphPriceTime); ShortestPathResult resultPriceTime = routeCalcPrice.CalculateShortestPath(source, destination); List <City> pathPriceTime = routeCalcTime.GetCityPath(resultPriceTime); this.SaveParcel(parcel); var cPath = new PathDTO() { Cities = ReturnCityDtos(pathPrice), Duration = 42, Price = resultPrice.Distance }; var fPath = new PathDTO() { Cities = ReturnCityDtos(pathTime), Duration = resultTime.Distance, Price = 42 }; var bPath = new PathDTO() { Cities = ReturnCityDtos(pathPriceTime), Duration = resultPriceTime.Distance, Price = 42 }; return(new SearchResultDTO { Cheapest = cPath, Fastest = fPath, Best = bPath }); }
protected override void Seed(DAL.TLContext context) { var cities = MappingService.GetCities(); cities.ForEach(city => context.City.AddOrUpdate(city)); var edges = MappingService.GetEdges(cities); edges.ForEach(edge => context.Edge.AddOrUpdate(edge)); context.SaveChanges(); // This method will be called after migrating to the latest version. // You can use the DbSet<T>.AddOrUpdate() helper extension method // to avoid creating duplicate seed data. }
public ActionResult SearchResult(int width, int height, int length, int weight, string sourceCity, string destinationCity, string parcelType) { var cities = MappingService.GetCities(); var destination = new City(destinationCity); destination.ID = GetCityId(destination.Name, cities); var source = new City(sourceCity); source.ID = GetCityId(source.Name, cities); var dimensions = new Dimension(width, height, length); var parcelTypes = GetParcelTypes(parcelType.Split(',').ToList()); var parcel = new Parcel(destination, source, dimensions, null, null, parcelTypes); var result = ClickCalculate(parcel, source, destination); return(PartialView(result)); }
public ActionResult Home() { IList <Edge> edges; IList <City> cities2; using (var context = new TLContext()) { edges = context.GetAllEdges(); cities2 = context.GetCities().ToList(); } var cities = MappingService.GetCities(); var dtoCities = new List <CityDTO>(); foreach (var city in cities) { dtoCities.Add(new CityDTO() { Id = city.ID, Name = city.Name }); } var parcelTypes = MappingService.GetParcelTypes(); var dtoParcelTypes = new List <ParcelTypeDTO>(); foreach (var parcelType in parcelTypes) { dtoParcelTypes.Add(new ParcelTypeDTO() { Id = parcelType.ID, Name = parcelType.Name }); } var model = new HomeDTO { SourceCitites = dtoCities, DestinationCitites = dtoCities, ParcelTypes = dtoParcelTypes }; return(View(model)); }