Exemplo n.º 1
0
        public ActionResult DeleteConfirmed(int id)
        {
            vertice vertice = db.vertice.Find(id);

            db.vertice.Remove(vertice);
            db.SaveChanges();
            return(RedirectToAction("Index"));
        }
Exemplo n.º 2
0
 public ActionResult Edit([Bind(Include = "id,latitud,longitud,poligono_id")] vertice vertice)
 {
     if (ModelState.IsValid)
     {
         db.Entry(vertice).State = EntityState.Modified;
         db.SaveChanges();
         return(RedirectToAction("Index"));
     }
     ViewBag.poligono_id = new SelectList(db.poligono, "id", "id", vertice.poligono_id);
     return(View(vertice));
 }
Exemplo n.º 3
0
        public ActionResult Create([Bind(Include = "id,latitud,longitud,poligono_id")] vertice vertice)
        {
            if (ModelState.IsValid)
            {
                db.vertice.Add(vertice);
                db.SaveChanges();
                return(RedirectToAction("Index"));
            }

            ViewBag.poligono_id = new SelectList(db.poligono, "id", "id", vertice.poligono_id);
            return(View(vertice));
        }
Exemplo n.º 4
0
        // GET: Vertice/Details/5
        public ActionResult Details(int?id)
        {
            if (id == null)
            {
                return(new HttpStatusCodeResult(HttpStatusCode.BadRequest));
            }
            vertice vertice = db.vertice.Find(id);

            if (vertice == null)
            {
                return(HttpNotFound());
            }
            return(View(vertice));
        }
Exemplo n.º 5
0
        // GET: Vertice/Edit/5
        public ActionResult Edit(int?id)
        {
            if (id == null)
            {
                return(new HttpStatusCodeResult(HttpStatusCode.BadRequest));
            }
            vertice vertice = db.vertice.Find(id);

            if (vertice == null)
            {
                return(HttpNotFound());
            }
            ViewBag.poligono_id = new SelectList(db.poligono, "id", "id", vertice.poligono_id);
            return(View(vertice));
        }
        public vertice AssignFirst(Graph graph, int position)
        {
            vertice first = new vertice();
            vertice vert  = graph.vertices.FirstOrDefault(x => x.Key == position).Value;

            if (vert.First == null)
            {
                if (vert.value == "|" || vert.value == ".")
                {
                    List <int> hijos     = new List <int>();
                    vertice    v1        = new vertice();
                    vertice    v2        = new vertice();
                    List <int> tempvert2 = new List <int>();
                    hijos.Add(graph.edges.FirstOrDefault(x => x.Value.Start == position).Value.End);
                    v1 = (AssignFirst(graph, hijos[0]));
                    hijos.Add(graph.edges.LastOrDefault(x => x.Value.Start == position).Value.End);
                    v2 = AssignFirst(graph, hijos[1]);
                    if (vert.value == "|")
                    {
                        vert.First = v1.First.Union(v2.First).ToList();
                    }
                    else if (vert.value == ".")
                    {
                        if (v1.nullable == true)
                        {
                            vert.First = v1.First.Union(v2.First).ToList();
                        }
                        else
                        {
                            vert.First = v1.First;
                        }
                    }
                    return(vert);
                }
                else
                {
                    int pos = graph.edges.FirstOrDefault(x => x.Value.Start == position).Value.End;
                    vert.First = AssignFirst(graph, pos).First;
                }
            }
            else if (vert.value != "*" || vert.value != "+" || vert.value != "?" || vert.value != "|")
            {
                return(vert);
            }
            return(vert);
        }
        public Dictionary <int, List <int> > AssignFollow(Graph graph)
        {
            List <int> templist = new List <int>();

            foreach (var item in graph.vertices)
            {
                if (item.Value.value == "*" || item.Value.value == "+" || item.Value.value == "?")
                {
                    Edge    edge    = graph.edges.Values.FirstOrDefault(x => x.Start == item.Key);
                    vertice vertice = graph.vertices.FirstOrDefault(x => x.Key == edge.End).Value;
                    foreach (var follow in vertice.Last)
                    {
                        if (Follows.ContainsKey(follow))
                        {
                            Follows[follow].AddRange(vertice.First.FindAll(x => Follows[follow].Contains(x) == false));
                        }
                        else
                        {
                            Follows.Add(follow, vertice.First);
                        }
                    }
                }
                else if (item.Value.value == ".")
                {
                    Edge edge  = graph.edges.Values.FirstOrDefault(x => x.Start == item.Key);
                    Edge edge2 = graph.edges.Values.LastOrDefault(x => x.Start == item.Key);

                    vertice vertice  = graph.vertices.FirstOrDefault(x => x.Key == edge.End).Value;
                    vertice vertice2 = graph.vertices.FirstOrDefault(x => x.Key == edge2.End).Value;

                    foreach (var follow in vertice.Last)
                    {
                        if (Follows.ContainsKey(follow))
                        {
                            Follows[follow].AddRange(vertice2.First.FindAll(x => Follows[follow].Contains(x) == false));
                        }
                        else
                        {
                            Follows.Add(follow, vertice2.First);
                        }
                    }
                }
            }
            return(Follows);
        }
