public void criaNodos(Nodo origem, Nodo destino)
 {
     nodos = new List<Nodo>();
     nodos.Add(origem);
     gameObjectsNodos = GameObject.FindGameObjectsWithTag("Nodo");
     foreach (var nodo in gameObjectsNodos) {
         Nodo aux = nodo.GetComponent<Nodo>();
         nodos.Add(aux);
     }
     nodos.Add(destino);
     grafo = new Grafo(nodos.ToArray());
 }
        public void DeberiaBorrarEnlace()
        {
            Grafo g = new Grafo();
            Nodo n = new Nodo("colo");
            Nodo b = new Nodo("colo1");

            Enlace e = new Enlace(55, n, b);
            g.AgregarNodo(n);
            g.AgregarNodo(b);
             g.AgregarEnlace(e);
             bool borro = g.BorrarEnlace(e);
             Assert.IsTrue(borro);
        }
        public void DeberiaAgregarEnlace()
        {
            Grafo g = new Grafo();
            Nodo n = new Nodo("colo");
            Nodo b = new Nodo("pepe");

            Enlace e = new Enlace(55, n, b);
            g.AgregarNodo(n);
            g.AgregarNodo(b);

            bool cargo = g.AgregarEnlace(e);
            Assert.IsTrue(cargo);
        }
 public void DeberiaRetornarListaVaciaSiElGrafoEstaVacio()
 {
     var g = new Grafo();
     var l = Kruskal.Ejecutar(g);
     Assert.IsNotNull(l);
     Assert.AreEqual(0, l.Count);
 }
 public void DeberiaAgregarNodo()
 {
     Grafo g = new Grafo();
     Nodo n = new Nodo("colo");
     bool cargo = g.AgregarNodo(n);
     Assert.IsTrue(cargo);
 }
        public void DeberiaCrearUnGrafo()
        {
            Grafo g = new Grafo();

            Assert.IsNotNull(g);

        }
 public void NoDeberiaAgregarNodosConElMismoNombre()
 {
     Grafo g = new Grafo();
     Nodo n = new Nodo("colo");
     Nodo b = new Nodo("colo");
     bool cargo = g.AgregarNodo(n);
     cargo = g.AgregarNodo(b);
     Assert.IsFalse(cargo);
 }
        public void NoDeberiaAgregarEnlaceSiNoExisteElNodo()
        {
            Grafo g = new Grafo();
            Nodo n = new Nodo("colo");
            Nodo b = new Nodo("colo");

            Enlace e = new Enlace(55, n, b);

            bool cargo = g.AgregarEnlace(e);
            Assert.IsFalse(cargo);
        }
 public void DeberiaRetornarListaCon1NodoSiElGrafoTiene1Nodo()
 {
     var g = new Grafo();
     var n1 = new Nodo("N1");
     var n2 = new Nodo("N2");
     g.AgregarNodo(n1);
     g.AgregarNodo(n2);
     var e1 = new Enlace(2, n1, n2);
     g.AgregarEnlace(e1);
     
     var l = Kruskal.Ejecutar(g);
     Assert.IsNotNull(l);
     Assert.AreEqual(1, l.Count);
 }
        public void DeberiaDevolverLaListaDeEnlacesDe1NodoSiNoSeVisitoElOtroNodo()
        {
            Grafo g = new Grafo();

            var n1 = new Nodo("N1");
            var n2 = new Nodo("N2");
            var n3 = new Nodo("N3");
            var n4 = new Nodo("N4");
            var n5 = new Nodo("N5");
            var n6 = new Nodo("N6");

            g.AgregarNodo(n1);
            g.AgregarNodo(n2);
            g.AgregarNodo(n3);
            g.AgregarNodo(n4);
            g.AgregarNodo(n5);
            g.AgregarNodo(n6);

            var e1 = new Enlace(2, n1, n2);
            var e2 = new Enlace(7, n2, n3);
            var e3 = new Enlace(3, n1, n3);
            var e4 = new Enlace(20, n1, n6);
            var e5 = new Enlace(5, n3, n6);
            var e6 = new Enlace(9, n1, n5);
            var e7 = new Enlace(3, n5, n4);

            g.AgregarEnlace(e1);
            g.AgregarEnlace(e2);
            g.AgregarEnlace(e3);
            g.AgregarEnlace(e4);
            g.AgregarEnlace(e5);
            g.AgregarEnlace(e6);
            g.AgregarEnlace(e7);
            n1.visitado = true;
            n2.visitado = true;
            List<Enlace> enlaces = g.GetEnlaces(n1);
            Assert.IsFalse(enlaces.Contains(e1)); // Esta visitado
            Assert.IsTrue(enlaces.Contains(e3));
            Assert.IsTrue(enlaces.Contains(e4));
            Assert.IsTrue(enlaces.Contains(e6));
            Assert.IsFalse(enlaces.Contains(e7));
            Assert.IsFalse(enlaces.Contains(e2));
            Assert.IsFalse(enlaces.Contains(e5));
        }
        public void DeberiaRetornarELEnlaceDeMenorPeso()
        {
            var g = new Grafo();
            var n1 = new Nodo("N1");
            var n2 = new Nodo("N2");
            var n3 = new Nodo("N3");
            var n4 = new Nodo("N4");
            var n5 = new Nodo("N5");
            var n6 = new Nodo("N6");
            

            g.AgregarNodo(n1);
            g.AgregarNodo(n2);
            g.AgregarNodo(n3);
            g.AgregarNodo(n4);
            g.AgregarNodo(n5);
            g.AgregarNodo(n6);

            var e1 = new Enlace(2, n1, n2);
            var e2 = new Enlace(7, n2, n3);
            var e3 = new Enlace(3, n1, n3);
            var e4 = new Enlace(20, n1, n6);
            var e5 = new Enlace(5, n3, n6);
            var e6 = new Enlace(9, n1, n5);
            var e7 = new Enlace(3, n5, n4);

            g.AgregarEnlace(e1);
            g.AgregarEnlace(e2);
            g.AgregarEnlace(e3);
            g.AgregarEnlace(e4);
            g.AgregarEnlace(e5);
            g.AgregarEnlace(e6);
            g.AgregarEnlace(e7);
            
            n1.visitado = true;
            n2.visitado = true;
            var enlaces = g.GetEnlaces(n1);
            

            Enlace eMenor = Prim.EnlaceMenorPeso(enlaces);
            Assert.IsNotNull(eMenor);
            Assert.AreNotEqual(eMenor, e1);
            Assert.AreEqual(eMenor, e3);
        }
        public void DeberiaRetornarARMGrafo()
        {
            var g = new Grafo();
            var n1 = new Nodo("N1");
            var n2 = new Nodo("N2");
            var n3 = new Nodo("N3");
            var n4 = new Nodo("N4");
            var n5 = new Nodo("N5");
            var n6 = new Nodo("N6");

            g.AgregarNodo(n1);
            g.AgregarNodo(n2);
            g.AgregarNodo(n3);
            g.AgregarNodo(n4);
            g.AgregarNodo(n5);
            g.AgregarNodo(n6);

            var e1 = new Enlace(2, n1, n2);
            var e2 = new Enlace(7, n2, n3);
            var e3 = new Enlace(3, n1, n3);
            var e4 = new Enlace(20, n1, n6);
            var e5 = new Enlace(5, n3, n6);
            var e6 = new Enlace(9, n1, n5);
            var e7 = new Enlace(3, n5, n4);

            g.AgregarEnlace(e1);
            g.AgregarEnlace(e2);
            g.AgregarEnlace(e3);
            g.AgregarEnlace(e4);
            g.AgregarEnlace(e5);
            g.AgregarEnlace(e6);
            g.AgregarEnlace(e7);

            var l = Kruskal.Ejecutar(g);
            Assert.IsNotNull(l);
            Assert.AreEqual(5, l.Count);
            Assert.AreEqual(e1, l[0]);
            Assert.AreEqual(e3, l[1]);
            Assert.AreEqual(e7, l[2]);
            Assert.AreEqual(e5, l[3]);
            Assert.AreEqual(e6, l[4]);
        }
        public AgenteAprende(List<Calle> calles, int destino)
        {
            this.calle = calles;
            this.destino = destino;
			mapa = new Grafo(calle);
        }
