Ejemplo n.º 1
0
 public Graph(Nodes n, Edges e)
 {
     nodes = n;
     edges = e;
     home = null;
     destination = null;
 }
Ejemplo n.º 2
0
 public bool Contains(Node n)
 {
     for(int i=0; i<list.Count; i++)
     {
         if(((Node)list[i]).Equals(n))
             return true;
     }
     return false;
 }
Ejemplo n.º 3
0
 //Checks if the two nodes have an edge connecting them
 public static bool hasEdge(Node a, Node b)
 {
     for(int i=0; i<a.Edges.Length(); i++)
     {
         if(a.Edges[i].NodeA.Equals(b) || a.Edges[i].NodeB.Equals(b))
         {
             return true;
         }
     }
     return false;
 }
Ejemplo n.º 4
0
 public Edge(Node n1, Node n2, InkOverlay i, int weight)
 {
     //Keep track of the nodes its attached to
     this.a = n1;
     this.b = n2;
     this.weight = weight;
     color = DEFAULT;
     //Make sure the nodes contain this in their edges
     a.Edges.Add(this);
     b.Edges.Add(this);
     Point[] p = {a.CenterPoint,b.CenterPoint};
     //Draw a stroke connecting both nodes
     this.stroke = i.Ink.CreateStroke(p);
 }
Ejemplo n.º 5
0
        /* Assigns the following node to either home or destination
         * depending on what was previously assigned
         */
        public void AssignNode(Node n)
        {
            if(n.Equals(destination))
            {
                destination = null;
                home = n;
            }
            else if(home == null)
            {
                home = n;
            }
            else if(destination == null)
            {
                destination = n;
            }
            else
            {

                Node tmp = destination;
                destination = n;
                home = tmp;
            }
        }
Ejemplo n.º 6
0
 public void Add(Node n)
 {
     list.Add(n);
 }
Ejemplo n.º 7
0
 public void Remove(Node a)
 {
     list.Remove(a);
 }
Ejemplo n.º 8
0
        /* Pops a node from the PQ and checks whether it is
         * the destination node or was the last node in the PQ
         * and terminates the animation if necessary.  Colors
         * popNode and its incoming edge as appropriate.
         */
        private void step1()
        {
            if(!pq.Contains(graph.Home) && !popped.Contains(graph.Home))
            {
                graph.Home.Distance = 0;
                pq.Add(graph.Home);
            }
            updateText();
            if(pq.Count <= 0)
            {
                stepCount = -1;
                finalize(false);
                return;
            }
            popNode = pq.Pop() as Node;
            popNode.Color = POPPED_N;

            if(incomingEdge[popNode] != null)
                ((Edge)incomingEdge[popNode]).Color = POPPED_E;

            popped.Add(popNode);
            if(popNode.Equals(graph.Destination))
            {
                stepCount = -1;
                finalize(true);
                return;
            }
            stepCount = 1;
        }
Ejemplo n.º 9
0
 //Get the node attached to Edge e that isn't Node n
 public static Node GetOther(Node n, Edge e)
 {
     if(n == null || !n.Edges.Contains(e)) return null;
     return (n.Equals(e.NodeB)) ? e.NodeA : e.NodeB;
 }
Ejemplo n.º 10
0
 public Edge(Node n1, Node n2, InkOverlay i)
     : this(n1,n2,i,Edge.DEFAULT_WEIGHT)
 {
 }
Ejemplo n.º 11
0
 private void RemoveNode(Node dead)
 {
     if(dead.Equals(home)) home = null;
     if(dead.Equals(destination)) destination = null;
     while(dead.Edges.Length()>0)
     {
         Edge e = dead.Edges[dead.Edges.Length()-1];
         RemoveEdge(e);
     }
     nodes.Remove(dead);
     dead.Stroke.Ink.DeleteStroke(dead.Stroke);
 }
Ejemplo n.º 12
0
 public void Clear()
 {
     nodes.Clear();
     edges.Clear();
     home = destination = null;
 }