Exemplo n.º 8
0
        public ActionResult CrearTerrenoJson()
        {
            var          poligono       = db.poligono.Where(p => p.id == 1).FirstOrDefault();
            var          resolveRequest = HttpContext.Request;
            List <Punto> puntos         = new List <Punto>();

            resolveRequest.InputStream.Seek(0, System.IO.SeekOrigin.Begin);
            string jsonString = new StreamReader(resolveRequest.InputStream).ReadToEnd();

            if (jsonString != null)
            {
                JavaScriptSerializer serializer = new JavaScriptSerializer();
                puntos = (List <Punto>)serializer.Deserialize(jsonString, typeof(List <Punto>));
                for (var i = 0; i < puntos.Count(); i++)
                {
                    try
                    {
                        var vert = new vertice();
                        vert.latitud  = puntos[i].latitud;
                        vert.longitud = puntos[i].longitud;
                        vert.poligono = poligono;
                        db.vertice.Add(vert);
                        db.SaveChanges();
                    }
                    catch (Exception e)
                    {
                    }
                }
            }



            //var usuarioId = Convert.ToInt32(Session["userId"]);
            //var poligono = db.poligono.Where(pol => pol.usuario_id == usuarioId).FirstOrDefault();


            return(Redirect("/Gps/UbicacionGanado"));
        }
        public Graph CreateTree(List <string> expresion, int nVertices, int nEdges)
        {
            Dictionary <int, vertice> vertices = new Dictionary <int, vertice>();
            Dictionary <int, Edge>    edges    = new Dictionary <int, Edge>();

            //Graph graph = new Graph();

            if (expresion.Count == 0)
            {
                Graph graph = new Graph(vertices, edges, 0);
                return(graph);
            }
            List <string> temp = new List <string>();
            string        valor = string.Empty; bool bandera = false;

            //if (expresion[expresion.Count-1] != "(")
            //{
            //    expresion.RemoveAt(expresion.Count - 1);
            //    temp = expresion;
            //    bandera =  temp.TrueForAll(x => x == "(");
            //}
            if (expresion.Count == 1 || bandera == true)
            {
                nVertices++;
                vertice vert = new vertice();
                vert.value = (bandera == true)? valor : expresion[0];
                if (expresion[0] != "?" && expresion[0] != "+" && expresion[0] != "*" && expresion[0] != "|" && expresion[0] != ".")
                {
                    vert.First = new List <int>();
                    vert.First.Add(NoTerminales);
                    vert.Last = new List <int>();
                    vert.Last.Add(NoTerminales);
                    NoTerminales++;
                    vert.nullable = false;
                }
                else if (expresion[0] == "?" || expresion[0] == "*")
                {
                    vert.nullable = true;
                }
                else
                {
                    vert.nullable = false;
                }
                vertices.Add(nVertices, vert);
                Graph graph = new Graph(vertices, edges, nVertices);
                return(graph);
            }
            List <string> A = expresion;
            List <string> B = expresion;
            int           parentesiscount = 0; bool expIsConcat = false;

            for (int i = 0; i < expresion.Count - 1 && !expIsConcat; i++)
            {
                if (expresion[i] == "(")
                {
                    parentesiscount++;
                }
                if (expresion[i] == ")")
                {
                    parentesiscount--;
                }
                if (expresion[i + 1] == "." && parentesiscount == 0)
                {
                    expIsConcat = true;
                    if (expresion[i] == "(")
                    {
                        A = expresion.GetRange(i, i + 1);
                    }
                    else
                    {
                        A = expresion.GetRange(0, i + 1);
                    }
                    B = expresion.GetRange(i + 2, expresion.Count - i - 2);
                }
            }
            // Si la expresion es de la forma a|b
            if (expIsConcat)
            {
                // Crear nodo de |
                nVertices++;
                vertice vert = new vertice();
                vert.value    = ".";
                vert.nullable = false;
                vertices.Add(nVertices, vert);
                // Crear el subtree de las expresiones
                Graph subTreeA = CreateTree(A, nVertices, nEdges);
                Graph subTreeB = CreateTree(B, nVertices + subTreeA.vertices.Count, nEdges + subTreeA.edges.Count);
                // Agregar los vertices del subtree
                subTreeA.vertices.ToList().ForEach(x => vertices.Add(x.Key, x.Value));
                subTreeB.vertices.ToList().ForEach(x => vertices.Add(x.Key, x.Value));
                // Agregar los edges del subtree
                subTreeA.edges.ToList().ForEach(x => edges.Add(edges.Count + 1, x.Value));
                subTreeB.edges.ToList().ForEach(x => edges.Add(edges.Count + 1, x.Value));
                // Agregar el edge que une al nodo y al subtree
                nEdges = edges.Count + 1;
                Edge newEdgeA = new Edge(nVertices, subTreeA.head);
                edges.Add(nEdges, newEdgeA);
                nEdges = edges.Count + 1;
                Edge newEdgeB = new Edge(nVertices, subTreeB.head);
                edges.Add(nEdges, newEdgeB);
                // Retornar el grafo
                Graph graph = new Graph(vertices, edges, nVertices);
                return(graph);
            }
            // Revisar que la expresion sea de la forma a|b
            List <string> a               = expresion;
            List <string> b               = expresion;
            int           parentesisCount = 0;
            bool          expIsOr         = false;

            for (int i = 0; i < expresion.Count - 1 && !expIsOr; i++)
            {
                if (expresion[i] == "(")
                {
                    parentesisCount++;
                }
                if (expresion[i] == ")")
                {
                    parentesisCount--;
                }
                if (parentesisCount == 0 && expresion[i + 1] == "|")
                {
                    expIsOr = true;
                    a       = expresion.GetRange(0, i + 1);
                    b       = expresion.GetRange(i + 2, expresion.Count - i - 2);
                }
            }
            // Si la expresion es de la forma a|b
            if (expIsOr)
            {
                // Crear nodo de |
                nVertices++;
                vertice vert = new vertice();
                vert.value    = "|";
                vert.nullable = false;
                vertices.Add(nVertices, vert);
                // Crear el subtree de las expresiones
                Graph subTreeA = CreateTree(a, nVertices, nEdges);
                Graph subTreeB = CreateTree(b, nVertices + subTreeA.vertices.Count, nEdges + subTreeA.edges.Count);
                // Agregar los vertices del subtree
                subTreeA.vertices.ToList().ForEach(x => vertices.Add(x.Key, x.Value));
                subTreeB.vertices.ToList().ForEach(x => vertices.Add(x.Key, x.Value));
                // Agregar los edges del subtree
                subTreeA.edges.ToList().ForEach(x => edges.Add(edges.Count + 1, x.Value));
                subTreeB.edges.ToList().ForEach(x => edges.Add(edges.Count + 1, x.Value));
                // Agregar el edge que une al nodo y al subtree
                nEdges = edges.Count + 1;
                Edge newEdgeA = new Edge(nVertices, subTreeA.head);
                edges.Add(nEdges, newEdgeA);
                nEdges = edges.Count + 1;
                Edge newEdgeB = new Edge(nVertices, subTreeB.head);
                edges.Add(nEdges, newEdgeB);
                // Retornar el grafo
                Graph graph = new Graph(vertices, edges, nVertices);
                return(graph);
            }
            // Si la expresion es del tipo (s)
            else if (expresion.Count >= 2 && expresion[0] == "(" && expresion[expresion.Count - 1] == ")")
            {
                // Devuelve el arbol de s
                return(CreateTree(expresion.GetRange(1, expresion.Count - 2), nVertices, nEdges));
            }
            // Si la expresion es de la forma s*
            else if ((expresion.Count == 2 && expresion[1] == "*") || (expresion.Count > 2 && expresion[0] == "(" && expresion[expresion.Count - 2] == ")" && expresion[expresion.Count - 1] == "*"))
            {
                // Crear el nodo del *
                nVertices++;
                vertice vert = new vertice();
                vert.value    = "*";
                vert.nullable = true;
                vertices.Add(nVertices, vert);
                // Crear el subtree de la expresion
                Graph subTree = CreateTree(expresion.GetRange(0, expresion.Count - 1), nVertices, nEdges);
                // Agregar los vertices del subtree
                subTree.vertices.ToList().ForEach(x => vertices.Add(x.Key, x.Value));
                // Agregar los edges del subtree
                subTree.edges.ToList().ForEach(x => edges.Add(x.Key, x.Value));
                // Agregar el edge que une al nodo y al subtree
                nEdges = edges.Count + 1;
                Edge newEdge = new Edge(nVertices, subTree.head);
                edges.Add(nEdges, newEdge);
                // Retornar el grafo
                Graph graph = new Graph(vertices, edges, nVertices);
                return(graph);
            }
            else if ((expresion.Count == 2 && expresion[1] == "?") || (expresion.Count > 2 && expresion[0] == "(" && expresion[expresion.Count - 2] == ")" && expresion[expresion.Count - 1] == "?"))
            {
                // Crear el nodo del *
                nVertices++;
                vertice vert = new vertice();
                vert.value    = "?";
                vert.nullable = true;
                vertices.Add(nVertices, vert);
                // Crear el subtree de la expresion
                Graph subTree = CreateTree(expresion.GetRange(0, expresion.Count - 1), nVertices, nEdges);
                // Agregar los vertices del subtree
                subTree.vertices.ToList().ForEach(x => vertices.Add(x.Key, x.Value));
                // Agregar los edges del subtree
                subTree.edges.ToList().ForEach(x => edges.Add(x.Key, x.Value));
                // Agregar el edge que une al nodo y al subtree
                nEdges = edges.Count + 1;
                Edge newEdge = new Edge(nVertices, subTree.head);
                edges.Add(nEdges, newEdge);
                // Retornar el grafo
                Graph graph = new Graph(vertices, edges, nVertices);
                return(graph);
            }
            else if ((expresion.Count == 2 && expresion[1] == "+") || (expresion.Count > 2 && expresion[0] == "(" && expresion[expresion.Count - 2] == ")" && expresion[expresion.Count - 1] == "+"))
            {
                // Crear el nodo del *
                nVertices++;
                vertice vert = new vertice();
                vert.value    = "+";
                vert.nullable = false;
                vertices.Add(nVertices, vert);
                // Crear el subtree de la expresion
                Graph subTree = CreateTree(expresion.GetRange(0, expresion.Count - 1), nVertices, nEdges);
                // Agregar los vertices del subtree
                subTree.vertices.ToList().ForEach(x => vertices.Add(x.Key, x.Value));
                // Agregar los edges del subtree
                subTree.edges.ToList().ForEach(x => edges.Add(x.Key, x.Value));
                // Agregar el edge que une al nodo y al subtree
                nEdges = edges.Count + 1;
                Edge newEdge = new Edge(nVertices, subTree.head);
                edges.Add(nEdges, newEdge);
                // Retornar el grafo
                Graph graph = new Graph(vertices, edges, nVertices);
                return(graph);
            }


            Graph graphtemp = new Graph(vertices, edges, 0);

            return(graphtemp);
        }
        public List <string> ValidarActions()
        {
            bool                  concatenacion = true; int count = 0;
            List <string>         listadeNodostemp     = new List <string>();
            List <List <string> > listaexpresionestemp = new List <List <string> >();
            List <string>         listadeNodos         = new List <string>();

            // List<string> listadeNodos = new List<string>{ "(", "(", "a", "|", "b", ")", "+", "|", "c", "*", ")", "+" };
            foreach (var item in TokenDic.Values)
            {
                listadeNodos.Clear();
                listadeNodostemp.Clear();
                foreach (var dato in item)
                {
                    if (dato != "(" && dato != "*" && dato != "?" && dato != "+" && dato != ")" && dato != "|")
                    {
                        if (concatenacion == true)
                        {
                            listadeNodostemp.Clear();
                            listadeNodostemp.AddRange(listadeNodos);
                            listadeNodos.Clear();
                            if (listadeNodostemp.Count > 0)
                            {
                                listadeNodos.Add("(");
                                listadeNodos = listadeNodos.Concat(listadeNodostemp).ToList();
                                listadeNodos.Add(".");
                                listadeNodos.Add(dato);
                                listadeNodos.Add(")");
                            }
                            else
                            {
                                listadeNodos.Add(dato);
                            }
                            concatenacion = true;
                        }
                        else
                        {
                            listadeNodostemp.Clear();
                            listadeNodostemp.AddRange(listadeNodos);
                            listadeNodos.Clear();
                            listadeNodos.Add("(");
                            listadeNodos = listadeNodos.Concat(listadeNodostemp).ToList();
                            listadeNodos.Add(dato);
                            listadeNodos.Add(")");
                            concatenacion = true;
                        }
                    }
                    else if (dato == "|")
                    {
                        listadeNodos.Add(dato);
                        concatenacion = false;
                    }
                    else
                    {
                        listadeNodos.Add(dato);
                    }
                }
                count++;
                if (count <= TokenDic.Values.Count)
                {
                    listadeNodostemp.Clear();
                    listadeNodostemp.AddRange(listadeNodos);
                    listadeNodos.Clear();
                    if (listadeNodostemp.ElementAt(listadeNodostemp.Count - 1) != ")")
                    {
                        listadeNodos.Add("(");
                        listadeNodos.AddRange(listadeNodostemp);
                        listadeNodos.Add(")");
                    }
                    else
                    {
                        listadeNodos.AddRange(listadeNodostemp);
                    }
                    List <string> temp = new List <string>();
                    temp.AddRange(listadeNodos);
                    listaexpresionestemp.Add(temp);
                    concatenacion = true;
                }
            }
            listadeNodos.Clear();
            foreach (var expresion in listaexpresionestemp)
            {
                listadeNodostemp.Clear();
                listadeNodostemp.AddRange(listadeNodos);
                listadeNodos.Clear();
                if (listadeNodostemp.Count > 0)
                {
                    listadeNodos.Add("(");
                    listadeNodos = listadeNodos.Concat(listadeNodostemp).ToList();
                    listadeNodos.Add("|");
                    listadeNodos.AddRange(expresion);
                    listadeNodos.Add(")");
                }
                else
                {
                    listadeNodos.AddRange(expresion);
                }
            }
            //List<string> listadeNodos = new List<string> {  "a" };
            // arbol.prueba();
            graph = arbol.CreateTree(listadeNodos, 0, 0);
            //Asigno first
            vertice graph1 = arbol.AssignFirst(graph, graph.head);
            //Asigno Last
            vertice graph2 = arbol.AssignLast(graph, graph.head);
            int     nt     = arbol.NoTerminales;

            Follows = arbol.AssignFollow(graph);

            foreach (var vertu in graph.vertices)
            {
                List <List <string> > TempData = new List <List <string> >();
                if (vertu.Value.value != "*" && vertu.Value.value != "+" && vertu.Value.value != "?" && vertu.Value.value != "|" && vertu.Value.value != "." && transitions.Keys.Contains(vertu.Value.value) == false)
                {
                    transitions.Add(vertu.Value.value, TempData);
                }
            }


            P.Add(1, graph.vertices.ToList().FirstOrDefault(x => x.Key == 1).Value.First);
            try
            {
                P = arbol.CreateTransitions(graph, transitions, P, 1);
            }
            catch
            {
                string p = string.Empty;
            }
            error.Add("fin");
            return(actions);
        }