Exemple #1
0
        public vertice nododistanciaminima()
        {
            int     min  = int.MaxValue;
            vertice temp = null;

            foreach (vertice origen in nodos)
            {
                if (origen.Visitado)
                {
                    foreach (vertice destino in nodos)
                    {
                        if (!destino.Visitado)
                        {
                            foreach (arco a in origen.ListaAdyacencia)
                            {
                                if (a.nDestino == destino && min > a.peso)
                                {
                                    min  = a.peso;
                                    temp = destino;
                                }
                            }
                        }
                    }
                }
            }
            return(temp);
        }
Exemple #2
0
        //=====================Operaciones Básicas=================================
        //Construye un nodo a partir de su valor y lo agrega a la lista de nodos
        public vertice AgregarVertice(string valor)
        {
            vertice nodo = new vertice(valor);

            nodos.Add(nodo);
            return(nodo);
        }
Exemple #3
0
 private void mapa_MouseUp(object sender, MouseEventArgs e)
 {
     switch (var_control)
     {
     case 1:     // Dibujando arco
         if ((NodoDestino = grafo.DetectarPunto(e.Location)) != null && NodoOrigen !=
             NodoDestino)
         {
             ventanaArco.Visible = false;
             ventanaArco.control = false;
             ventanaArco.ShowDialog();
             if (ventanaArco.control)
             {
                 if (grafo.AgregarArco(NodoOrigen, NodoDestino, ventanaArco.dato))     //Se procede a crear la arista
                 {
                     int distancia = ventanaArco.dato;
                     NodoOrigen.ListaAdyacencia.Find(v => v.nDestino == NodoDestino).peso =
                         distancia;
                 }
                 nuevoArco = true;
             }
         }
         var_control = 0;
         NodoOrigen  = null;
         NodoDestino = null;
         mapa.Refresh();
         break;
     }
 }
Exemple #4
0
 //Metodo para actualizar información general del arco
 public arco(vertice destino, int peso)
 {
     this.nDestino      = destino;
     this.peso          = peso;
     this.grosor_flecha = 3;
     this.color         = Color.DarkRed;
 }
Exemple #5
0
 // Crea la arista a partir de los nodos de origen y de destino
 public bool AgregarArco(vertice origen, vertice nDestino, int peso = 1)
 {
     if (origen.ListaAdyacencia.Find(v => v.nDestino == nDestino) == null)
     {
         origen.ListaAdyacencia.Add(new arco(nDestino, peso));
         return(true);
     }
     return(false);
 }
Exemple #6
0
 public lista(lista pLista)
 {
     if (pLista != null)
     {
         aElemento = pLista.aElemento;
         aSubLista = pLista.aSubLista;
         aPeso     = pLista.aPeso;
     }
 }
Exemple #7
0
 public principal()
 {
     InitializeComponent();
     grafo             = new grafo();
     nuevoNodo         = null;
     var_control       = 0;
     ventanaVertice    = new verticecrud();
     ventanaArco       = new arcocrud();
     ventanaEditarArco = new editararco();
     nodosOrdenados    = new List <vertice>();
     this.SetStyle(ControlStyles.AllPaintingInWmPaint | ControlStyles.UserPaint | ControlStyles.DoubleBuffer, true);
 }
Exemple #8
0
 public bool ExisteElemento(vertice pElemento)
 {
     if ((aElemento != null) && (pElemento != null))
     {
         return(aElemento.Equals(pElemento) ||
                (aSubLista.ExisteElemento(pElemento)));
     }
     else
     {
         return(false);
     }
 }
Exemple #9
0
 private void recorridoNodoProfundidad(vertice vertice, Graphics g)
 {
     vertice.Visitado = true;
     vertice.colorear(g);
     Thread.Sleep(1000);
     vertice.DibujarVertice(g);
     foreach (arco adya in vertice.ListaAdyacencia)
     {
         if (!adya.nDestino.Visitado)
         {
             recorridoNodoProfundidad(adya.nDestino, g);
         }
     }
 }
Exemple #10
0
 public void Eliminar(vertice pElemento)
 {
     if (aElemento != null)
     {
         if (aElemento.Equals(pElemento))
         {
             aElemento = aSubLista.aElemento;
             aSubLista = aSubLista.SubLista;
         }
         else
         {
             aSubLista.Eliminar(pElemento);
         }
     }
 }
Exemple #11
0
 //Funcion para re-dibujar los arcos que llegan a un nodo
 public void DibujarEntrantes(vertice nDestino)
 {
     foreach (vertice nodo in nodos)
     {
         foreach (arco a in nodo.ListaAdyacencia)
         {
             if (nodo.ListaAdyacencia != null && nodo != nDestino)
             {
                 if (a.nDestino == nDestino)
                 {
                     a.color         = Color.Black;
                     a.grosor_flecha = 2;
                     break;
                 }
             }
         }
     }
 }
Exemple #12
0
 public int PosicionElemento(vertice pElemento)
 {
     if ((aElemento != null) || (ExisteElemento(pElemento)))
     {
         if (aElemento.Equals(pElemento))
         {
             return(1);
         }
         else
         {
             return(1 + aSubLista.PosicionElemento(pElemento));
         }
     }
     else
     {
         return(0);
     }
 }
