Beispiel #1
0
        public void CalculateDijkstra()
        {
            OnDijkstraStepPerformed(new StepEventArgs("", "begin"));
            foreach (Vertex v in VertexCollection) // for each v∈V
            {
                v.Distance = Int32.MaxValue;       // d[v]←∞
                v.Previous = null;                 // π[v]←∅
            }
            Source.Distance = 0;                   // d[s]←0
            OnDijkstraStepPerformed(new StepEventArgs("", "init"));
            List <Vertex> S = new List <Vertex>(); // S←∅

            OnDijkstraStepPerformed(new StepEventArgs(S, "S"));
            List <Vertex> Q = VertexCollection.ToList();// Q←V

            bool finished = false;

            while (!finished)
            {
                Vertex u = Q.OrderBy(n => n.Distance).FirstOrDefault(n => n.Distance != Int32.MaxValue);// u←ExtractMin(Q)
                if (u != null)
                {
                    Q.Remove(u);

                    OnDijkstraStepPerformed(new StepEventArgs(u, "min"));

                    foreach (Edge e in u.Edges)// for each v∈Adj[u]
                    {
                        Int32 distance = u.Distance + e.Weight;
                        if (distance < e.Target.Distance) // if d[v]<d[u]+w(u,v)
                        {
                            e.Target.Distance = distance; // d[v]←d[u]+w(u,v)
                            e.Target.Previous = u;        // π[v]=u
                        }
                        OnDijkstraStepPerformed(new StepEventArgs(e, "relax"));
                    }
                    S.Add(u);// S←S∪{u}
                    OnDijkstraStepPerformed(new StepEventArgs(S, "S"));
                }
                else
                {
                    finished = true;
                }
            }
            OnDijkstraStepPerformed(new StepEventArgs("", "end"));
        }
Beispiel #2
0
 public void RemoveVertex(Vertex vertex)
 {
     VertexCollection.Remove(vertex);
 }
Beispiel #3
0
 public Graph(Boolean isAutomaticWeights)
 {
     IsAutomaticWeights = isAutomaticWeights;
     VertexCollection   = new VertexCollection(this);
     EdgeCollection     = new EdgeCollection(this);
 }
Beispiel #4
0
        public void AddVertex(PointF location)
        {
            Vertex v = new Vertex(VertexCollection, location);

            VertexCollection.Add(v);
        }
Beispiel #5
0
 public Vertex(VertexCollection vertexCollection, PointF location)
 {
     VertexCollection = vertexCollection;
     Location         = location;
 }