private void AddCityToPath(int lastElementId, int newCityId) { var lastElement = wholePath[lastElementId]; lastElement.SecondConnectionId = newCityId; var cityToAdd = new CityInPath { CityId = newCityId, FirstConnectionId = lastElementId }; wholePath.Add(newCityId, new CityInPath(cityToAdd)); }
public void GeneratePath(int startingCityId, Dictionary <int, City> _citiesDictionary) { this.citiesDictionary = _citiesDictionary; this.startingCityId = startingCityId; wholePath = new Dictionary <int, CityInPath>(); var startingCity = new CityInPath(startingCityId); wholePath.Add(startingCityId, startingCity); var numberOfCitiesOutsidePath = GetCityIdsOutsidePath().Count(); var random = new Random(); var lastElementId = startingCityId; while (numberOfCitiesOutsidePath != 0) { var closestNeighbourId = GetLastElementClosestNeighbourId(lastElementId); AddCityToPath(lastElementId, closestNeighbourId); numberOfCitiesOutsidePath--; lastElementId = closestNeighbourId; } }
public void GenerateRandomPath(int startingCityId, Dictionary <int, City> _citiesDictionary) { this.citiesDictionary = _citiesDictionary; this.startingCityId = startingCityId; wholePath = new Dictionary <int, CityInPath>(); var startingCity = new CityInPath(startingCityId); wholePath.Add(startingCityId, startingCity); var numberOfCitiesOutsidePath = GetCityIdsOutsidePath().Count(); var random = new Random(); var lastElementId = startingCityId; while (numberOfCitiesOutsidePath != 0) { var closestNeighboursIds = GetClosestNeighboursIdsOfLastElement(lastElementId, 2); var randomCityIndex = closestNeighboursIds.ElementAt(random.Next(closestNeighboursIds.Count)); //taking one random city from best results AddCityToPath(lastElementId, randomCityIndex); numberOfCitiesOutsidePath--; lastElementId = randomCityIndex; } }
public CityInPath(CityInPath cityInPath) { this.CityId = cityInPath.CityId; this.FirstConnectionId = cityInPath.FirstConnectionId; this.SecondConnectionId = cityInPath.SecondConnectionId; }