Exemple #1
0
 public void addEdge(Arrow q, Arrow w, double l)
 {
     g[AtoI[q]].Add(new KeyValuePair <int, double>(AtoI[w], l));
     g[AtoI[w]].Add(new KeyValuePair <int, double>(AtoI[q], l));
 }
Exemple #2
0
        private bool Dijkstra1()
        {
            minL       = new Dictionary <Arrow, double>();
            prevA      = new Dictionary <Arrow, Arrow>();
            prevR      = new Dictionary <Arrow, Road>();
            previewMin = new List <KeyValuePair <Arrow, double> >();

            Arrow[] s = Start.GetArrow();
            Road[]  temp;
            Arrow   th;
            KeyValuePair <Arrow, double> tr;

            foreach (Arrow item in s)
            {
                StartArrows.Add(item);
                minL.Add(item, 0);
                temp = item.GetRoadPlatform();
                foreach (Road j in temp)
                {
                    if (!disable.Contains(j))
                    {
                        th       = j.GetArrow(item);
                        minL[th] = j.Lenght;
                        previewMin.Add(new KeyValuePair <Arrow, double>(th, j.Lenght));
                        prevA[th] = item;
                        prevR[th] = j;
                    }
                }
            }
            while (previewMin.Count != 0)
            {
                previewMin.Sort(comp);
                tr   = previewMin[0];
                temp = tr.Key.GetRoad(prevR[tr.Key]);
                for (int i = 0; i < temp.Length; i++)
                {
                    if (!disable.Contains(temp[i]))
                    {
                        th = temp[i].GetArrow(tr.Key);
                        if (minL.ContainsKey(th))
                        {
                            if (minL[tr.Key] + temp[i].Lenght < minL[th])
                            {
                                int z = previewMin.IndexOf(new KeyValuePair <Arrow, double>(th, minL[th]));
                                if (z > -1)
                                {
                                    previewMin[z] = new KeyValuePair <Arrow, double>(th, minL[tr.Key] + temp[i].Lenght);
                                }
                                minL[th]  = minL[tr.Key] + temp[i].Lenght;
                                prevA[th] = tr.Key;
                                prevR[th] = temp[i];
                            }
                        }
                        else
                        {
                            minL[th]  = minL[tr.Key] + temp[i].Lenght;
                            prevA[th] = tr.Key;
                            prevR[th] = temp[i];
                        }
                    }
                }
            }
            s = Finish.GetArrow();
            double minn = Inf;
            int    qq   = -1;

            for (int i = 0; i < s.Length; i++)
            {
                if (minL.ContainsKey(s[i]))
                {
                    if (minn > minL[s[i]])
                    {
                        minn = minL[s[i]];
                        qq   = i;
                    }
                }
            }
            finished = s[qq];
            if (qq == -1)
            {
                finished = null;
                return(false);
            }
            else
            {
                finished = s[qq];
                return(true);
            }
        }