Пример #1
0
        //public Agent()
        // {
        //  _dRouteLength = 0;
        //  _route = null;
        // Маршрута-то ещё нет!
        // for (int i = 0; i < Route.Cities.Count; i++)
        // {
        //     _liTaboo.Add(false);// первоначальное заполнение нулями
        // }

        //}

        /// <summary>
        /// Create new agent
        /// </summary>
        /// <param name="cc">Cities collection to create Agent's Route</param>
        public Agent(CitiesCollection cc)
        {
            // Temporary collection
            CitiesCollection tmpCC = new CitiesCollection();

            // List of remained city indexes
            List <int> _liRemIndexes = new List <int>();

            for (int i = 0; i < cc.Count; i++)
            {
                _liRemIndexes.Add(i);
            }


            tmpCC.MaxDistance = cc.MaxDistance;

            int nextCityIndex;

            // Constructing random route
            do
            {
                nextCityIndex = _rnd.Next(_liRemIndexes.Count);

                City tmpc = new City();
                tmpc = cc[_liRemIndexes[nextCityIndex]];
                _liRemIndexes.Remove(_liRemIndexes[nextCityIndex]);
                tmpCC.Add(tmpc);
            }while (_liRemIndexes.Count > 0);

            this.Route = new Route(tmpCC, "генетический алгоритм");
        }
Пример #2
0
 /// <summary>
 /// Конструктор
 /// </summary>
 public Route(CitiesCollection cities, string name) : this(name)
 {
     _cities = cities;
     LengthCalculation(); //расчет длинны маршрута
 }
Пример #3
0
 public CitiesCollection(CitiesCollection CC)
 {
     this._liCities = new List <City>(CC._liCities);
     this._iCount   = CC._iCount;
     DistanceCalculate();
 }