Exemplo n.º 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));
        }
Exemplo n.º 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;
            }
        }
Exemplo n.º 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;
            }
        }
Exemplo n.º 4
0
 public CityInPath(CityInPath cityInPath)
 {
     this.CityId             = cityInPath.CityId;
     this.FirstConnectionId  = cityInPath.FirstConnectionId;
     this.SecondConnectionId = cityInPath.SecondConnectionId;
 }