Example #1
0
        // Not valid, check this!
        public List <int> ShortestPath(DijkstraNode start, DijkstraNode end)
        {
            var visited = new HashSet <int>();
            var pq      = new PQ();

            pq.Add(start);

            while (pq.Count() > 0)
            {
                var u = pq.GetMin();
                if (visited.Contains(u.Id))
                {
                    continue;
                }
                visited.Add(u.Id);

                foreach (var n in u.Adjacent)
                {
                    // to nie ma sensu
                    if (u.Distance + n.Distance <= n.Distance)
                    {
                        n.Distance = u.Distance + n.Distance;
                    }

                    pq.AddOrUpdate(n);
                }
            }

            return(visited.ToList());
        }
Example #2
0
        public void AddOrUpdate(DijkstraNode dn)
        {
            if (pq.ContainsKey(dn))
            {
                pq.Remove(dn);
            }

            pq.Add(dn, true);
        }
Example #3
0
 public void Add(DijkstraNode n) => pq.Add(n, true);
Example #4
0
 public void Add(DijkstraNode dn) => Adjacent.Add(dn);