Exemplo n.º 1
0
        public void CalcShortestDistSum()
        {
            ICityStorage queue         = new CityStorage();
            ICityStorage resultStorage = new CityStorage();

            queue.Add(this);
            _distSums.SetData(_id, 0);

            while (!queue.isEmpty())
            {
                int   index           = 0;
                ICity currentCity     = GetMinFromTabAndStor(_distSums, queue, ref index);
                int   CurrentCityDist = _distSums.GetInfo(currentCity.Id);
                for (int i = 0; i < currentCity.GetCntOfNeighbors(); i++)
                {
                    ICity currentNeighbor = currentCity.GetNeighbor(i);
                    int   tmpDist         = currentCity.GetWeightToNeighbor(currentNeighbor.Id) + CurrentCityDist;

                    if (tmpDist < _distSums.GetInfo(currentNeighbor.Id))
                    {
                        _distSums.SetData(currentNeighbor.Id, tmpDist);
                        queue.Add(currentNeighbor);//new
                    }
                    if (!CheckIsItHere(resultStorage, currentNeighbor) &&
                        !CheckIsItHere(queue, currentNeighbor))
                    {
                        queue.Add(currentNeighbor);
                    }
                }
                resultStorage.Add(currentCity);
                queue.Delete(index);
            }
        }
 public Form1()
 {
     InitializeComponent();
     storage  = new CityStorage();
     drawMode = "city";
 }