Exemple #13
0
 public void Agregar(vertice pElemento, int pPeso)
 {
     if (pElemento != null)
     {
         if (aElemento == null)
         {
             aElemento = new vertice(pElemento.Valor);
             aPeso     = pPeso;
             aSubLista = new lista();
         }
         else
         {
             if (!ExisteElemento(pElemento))
             {
                 aSubLista.Agregar(pElemento, pPeso);
             }
         }
     }
 }
Exemple #14
0
 private void recorridoNodoAnchura(vertice vertice, Graphics g, string destino)
 {
     vertice.Visitado = true;
     cola.Enqueue(vertice);
     vertice.colorear(g);
     Thread.Sleep(1000);
     vertice.DibujarVertice(g);
     if (vertice.Valor == destino)
     {
         nodoEncontrado = true;
         return;
     }
     while (cola.Count > 0)
     {
         vertice aux = (vertice)cola.Dequeue();
         foreach (arco adya in aux.ListaAdyacencia)
         {
             if (!adya.nDestino.Visitado)
             {
                 if (!nodoEncontrado)
                 {
                     adya.nDestino.Visitado = true;
                     adya.nDestino.colorear(g);
                     Thread.Sleep(1000);
                     adya.nDestino.DibujarVertice(g);
                     if (destino != "")
                     {
                         distancia += adya.peso;
                     }
                     cola.Enqueue(adya.nDestino);
                     if (adya.nDestino.Valor == destino)
                     {
                         nodoEncontrado = true;
                         return;
                     }
                 }
             }
         }
     }
 }
Exemple #15
0
 private void mapa_MouseDown(object sender, MouseEventArgs e)
 {
     if (e.Button == System.Windows.Forms.MouseButtons.Left) // Si se ha presionado el botón
     // izquierdo del mouse
     {
         if ((NodoOrigen = grafo.DetectarPunto(e.Location)) != null)
         {
             var_control = 1; // recordemos que es usado para indicar el estado en la pizarra:
             // 0 -> sin accion, 1 -> Dibujando arco, 2 -> Nuevo vértice
         }
         if (nuevoNodo != null && NodoOrigen == null)
         {
             ventanaVertice.Visible = false;
             ventanaVertice.control = false;
             ventanaVertice.ShowDialog();
             numeronodos = grafo.nodos.Count;//cuenta cuantos nodos hay en el grafo
             if (ventanaVertice.control)
             {
                 if (grafo.BuscarVertice(ventanaVertice.dato) == null)
                 {
                     grafo.AgregarVertice(nuevoNodo);
                     nuevoNodo.Valor = ventanaVertice.dato;
                 }
                 else
                 {
                     label5.Text      = "El Nodo " + ventanaVertice.dato + " ya existe en el grafo";
                     label5.BackColor = Color.Red;
                 }
             }
             nuevoNodo    = null;
             nuevoVertice = true;
             var_control  = 0;
             mapa.Refresh();
         }
         if (e.Button == System.Windows.Forms.MouseButtons.Right) // Si se ha presionado el botón
         // derecho del mouse
         {
             if (var_control == 0)
             {
                 if ((NodoOrigen = grafo.DetectarPunto(e.Location)) != null)
                 {
                     // nuevoVerticeToolStripMenuItem.Text = "Nodo " + NodoOrigen.Valor;
                 }
                 else
                 {
                     mapa.ContextMenuStrip = this.contextMenuStrip1;
                 }
             }
         }
     }
     if (e.Button == System.Windows.Forms.MouseButtons.Right) // Si se ha presionado el botón
     // derecho del mouse
     {
         if (var_control == 0)
         {
             if ((NodoOrigen = grafo.DetectarPunto(e.Location)) != null)
             {
                 //nuevoVerticeToolStripMenuItem.Text = "Nodo " + NodoOrigen.Valor;
             }
             else
             {
                 mapa.ContextMenuStrip = this.contextMenuStrip1;
             }
         }
     }
 }
Exemple #16
0
 private void nUEVOVERTICEToolStripMenuItem_Click(object sender, EventArgs e)
 {
     nuevoNodo   = new vertice();
     var_control = 2; // recordemos que es usado para indicar el estado en la pizarra: 0 ->
                      // sin accion, 1 -> Dibujando arco, 2 -> Nuevo vértice
 }
Exemple #17
0
 //Agrega un nodo a la lista de nodos del grafo
 public void AgregarVertice(vertice nuevonodo)
 {
     nodos.Add(nuevonodo);
 }
Exemple #18
0
 //Metodo para actualizar el arco destino
 public arco(vertice destino) : this(destino, 1)
 {
     this.nDestino = destino;
 }
Exemple #19
0
 // Constructores
 public lista()
 {
     aElemento = null;
     aSubLista = null;
     aPeso     = 0;
 }
Exemple #20
0
 public lista(vertice pElemento, lista pSubLista, int pPeso)
 {
     aElemento = pElemento;
     aSubLista = pSubLista;
     aPeso     = pPeso;
 }
Exemple #21
0
 public void Colorear(vertice nodo)
 {
     nodo.Color     = Color.AliceBlue;
     nodo.FontColor = Color.Black;
 }