예제 #1
0
        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));
        }
예제 #2
0
        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;
            }
        }
예제 #3
0
        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;
            }
        }
예제 #4
0
 public CityInPath(CityInPath cityInPath)
 {
     this.CityId             = cityInPath.CityId;
     this.FirstConnectionId  = cityInPath.FirstConnectionId;
     this.SecondConnectionId = cityInPath.SecondConnectionId;
 }