public void SeedData() { if (!Categories.Any()) { var appliances = new Category() { Name = "Appliances", Subcategories = new List <Category>() { new Category() { Name = "Microwaves" } } }; Categories.Add(appliances); SaveChanges(); } if (!Cities.Any()) { Cities.AddRange( new City { Name = "New York" }, new City { Name = "Seattle" }, new City { Name = "San Francisco" }); SaveChanges(); } }
/// <summary> /// В этом закрытом методе заполняются списки Cities, Directions данными из файла input.txt /// </summary> void Filling() { if (Lines != null) { foreach (var line in Lines) { var split = line.Replace(" ", string.Empty).Replace("\"", string.Empty).Split('→'); City cityFrom = new City(split.First()); City cityTo = new City(split.Last()); if (!Cities.Any(c => c.Name == cityFrom.Name)) { Cities.Add(cityFrom); } if (!Cities.Any(c => c.Name == cityTo.Name)) { // здесь указывется что данный город не является точкой отсчета т.к. он является пунктом назначения на данном этапе cityTo.IsNotRoot = true; Cities.Add(cityTo); } else { //этот город был пунктом откправления но в данном случае он является пунктом назначения Cities.FirstOrDefault(c => c.Name == cityTo.Name).IsNotRoot = true; } Directions.Add(new Direction(cityFrom, cityTo)); } } }
private void SeedForecasts(int maxDays) { if (maxDays < 1) { throw new InvalidSeedDataException("Expected maxDays to be at least 1."); } if (!Cities.Any()) { throw new InvalidSeedOrderException("Cities must be seeded first."); } foreach (var city in Cities) { for (int days = 1; days <= maxDays; days++) { Forecasts.Add(new Forecast(city, days)); } } }
public void Initialize() { _attentionCode = 0x00; // 0b00000000 // MORALE { _morale = Convert.ToInt32(Cities.Average(city => city.Morale)); _moraleColumn = _morale + " Avg"; _moraleModifiersColumn = ""; foreach (HCity city in _cities) { int sum = city.MoraleModifiers.Values.Sum(); if (!_moraleModifiers.Contains(sum)) { if (_moraleModifiersColumn != "") { _moraleModifiersColumn += ", "; } _moraleModifiersColumn += sum.ToString("+#0;-#0;±#0"); } _moraleModifiers.Add(sum); } _moraleModifiersColumn = Math.Floor(_moraleModifiers.Average()).ToString("+#0;-#0;±#0") + " (" + _moraleModifiersColumn + ")"; _moraleOverview = "WIP"; } // Decay { _abandonment = Cities.Min(city => city.Abandonment); _abandonmentMax = Cities.Min(city => city.AbandonmentMax); bool decaying = Cities.Any(city => city.DistressOverview.Contains("City is decaying.")); if (decaying) { _abandonmentColumn = " Decaying"; } else if (_abandonmentMax < Hazeron.AbandonmentInterval) { _abandonmentColumn = " Unstable"; } else if (_abandonment == _abandonmentMax) { _abandonmentColumn = _abandonment.ToString("00") + "~/" + _abandonmentMax.ToString("00") + " days"; } else if (_abandonment > 0) { _abandonmentColumn = _abandonment.ToString("00") + " /" + _abandonmentMax.ToString("00") + " days"; } else { _abandonmentColumn = " ERROR!?"; } } // POPULATION & LIVING CONDITIONS { _population = Cities.Sum(city => city.Population); _homes = Cities.Sum(city => city.Homes); _jobs = Cities.Sum(city => city.Jobs); _populationLimit = Cities.Sum(city => city.PopulationLimit); _populationColumn = "Population " + _population + ", Homes " + _homes; _loyalty = Cities.Sum(city => city.Loyalty); _loyaltyColumn = _loyalty + " citizens (" + Math.Round(((float)_loyalty / _population) * 100, 2) + "%)"; } // Population overwiew { _populationOverview = "City's population:"; _populationOverview += Environment.NewLine + " " + _loyalty.ToString().PadLeft(5) + ", Loyal citizens"; if (_loyalty != _population) { int minutesToLoyal; bool disloyal = (_cities.Min(city => city.Loyalty) < 0); if (!disloyal) { minutesToLoyal = ((_cities.Max(city => (city.Population - city.Loyalty))) * 13); } else { minutesToLoyal = (Math.Abs(_loyalty) * 13); } _populationOverview += " [color=" + (disloyal ? "red" : "orange") + "]("; if (minutesToLoyal < 120) // Less than two hours. { _populationOverview += minutesToLoyal + " minutes"; } else if (minutesToLoyal < 2980) // Less than two days. { _populationOverview += (minutesToLoyal / 60) + " hours"; } else // More than two days. { _populationOverview += (minutesToLoyal / 1490) + " days"; } _populationOverview += " to " + (disloyal ? "loyal" : "full") + ")[/color]"; } _populationOverview += Environment.NewLine + " " + _population.ToString().PadLeft(5) + ", Citizens"; _populationOverview += Environment.NewLine + " " + _homes.ToString().PadLeft(5) + ", Homes"; _populationOverview += Environment.NewLine + " " + _jobs.ToString().PadLeft(5) + ", Jobs"; _populationOverview += Environment.NewLine + " " + _populationLimit.ToString().PadLeft(5) + ", Population limit"; } // Technology overview { _technologyOverview = ""; _reseatchProjects = new Dictionary <string, int>(); _factilitiesTL = new Dictionary <string, int>(); // Get all the info from the cities foreach (HCity city in Cities) { foreach (KeyValuePair <string, int> project in city.ReseatchProjects) { if (!_reseatchProjects.ContainsKey(project.Key)) { _reseatchProjects.Add(project.Key, project.Value); } else { _reseatchProjects[project.Key] += project.Value; } } foreach (KeyValuePair <string, int> tech in city.FactilitiesTL) { if (!_factilitiesTL.ContainsKey(tech.Key)) { _factilitiesTL.Add(tech.Key, tech.Value); } else if (_factilitiesTL[tech.Key] != tech.Value) { _factilitiesTL[tech.Key] = -Math.Max(Math.Abs(_factilitiesTL[tech.Key]), Math.Abs(tech.Value)); } } } if (_reseatchProjects.Count != 0) { _technologyOverview = "System's technology projects:"; foreach (string building in _reseatchProjects.Keys) { if (_factilitiesTL.ContainsKey(building)) { _technologyOverview += Environment.NewLine + " " + _reseatchProjects[building].ToString().PadLeft(2) + " (TL" + Math.Abs(_factilitiesTL[building]).ToString().PadLeft(2) + ") running, " + building; } else { _technologyOverview += Environment.NewLine + " [color=red]" + _reseatchProjects[building].ToString().PadLeft(2) + " running, " + building + " (wasted, none in city)[/color]"; } } } if (_technologyOverview != "") { _technologyOverview += Environment.NewLine + Environment.NewLine; } _technologyOverview += "System's technology levels:"; List <string> buildingList = _factilitiesTL.Keys.ToList(); buildingList.Sort(); foreach (string building in buildingList) { _technologyOverview += Environment.NewLine + " TL" + Math.Abs(_factilitiesTL[building]).ToString().PadLeft(2) + ", " + building; if (_factilitiesTL[building] < 0) { _technologyOverview += " [color=red](not all cities)[/color]"; } } } // Overview _overview = "WIP"; // AttentionCodes if (false) // Nothing yet! { _attentionCode = (byte)(_attentionCode | 0x01); // 0b00000001 } if (_population < _homes || _population > _homes) // Population not full, or more than full. { _attentionCode = (byte)(_attentionCode | 0x02); // 0b00000010 } if (Hazeron.AbandonmentInterval * 2 >= _abandonment) // Less than or equal to (Hazeron.AbandonmentInterval * 2) days to decay. { _attentionCode = (byte)(_attentionCode | 0x04); // 0b00000100 } if (Hazeron.AbandonmentInterval >= _abandonment) // Less than or equal to (Hazeron.AbandonmentInterval) days to decay. { _attentionCode = (byte)(_attentionCode | 0x08); // 0b00001000 } if (_population == 0 || _population > _populationLimit) // Population is 0, or zone over populated! { _attentionCode = (byte)(_attentionCode | 0x10); // 0b00010000 } if (false) // Nothing yet! { _attentionCode = (byte)(_attentionCode | 0x20); // 0b00100000 } if (_morale < 20) // Morale not full. { _attentionCode = (byte)(_attentionCode | 0x40); // 0b01000000 } if (false) // Nothing yet! { _attentionCode = (byte)(_attentionCode | 0x80); // 0b10000000 } _initialized = true; }
public SalesmanVM() { model = new SalesmanM(AreaWidth - 30, AreaHeight - 30, 0); AlgorithmCBs = new ObservableCollection <AlgorithmCB>() { new AlgorithmCB() { Id = AlgorithmType.Astar, Name = "A*" }, new AlgorithmCB() { Id = AlgorithmType.NearestNeighbour, Name = "Nearest Neighbour" }, new AlgorithmCB() { Id = AlgorithmType.SimulatedAnnealing, Name = "Simulated Annealing" }, new AlgorithmCB() { Id = AlgorithmType.AntColony, Name = "AntColony" } }; Cities = new ObservableCollection <City>(); Edges = new ObservableCollection <Edge>(); VisitedCities = new ObservableCollection <City>(); CurrentEdges = new ObservableCollection <Edge>(); CurrentBestEdge = new ObservableCollection <Edge>(); FinalEdges = new ObservableCollection <Edge>(); CurrentFinalEdges = new ObservableCollection <Edge>(); BindingOperations.EnableCollectionSynchronization(CurrentEdges, _lockCurrentEdges); BindingOperations.EnableCollectionSynchronization(FinalEdges, _lockFinalEdges); BindingOperations.EnableCollectionSynchronization(CurrentFinalEdges, _lockCurrentFinalEdges); BindingOperations.EnableCollectionSynchronization(VisitedCities, _lockVisitedCities); BindingOperations.EnableCollectionSynchronization(CurrentBestEdge, _lockCurrentBestEdges); drawGraph = new RelayCommand() { CanExecuteDelegate = x => true, ExecuteDelegate = x => { VisitedCities.Clear(); FinalEdges.Clear(); CurrentEdges.Clear(); CurrentBestEdge.Clear(); model.GenerateRandomCities(CitiesAmount); model.GenerateRandomDistances(); Cities = new ObservableCollection <City>(model.Cities); Edges = new ObservableCollection <Edge>(model.Edges); OnPropertyChanged(nameof(Cities)); OnPropertyChanged(nameof(Edges)); OnPropertyChanged(nameof(VisitedCities)); OnPropertyChanged(nameof(FinalEdges)); OnPropertyChanged(nameof(CurrentEdges)); OnPropertyChanged(nameof(CurrentBestEdge)); } }; runCommand = new RelayCommand() { CanExecuteDelegate = x => Cities.Any(), ExecuteDelegate = x => { VisitedCities.Clear(); FinalEdges.Clear(); CurrentEdges.Clear(); CurrentBestEdge.Clear(); OnPropertyChanged(nameof(VisitedCities)); OnPropertyChanged(nameof(FinalEdges)); OnPropertyChanged(nameof(CurrentEdges)); OnPropertyChanged(nameof(CurrentBestEdge)); Task.Factory.StartNew(() => { Tuple <int, string> result = model.TSP(AlgorithmCBPicked.Id, Delay, VisitedCities, CurrentEdges, CurrentBestEdge, CurrentFinalEdges, FinalEdges); Path = result.Item2; BestDistance = result.Item1.ToString(); }); } }; }
public bool HasWonder <T>() where T : IWonder => Cities.Any(c => c.HasWonder <T>());
public bool HasWonder <T>() where T : IWonder { return(Cities.Any(c => c.HasWonder <T>())); }
public bool ApplyCities() => Cities != null && Cities.Any();
public void SeedData() { if (!Categories.Any()) { var appliances = new Category() { Name = "Appliances", SubCategories = new List <Category>() { new Category() { Name = "Microwaves" } } }; Categories.Add(appliances); SaveChanges(); } if (!Cities.Any()) { Cities.AddRange( new City { Name = "New York" }, new City { Name = "Seattle" }, new City { Name = "San Francisco" }); SaveChanges(); } if (!Users.Any()) { Users.AddRange( new User() { Id = "*****@*****.**" }, new User() { Id = "*****@*****.**" }, new User() { Id = "*****@*****.**" }, new User() { Id = "*****@*****.**" }); SaveChanges(); } //if (!Products.Any()) //{ // Products.AddRange( // new Product // { // Owner = Users.SingleOrDefault(u => u.Id == "*****@*****.**"), // Title = "Frigidaire", // Description =@"This classic top freezer refrigerator from Frigidaire is an excellent piece // for a starter kitchen. The Store-More™ door shelves featuring gallon storage offer plenty of // room for condiments and drinks.", // Category = Categories.SingleOrDefault(c => c.Name == "Appliances"), // City = Cities.SingleOrDefault(c => c.Name == "San Francisco"), // PublishDate = DateTime.Now // }, // new Product // { // Owner = Users.SingleOrDefault(u => u.Id == "*****@*****.**"), // Title = "Dyson V8 Absolute vacuum cleaner", // Description = @"The Dyson V8 Absolute vacuum cleaner has a soft roller cleaner head for // hard floors and a motorized cleaner head to remove dirt from carpets. In nickel/iron.", // Category = Categories.SingleOrDefault(c => c.Name == "Appliances"), // City = Cities.SingleOrDefault(c => c.Name == "Seattle"), // PublishDate = DateTime.Now // }, // new Product // { // Owner = Users.SingleOrDefault(u => u.Id == "*****@*****.**"), // Title = "Whirlpool", // Description = @"1.7 cu. ft. Over the Range Microwave in Stainless Steel with Electronic Touch Controls", // Category = Categories.SingleOrDefault(c => c.Name == "Microwaves"), // City = Cities.SingleOrDefault(c => c.Name == "New York"), // PublishDate = DateTime.Now // } // ); // SaveChanges(); //} }