Ejemplo n.º 1
0
 /// <summary>
 ///retourne le poid entre 2 noeuds
 /// </summary>
 /// <param name="n1">Noeud 1</param>
 /// <param name="n2">Noeud 2</param>
 /// <returns>poids entre les 2 noeuds</returns>
 public int GetWeight(Node n1, Node n2)
 {
     int value = -1;
     foreach (Edge edge in Edges)
     {
         if (edge.A == n1 && edge.B == n2)
         {
             value = edge.Weight;
         }
     }
     return value;
 }
Ejemplo n.º 2
0
        public Node ExtractMin()
        {
            double min = double.PositiveInfinity;
            Node toRemove = new Node();

            foreach (Node node in NodeTampon)
            {
                if (node.Value < min)
                {
                    min = node.Value;
                    toRemove = node;
                }
            }
            return toRemove;
        }
Ejemplo n.º 3
0
 /// <summary>
 /// retourne le poid entre 2 noeuds
 /// </summary>
 /// <param name="n1">Noeud 1</param>
 /// <param name="n2">Noeud 2</param>
 /// <returns>Poids entre les 2 noeuds</returns>
 public int GetWeightDijkstra(Node n1, Node n2)
 {
     int value = 0;
     foreach (Edge edge in Edges)
     {
         if (edge.A == n1 && edge.B == n2)
         {
             value = edge.Weight;
         }
         else if (edge.B == n1 && edge.A == n2)
         {
             value = edge.Weight;
         }
     }
     return value;
 }
Ejemplo n.º 4
0
        /// <summary>
        /// trouve les noeuds voisins
        /// </summary>
        /// <param name="node"></param>
        /// <returns></returns>
        public List<Node> GetNeighbors(Node node)
        {
            List<Node> neighbors = new List<Node>();

            foreach (Edge e in Edges)
            {
                if (e.A.Equals(node))
                {
                    neighbors.Add(e.B);
                }
                else if (e.B.Equals(node))
                {
                    neighbors.Add(e.A);
                }
            }
            return neighbors;
        }
Ejemplo n.º 5
0
 /// <summary>
 /// Relâche Les noeuds ,si la valeur du Noeud 2 est supérieur à la valeur du Noeud 1 + (valeur noeud1 +noued2 )
 /// affecte cette valeur au noeud 2 et le noeud 1 devient son parent
 /// </summary>
 /// <param name="n1">Noeud 1</param>
 /// <param name="n2">Noeud 2</param>
 public void Relax(Node n1, Node n2)
 {
     if (n2.Value > (n1.Value + GetWeight(n1, n2)))
     {
         n2.Value = n1.Value + GetWeight(n1, n2);
         n2.parent = n1;
     }
 }