public void BucarCamino(Graph graph) { int x = 100000; int j = 0; int[] distancia = null; // DeclaraciĆ³n del array NodosRecorridos.Clear(); distancia = new int[graph.Count]; // InstanciaciĆ³n del array s.Add(graph[index]); // V.RemoveAt(index); if (index == 0) { for (int i = 0; i < graph.Count; i++) { distancia[i] = ListAdyacencia[0][i]; } } else if (index != 0) { for (int i = 0; i < index; i++) { distancia[i] = ListAdyacencia[index][i]; } for (int i = index + 1; i < graph.Count; i++) { distancia[i] = ListAdyacencia[index][i]; } } for (int i = 0; i < graph.Count; i++) { if (distancia[i] < x) { x = distancia[i]; } } for (int k = 0; k < graph.Count; k++) { foreach (Edge ar in graph.edgesList) { if (graph[k].Name == ar.Source.Name) { distancia[ConvierteLetra(ar.Destiny.Name)] = Minimo(distancia[ConvierteLetra(ar.Destiny.Name)], distancia[ConvierteLetra(ar.Source.Name)] + ListAdyacencia[ConvierteLetra(ar.Source.Name)][(ConvierteLetra(ar.Destiny.Name))]); } } NodosRecorridos.Text += "->" + graph[k].Name + "->"; } textBox1.Text += distancia[index2].ToString(); label5.Text = graph[index].Name + "->" + graph[index2].Name; for (int i = 0; i < graph.Count; i++) { Vector.Text += distancia[i].ToString() + "->"; } }
public void dijkstra(Graph graph) { textBox1.Text = " "; NodosRecorridos.Clear(); label5.Text = " "; Vector.Text = " "; for (int j = 0; j < graph.Count; j++) { auxiliar = new List <int>(); for (int i = 0; i < graph.Count; i++) { auxiliar.Add(0); } ListAdyacencia.Add(auxiliar); } if (graph.Count > 0) //Para saber si la lista tiene elementos { foreach (Edge Ar in graph.edgesList) { //posiciones // i //j ListAdyacencia[ConvierteLetra(Ar.Source.Name)][ConvierteLetra(Ar.Destiny.Name)] = Ar.Weight; // Arista dirigida } } for (int i = 0; i < graph.Count; i++) { for (int j = 0; j < graph.Count; j++) { if (ListAdyacencia[i][j] == 0) { ListAdyacencia[i][j] = 10000; } // if (i == j) // { // ListAdyacencia[i][j] = 0; //} } } for (int i = 0; i < graph.Count; i++) { V.Add(graph[i]); } }