示例#1
0
        public Cvertice AgregarVertice(string valor)
        {
            Cvertice nodo = new Cvertice(valor);

            nodos.Add(nodo);
            return(nodo);
        }
示例#2
0
 public CLista(CLista pLista)
 {
     if (pLista != null)
     {
         aElemento = pLista.aElemento;
         aSubLista = pLista.aSubLista;
         aPeso     = pLista.aPeso;
     }
 }
示例#3
0
 public bool AgregarArco(Cvertice origen, Cvertice nDestino, int peso = 1)
 {
     if (origen.ListaAdyacencia.Find(v => v.nDestino == nDestino) == null)
     {
         origen.ListaAdyacencia.Add(new CArco(nDestino, peso));
         return(true);
     }
     return(false);
 }
示例#4
0
 public bool ExisteElemento(Cvertice pElemento)
 {
     if ((aElemento != null) && (pElemento != null))
     {
         return(aElemento.Equals(pElemento) || (aSubLista.ExisteElemento(pElemento)));
     }
     else
     {
         return(false);
     }
 }
示例#5
0
 public void Eliminar(Cvertice pElemento)
 {
     if (aElemento != null)
     {
         if (aElemento.Equals(pElemento))
         {
             aElemento = aSubLista.aElemento;
             aSubLista = aSubLista.aSubLista;
         }
         else
         {
             aSubLista.Eliminar(pElemento);
         }
     }
 }
示例#6
0
        public Simulador(String path, String stringInicio, String stringFinal)
        {
            InitializeComponent();
            grafo       = new CGrafo();
            nuevoNodo   = null;
            var_control = 0;
            ListaNodos.inicio();
            ListaNodos.ReadFile(path);
            String inicio = stringInicio;
            String final  = stringFinal;

            Vertice        = new Vertice();
            listaRecorrido = ListaNodos.AEstrella(ListaNodos.BuscaNodo(stringInicio), ListaNodos.BuscaNodo(stringFinal));
            this.SetStyle(ControlStyles.AllPaintingInWmPaint | ControlStyles.UserPaint |
                          ControlStyles.OptimizedDoubleBuffer, true);
        }
示例#7
0
        private void nuevoVerticeToolStripMenuItem_Click(object sender, EventArgs e)
        {
            int posX = 200;

            int offsetY = Pizarra.Height / 5;
            int posY    = 0;

            for (int i = 0; i < ListaNodos.Grafo.Count; i++)
            {
                nuevoNodo       = new Cvertice();
                nuevoNodo.Valor = ListaNodos.Grafo[i].Nombre;
                grafo.AgregarVertice(nuevoNodo);
                if (i == 0)
                {
                    nuevoNodo.Posicion = new Point(30, Pizarra.Height / 2);
                }
                else
                {
                    posY += offsetY;
                    if (posY >= Pizarra.Height - offsetY)
                    {
                        posX += 120;
                        posY  = offsetY;
                    }
                    nuevoNodo.Posicion = new Point(posX, posY);
                }
                Pizarra.Refresh();
                nuevoNodo.DibujarVertice(Pizarra.CreateGraphics());
            }

            foreach (Nodo nodo in ListaNodos.Grafo)
            {
                foreach (Arista arista in nodo.Aristas)
                {
                    NodoOrigen  = BuscaNodo(arista.partida.Nombre);
                    NodoDestino = BuscaNodo(arista.destino.Nombre);
                    if (grafo.AgregarArco(NodoOrigen, NodoDestino))
                    {
                        int distancia = arista.peso;
                        NodoOrigen.ListaAdyacencia.Find(v => v.nDestino == NodoDestino).peso = distancia;
                    }
                }
            }
            flag = true;
            Pizarra.Refresh();
        }
示例#8
0
 public int PosicionElemento(Cvertice pElemento)
 {
     if ((aElemento != null) || (ExisteElemento(pElemento)))
     {
         if (aElemento.Equals(pElemento))
         {
             return(1);
         }
         else
         {
             return(1 + aSubLista.PosicionElemento(pElemento));
         }
     }
     else
     {
         return(0);
     }
 }
示例#9
0
 public void Agregar(Cvertice pElemento, int pPeso)
 {
     if (pElemento != null)
     {
         if (aElemento == null)
         {
             aElemento = new Cvertice(pElemento.Valor);
             aPeso     = pPeso;
             aSubLista = new CLista();
         }
         else
         {
             if (!ExisteElemento(pElemento))
             {
                 aSubLista.Agregar(pElemento, pPeso);
             }
         }
     }
 }
示例#10
0
 public CLista(Cvertice pElemento, CLista pSubLista, int pPeso)
 {
     aElemento = pElemento;
     aSubLista = pSubLista;
     aPeso     = pPeso;
 }
示例#11
0
 public CLista()
 {
     aElemento = null;
     aSubLista = null;
     aPeso     = 0;
 }
示例#12
0
 public void AgregarVertice(Cvertice nuevonodo)
 {
     nodos.Add(nuevonodo);
 }