public void LoadVanForCity(Van van, City city) { foreach (var pair in city.Prices.OrderByDescending((x) => x.Value)) { string item = pair.Key; double amount = this.stock[item]; if (amount > van.RemainingCapacity) { amount = van.RemainingCapacity; } if (amount > 0) { van.Load(item, amount); } } var profit = van.Contents.GetProfitForCity(city); if (profit > ProfitForBestCity) { BestCity = city; RevenueForBestCity = van.Contents.GetRevenueForCity(city); ProfitForBestCity = profit; ItemsSoldAtBestCity = van.Contents; } }
public void SelectBestCity(ICollection <City> cities) { foreach (City city in cities) { Van van = new Van(200); LoadVanForCity(van, city); } }
public void SelectBestCity(ICollection<City> cities) { foreach (City city in cities) { Van van = new Van(200); LoadVanForCity(van, city); } }
public void OptimalLoadForOneCity(string cityName, double expectedRevenue, double expectedProfit) { var city = cityIndex[cityName]; var van = new Van(200); this.optimizer.LoadVanForCity(van, city); this.optimizer.DumpResult(); Assert.That(this.optimizer.BestCity.Name, Is.EqualTo(city.Name)); Assert.That(this.optimizer.RevenueForBestCity, Is.EqualTo(expectedRevenue)); Assert.That(this.optimizer.ProfitForBestCity, Is.EqualTo(expectedProfit)); }
public void LoadVanForCity(Van van, City city) { foreach (var pair in city.Prices.OrderByDescending((x) => x.Value)) { string item = pair.Key; double amount = this.stock[item]; if (amount > van.RemainingCapacity) amount = van.RemainingCapacity; if (amount > 0) van.Load(item, amount); } var profit = van.Contents.GetProfitForCity(city); if (profit > ProfitForBestCity) { BestCity = city; RevenueForBestCity = van.Contents.GetRevenueForCity(city); ProfitForBestCity = profit; ItemsSoldAtBestCity = van.Contents; } }
public void CreateVan() { this.van = new Van(200); }