Beispiel #1
0
 public void BuildMatrix()
 {
     CountNumberOfUniquePoints();
     _timeMatrix     = new IndexKeyMatrix <string, double>(NumberOfUniquePoints);
     _distanceMatrix = new IndexKeyMatrix <string, double>(NumberOfUniquePoints);
     _wayMatrix      = new int[NumberOfUniquePoints, NumberOfUniquePoints];
     for (int i = 0; i < NumberOfUniquePoints; i++)
     {
         for (int j = 0; j < NumberOfUniquePoints; j++)
         {
             _timeMatrix[i, j]     = 0;
             _distanceMatrix[i, j] = 0;
             _wayMatrix[i, j]      = 0;
         }
     }
     foreach (Way way in Ways)
     {
         for (int k = 0; k < way.Count - 1; k++)
         {
             double dTime     = Math.Abs(way[k + 1] - way[k]);
             double dDistance = Math.Abs(way[k + 1].Position - way[k].Position);
             _timeMatrix.Add(dTime, way[k].Title, way[k + 1].Title);
             _timeMatrix.Add(dTime, way[k + 1].Title, way[k].Title);
             _distanceMatrix.Add(dDistance, way[k].Title, way[k + 1].Title);
             _distanceMatrix.Add(dDistance, way[k + 1].Title, way[k].Title);
         }
     }
 }
Beispiel #2
0
        public void WayBetween(string start_, string stop_, bool isByTime = true)
        {
            int start = _timeMatrix[start_];
            int stop  = _timeMatrix[stop_];

            pathDisplay = new Stack <double>();
            if (start > stop)
            {
                int tmp = start;
                start = stop;
                stop  = tmp;
                string tmp_ = start_;
                start_ = stop_;
                stop_  = tmp_;
            }
            this.isByTime = isByTime;
            if (isByTime)
            {
                _workMatrix = _timeMatrix;
            }
            else
            {
                _workMatrix = _distanceMatrix;
            }
            FindTheShortestWays();
            path.Push(stop_);
            FindShortestPathBetween(start, stop);
            path.Push(start_);
        }