Exemple #14
0
 public void Teste_Triangulo()
 {
     string pastaArquivo = @"C:\Trabalho\TestePromob\JSONs";
     string nomeArquivo  = "Grafo1.json";
     Grafo  grafo        = new Grafo(false, pastaArquivo + @"\" + nomeArquivo);
 }
Exemple #15
0
        static void Main(string[] args)
        {
            string   opcion;
            string   flag;
            cGrafo   Grafo = new cGrafo();
            cVertice ver   = new cVertice();
            cVertice ver1  = new cVertice();
            cVertice ver2  = new cVertice();

            do
            {
                Menu();
                opcion = Console.ReadLine();
                switch (opcion)
                {
                case "1":
                {
                    Console.WriteLine("¿Desea crear un nuevo grafo?: (S)/(N)");
                    flag = Console.ReadLine();
                    if (flag == "S")
                    {
                        Grafo = new cGrafo();
                        Console.WriteLine("Grafo Creado");
                    }
                    break;
                }

                case "2":
                {
                    Console.Write("Ingrese el nombre del vertice: ");
                    ver.nombre = Console.ReadLine();
                    Grafo.AgregarVertice(ver);
                    break;
                }

                case "3":
                {
                    Console.Write("Ingrese el vertice origen: ");
                    ver1.nombre = Console.ReadLine();
                    Console.WriteLine("Ingrese el vertice destino: ");
                    ver2.nombre = Console.ReadLine();
                    Console.WriteLine("Ingrese la distancia: ");
                    int dist = int.Parse(Console.ReadLine());
                    Grafo.AgregarArco(ver1, ver2, dist);
                    break;
                }

                case "4":
                {
                    Console.WriteLine("Los vertices del grafo son: ");
                    Grafo.MostrarVertices();
                    break;
                }

                case "5":
                {
                    Console.WriteLine("El grafo es el siguiente: ");
                    Grafo.MostrarGrafo();
                    break;
                }
                }
            }while (opcion != "0");
            Console.ReadKey();
        }
 public GrafoDirigidoBuilder GrafoComum()
 {
     this.grafo = LeituraArquivo.GrafoDirigido(@"..\..\txts\Dirigido\ComCiclo.txt");
     return(this);
 }
Exemple #17
0
    protected void getGraph(long id_visita, int area)
    {
        Grafo    g   = new Grafo();
        PanoInfo inf = new PanoInfo();

        using (MySqlConnection conn = Bdatos.open(Bdatos.ConnGlobal))
        {
            MySqlCommand command = new MySqlCommand();

            command.Connection = conn;
            String sSql = "Num2=1 and Text30 = " + id_visita;

            if (area != -1)
            {
                sSql += " AND Num15 = " + area;
            }
            sSql += " AND " + Permisos.queryEditAuth(ref parameters);

            command.CommandText = "Select count(Codigo) From elementos where " + sSql + " Order By numero_pano,Num13 Asc";
            Int64 nNodes = (Int64)command.ExecuteScalar();
            g.vertices = new String[nNodes];


            command.CommandText = "Select  e.codigo,if(e.Text63 is null,'',e.Text63),e.Num13 + 1 as Num13,numero_pano From elementos e where " + sSql + " Order By numero_pano,Num13 Asc";
            using (MySqlDataReader oDR = command.ExecuteReader())
            {
                int i = 0;
                while (oDR.Read())
                {
                    g.vertices[i++] = oDR.GetString("Codigo");
                    string label = Bdatos.readStringBD(oDR, "numero_pano");
                    if (label == "-1")
                    {
                        label = Bdatos.readStringBD(oDR, "Num13");
                    }
                    g.labels.Add(oDR.GetString(0), label);
                    inf.text.Add(oDR.GetString(0), oDR.GetString(1));
                }
            }

            if (g.vertices.Length == 0)
            {
                return;
            }
            command.CommandText = "Select count(*) From arista_visita where nodo1 in (" + String.Join(",", g.vertices) + ") and nodo2 in (" + String.Join(",", g.vertices) + ")";

            Int64 nEdges = (Int64)command.ExecuteScalar();
            if (nEdges == 0)
            {
                g.fit = true;
            }


            List <String[]> edgeList = new List <String[]>();
            g.edges = edgeList.ToArray();


            command.CommandText = "Select nodo1,nodo2,(Select count(*) From hotspots h where id_pano in (av.nodo1,av.nodo2) and h.general_data regexp concat('\"next_pano\":(',av.nodo1,'|',av.nodo2,')[,}]')) > 1 as edited From arista_visita av where nodo1 in (" + String.Join(",", g.vertices) + ") and nodo2 in (" + String.Join(",", g.vertices) + ")";
            using (MySqlDataReader oDR = command.ExecuteReader())
            {
                while (oDR.Read())
                {
                    String[] edge;
                    if (oDR.GetBoolean(2))
                    {
                        edge = new String[] { oDR.GetString(0), oDR.GetString(1), "ok" }
                    }
                    ;
                    else
                    {
                        edge = new String[] { oDR.GetString(0), oDR.GetString(1) }
                    };
                    if (!contains_edge(edgeList, edge))
                    {
                        edgeList.Add(edge);
                    }
                }
            }
            g.edges = edgeList.ToArray();

            command.CommandText = "Select e.codigo,if(e.Text63 is null,'',e.Text63),n.x,n.y,e.Num13,numero_pano From elementos e left join nodo_visita n on e.Codigo = n.id where " + sSql + " Order By numero_pano,Num13 Asc";

            using (MySqlDataReader oDR = command.ExecuteReader())
            {
                int auxX = 1, auxY = 0, step = 1;
                while (oDR.Read())
                {
                    if (nEdges > 0)
                    {
                        double x, y;

                        if (!oDR.IsDBNull(2))
                        {
                            x = oDR.GetDouble("x");
                        }
                        else
                        {
                            x = 30;
                        }
                        if (!oDR.IsDBNull(3))
                        {
                            y = oDR.GetDouble("y");
                        }
                        else
                        {
                            y = 30;
                        }

                        g.pos.Add(oDR.GetString(0), new Double[] { x, y });
                    }
                    else
                    {
                        g.pos.Add(oDR.GetString(0), new Double[] { auxX, auxY });

                        auxX += step;


                        if (auxX == 10 || auxX == 0)
                        {
                            auxY += 1;
                            step *= -1;
                            auxX += step;
                        }
                    }
                }
            }

            foreach (string node in g.vertices)
            {
                HotSpotsManager hsm = new HotSpotsManager();
                hsm.loadUntranslated = true;
                hsm.loadCustomData   = true;
                hsm.locale           = parameters.lenguaje;
                foreach (NavigationHS hs in hsm.getHotSpotsByPano(Convert.ToInt64(node), HotSpotType.navigation))
                {
                    if (!hs.generalData.external && Array.IndexOf(g.vertices, hs.generalData.next_pano.ToString()) != -1)
                    {
                        if (!inf.hsLabels.Keys.Contains(hs.generalData.id_pano + "," + hs.generalData.next_pano))
                        {
                            inf.hsLabels.Add(hs.generalData.id_pano + "," + hs.generalData.next_pano, hs.localizedData.title);
                        }
                    }
                }
            }



            JavaScriptSerializer serializer = new JavaScriptSerializer();
            grafJSON = serializer.Serialize(g);
            infoJSON = serializer.Serialize(inf);
        }
    }
        private static void RecorrerGrafoDijkstra(int inicio, ref int actual, int cantidadNodos, Grafo grafo, int[,] tabla)
        {
            // Peso de la arista
            int peso = 0;

            // Inicializar tabla, que guarda la informacion que necesita el algoritmo
            for (int n = 0; n < cantidadNodos; n++)
            {
                tabla[n, 0] = 0;
                tabla[n, 1] = int.MaxValue;
                tabla[n, 2] = 0;
            }
            tabla[inicio, 1] = 0;

            do
            {
                // Marcar nodo como visitado
                tabla[actual, 0] = 1;
                for (int columna = 0; columna < cantidadNodos; columna++)
                {
                    // buscar a quien se dirige
                    if (grafo.ObtenerAdyacencia(actual, columna) != 0)
                    {
                        // Calular el tiempo
                        peso = grafo.ObtenerAdyacencia(actual, columna) + tabla[actual, 1];

                        // Actualizamos el tiempo en la tabla de informacion del algoritmo
                        if (peso < tabla[columna, 1])
                        {
                            tabla[columna, 1] = peso;

                            // Se coloca la informacion del padre
                            tabla[columna, 2] = actual;
                        }
                    }
                }

                // El nuevo actual es el nodo con el menor tiempo que no se ha visitado

                int indiceMenor = -1;
                int tiempoMenor = int.MaxValue;

                for (int x = 0; x < cantidadNodos; x++)
                {
                    if (tabla[x, 1] < tiempoMenor && tabla[x, 0] == 0)
                    {
                        indiceMenor = x;
                        tiempoMenor = tabla[x, 1];
                    }
                }

                actual = indiceMenor;
            } while (actual != -1);
        }
Exemple #19
0
 // Start is called before the first frame update
 void Start()
 {
     _graph = CriaGrafoDoMapa();
     CriaTelaTextura();
 }
        public void DeberiaRetornarTruePorqueTodosLosNodosFueronVisitados()
        {
            Grafo g = new Grafo();
            Nodo n1 = new Nodo("n1");
            Nodo n2 = new Nodo("n2");

            Enlace e = new Enlace(55, n1, n2);
            g.AgregarNodo(n1);
            g.AgregarNodo(n2);
            n1.visitado = true;
            n2.visitado = true;
            bool visitados = g.TodosVisitados();
            Assert.IsTrue(visitados);
        }
        public void DeberiaDevolverLaListaDeEnlacesOrdenada()
        {
            Grafo g = new Grafo();

            var n1 = new Nodo("N1");
            var n2 = new Nodo("N2");
            var n3 = new Nodo("N3");
            var n4 = new Nodo("N4");
            var n5 = new Nodo("N5");
            var n6 = new Nodo("N6");

            g.AgregarNodo(n1);
            g.AgregarNodo(n2);
            g.AgregarNodo(n3);
            g.AgregarNodo(n4);
            g.AgregarNodo(n5);
            g.AgregarNodo(n6);

            var e1 = new Enlace(2, n1, n2);
            var e2 = new Enlace(7, n2, n3);
            var e3 = new Enlace(3, n1, n3);
            var e4 = new Enlace(20, n1, n6);
            var e5 = new Enlace(5, n3, n6);
            var e6 = new Enlace(9, n1, n5);
            var e7 = new Enlace(3, n5, n4);

            g.AgregarEnlace(e1);
            g.AgregarEnlace(e2);
            g.AgregarEnlace(e3);
            g.AgregarEnlace(e4);
            g.AgregarEnlace(e5);
            g.AgregarEnlace(e6);
            g.AgregarEnlace(e7);

            List<Enlace> enlaces = g.GetEnlacesDeMenorAMayor();

            Assert.AreEqual(2, enlaces[0].Peso);
            Assert.AreEqual(3, enlaces[1].Peso);
            Assert.AreEqual(3, enlaces[2].Peso);
            Assert.AreEqual(5, enlaces[3].Peso);
            Assert.AreEqual(7, enlaces[4].Peso);
            Assert.AreEqual(9, enlaces[5].Peso);
            Assert.AreEqual(20, enlaces[6].Peso);
        }
        public AgenteAprende(List<Calle> calles)
        {
            this.calle = calles;
			mapa = new Grafo(calle);
        }
        private static int SumarPesoAristas(List <int> rutaInicial, List <int> rutaFinal, Grafo grafo)
        {
            int[] pesoAristas = new int[rutaInicial.Count + rutaFinal.Count];
            int   index       = 0;
            int   sumaAristas = 0;

            foreach (int posicion in rutaInicial)
            {
                pesoAristas[index] = posicion;
                index++;
            }

            foreach (int posicion in rutaFinal)
            {
                pesoAristas[index] = posicion;
                index++;
            }

            for (int i = 0; i < pesoAristas.Length - 1; i++)
            {
                sumaAristas += grafo.ObtenerAdyacencia(pesoAristas[i], pesoAristas[i + 1]);
            }

            return(sumaAristas);
        }
Exemple #24
0
        static void Main(string[] args)
        {
            Grafo<string> grafo = new Grafo<string>();

            Vertice<string> v1 = new Vertice<string>("Index.htm");
            Vertice<string> v2 = new Vertice<string>("Home.htm");
            Vertice<string> v3 = new Vertice<string>("Contact.htm");
            Vertice<string> v4 = new Vertice<string>("About.htm");
            //InserirVertice()
            grafo.InserirVertice(v1);
            grafo.InserirVertice(v2);
            grafo.InserirVertice(v3);
            grafo.InserirVertice(v4);

            var lista = grafo.Vertices().ToList();
            foreach (Node<string> vertice in lista)
            {
                Console.WriteLine(vertice.Value.ToString());
            }
            Console.WriteLine();

            //InserirVerticeDirecionado()
            Aresta<string> aresta1 = grafo.InserirAresta(v1, v2, 1);
            Aresta<string> aresta2 = grafo.InserirAresta(v2, v3, 2);
            Aresta<string> aresta3 = grafo.InserirAresta(v1, v3, 3);
            Aresta<string> aresta4 = grafo.InserirAresta(v1, v4, 4);
            //Vertice<string> verticeSubst = new Vertice<string>("Gallery.htm");
            //grafo.substituirVertice(v1, verticeSubst);
            //bool verticeRemovido = grafo.RemoverVertice(v2);
            Console.WriteLine("Lista de arestas: ");
            List<Aresta<string>> listaArestas = grafo.Arestas();
            foreach (Aresta<string> arestaItem in listaArestas)
            {
                Console.WriteLine(grafo.GetAresta(arestaItem));
                if(!grafo.eDirecionado(arestaItem))
                    Console.WriteLine(arestaItem.to.Value.ToString()+" - "+ arestaItem.from.Value.ToString());
            }

            //eAdjacente()
            if (grafo.eAdjacente(v1, v2)) Console.WriteLine(v1.Value.ToString() + " é adjacente de " + v2.Value.ToString());
            else Console.WriteLine(v1.Value.ToString() + " não é adjacente de " + v2.Value.ToString());

            /*
            //removerVertice
            //
            //oposto
            Console.WriteLine(grafo.oposto(v1, aresta1).Value.ToString());
            //finalVertice
            Vertice<string>[] verticesFinais = grafo.finalVertices(aresta1);
            Console.WriteLine(verticesFinais[0].Value.ToString()+ " - " +verticesFinais[1].Value.ToString());
            //Subistuir Vertice
            Console.WriteLine("\nNova Lista de Vertices: ");
            Vertice<string> verticeSubst =new Vertice<string>("Galery.htm");
            grafo.substituirVertice(v1, verticeSubst);
            var listaSubstituidos = grafo.Vertices().ToList();
            foreach (Vertice<string> vertice in lista)
            {
                Console.WriteLine(vertice.Value.ToString());
            }
            Aresta<string> arestaSubst = new Aresta<string>(v3, v4);
            grafo.substituirAresta(aresta1, arestaSubst);
            Console.WriteLine("\nNova Lista de Arestas");
            List<Aresta<string>> listaSubst = grafo.Arestas();
            foreach (Aresta<string> arestaItem in listaSubst)
            {
                Console.WriteLine(Aresta<string>.GetAresta(arestaItem));
                if (!grafo.eDirecionado(arestaItem))
                    Console.WriteLine(arestaItem.to.Value.ToString() + " - " + arestaItem.from.Value.ToString());
            }*/
            //Aresta<string> arestaSubst = new Aresta<string>(v3, v4);
            //grafo.substituirAresta(aresta1, arestaSubst);

            Console.WriteLine("\nMatriz de Custo");
            grafo.MostrarMatrizdeCusto();
            Console.WriteLine("\nMatriz de Adjacencia");
            grafo.MostrarMatrizdeAdjacencia();
            grafo.eEuleriano();
            //grafo.Dijkstra(v1, v2);
            Console.Read();
        }
		public override void funcionAgente(Vehiculo miVehiculo, List<Elemento> calles, List<Elemento> señaleticas, Hashtable sectores)
        {
            estadoActual = this.percepcionVehiculo(miVehiculo, calles, señaleticas, sectores);
            if (Modificar.cambio)
            {//Vuelve a crear el grafo cuando cambian las calles
                Modificar.cambio = false;
				mapa = new Grafo (calle);
            }
            if (ruta == null)
            {
                crearObjetivo();
            }
            trabajandoObjetivo();
            this.tabla_de_reglas(miVehiculo, estadoActual);
        }