Esempio n. 1
0
        public EntContenedor AplicaAlgoritmo(EntContenedor oEntContenedor, TipoAlgoritmo eTipoAlgoritmo)
        {
            string camino    = string.Empty;
            string nodoHijo  = string.Empty;
            string nodoPadre = string.Empty;
            int    aux       = 0;

            try
            {
                for (int i = 0; i < oEntContenedor.lstEntNodo.Count; i++)
                {
                    EntNodo oEntNodo = oEntContenedor.lstEntNodo[i];
                    if (i == 0)
                    {
                        oEntNodo.esSeleccionado = true;
                        oEntNodo.nodoPrevio     = oEntNodo.nombreNodo;
                        nodoHijo  = oEntNodo.nombreNodo;
                        nodoPadre = oEntNodo.nombreNodo;
                        if (eTipoAlgoritmo == TipoAlgoritmo.Greedy)
                        {
                            oEntContenedor.lstEntNodo = this.ActualizaVertices(oEntContenedor.lstEntNodo, oEntNodo.idNodo);
                        }
                        oEntContenedor.lstResultados.Add(this.CreaResultado(aux, nodoPadre));
                    }
                    if (oEntNodo.nombreNodo == nodoHijo)
                    {
                        oEntNodo.esSeleccionado = true;
                        oEntNodo.nodoPrevio     = nodoPadre;
                        oEntNodo.peso           = aux;
                        oEntNodo.lstEntVertice  = this.OrdenaLista(oEntNodo.lstEntVertice);
                        for (int j = 0; j < oEntNodo.lstEntVertice.Count; j++)
                        {
                            EntVertice oEntVertice = oEntNodo.lstEntVertice[j];
                            if (j == 0)
                            {
                                i        = oEntVertice.idNodo - 2;
                                aux      = oEntNodo.peso + oEntVertice.peso;
                                nodoHijo = oEntVertice.nombreNodo;
                            }
                            oEntContenedor.lstEntNodo = this.ActualizaVertices(oEntContenedor.lstEntNodo, oEntVertice.idNodo);
                        }
                        nodoPadre = oEntNodo.nombreNodo;
                        if (eTipoAlgoritmo == TipoAlgoritmo.Greedy)
                        {
                            oEntContenedor.lstEntNodo = this.ActualizaVerticesHijos(oEntContenedor.lstEntNodo, oEntNodo);
                        }
                        oEntContenedor.lstResultados.Add(this.CreaResultado(aux, nodoPadre));
                    }
                }
            }
            catch (Exception ex)
            {
                oEntContenedor.mensajeError = ex.Message;
                oEntContenedor.eTipoError   = TipoError.Error;
            }
            return(oEntContenedor);
        }
Esempio n. 2
0
        public EntContenedor LecturaArchivo()
        {
            EntContenedor oEntContenedor = new EntContenedor();

            try
            {
                StreamReader  objReader = new StreamReader(this.rutaArchivo);
                string        sLine     = "";
                List <string> arrText   = new List <string>();
                while (sLine != null)
                {
                    sLine = objReader.ReadLine();
                    if (sLine != null)
                    {
                        arrText.Add(sLine);
                    }
                }
                objReader.Close();
                if (arrText.Count > 0)
                {
                    oEntContenedor.lstEntNodo = this.GenerarListaNodos(arrText);
                    oEntContenedor.lstEntNodo = this.GenerarVerticesB(arrText, oEntContenedor.lstEntNodo);
                    oEntContenedor.lstEntNodo = this.ValidaUltimoNodo(arrText, oEntContenedor.lstEntNodo);
                    oEntContenedor.lstEntNodo = this.ActualizaIdVertices(oEntContenedor.lstEntNodo);
                }
                else
                {
                    oEntContenedor.mensajeError = "No hay datos en el archivo";
                    oEntContenedor.eTipoError   = TipoError.Warning;
                }
            }
            catch (ApplicationException aEx)
            {
                oEntContenedor.mensajeError = aEx.Message;
                oEntContenedor.eTipoError   = TipoError.Warning;
            }
            catch (Exception ex)
            {
                oEntContenedor.mensajeError = ex.Message;
                oEntContenedor.eTipoError   = TipoError.Error;
            }
            return(oEntContenedor);
        }