Exemplo n.º 1
0
        /// <summary>
        /// Get the routes between 2 points
        /// </summary>
        /// <param name="lstvertex"></param>
        /// <param name="origin"></param>
        /// <param name="destiny"></param>
        /// <param name="caminos"></param>
        /// <param name="path"></param>

        public void getRoutes(List<clsVertex> lstvertex, string origin, string destiny, List<clsCamino> caminos, string path)
        {
            lstVertex.Where(x => x.Name.Equals(origin)).FirstOrDefault().Estado = true;

            path = string.Concat(path, origin);

            foreach (var item in lstVertex.Where(x => x.Name.Equals(origin)).FirstOrDefault().lstEdge)
            {
                clsVertex v = lstVertex.Where(x => x.Name.Equals(item.Vertex2.ToString())).FirstOrDefault();

                if (v.Name.Equals(destiny) &&path.Length > 1)
                {
                    path = string.Concat(path, v.Name);
                    caminos.Add(new clsCamino() { path = path, costo= int.Parse(this.getDistance(path)) });
                    v.Estado = false;
                    return;
                }

                if (!v.Estado)
                {
                    getRoutes(lstVertex, v.Name, destiny, caminos, path);
                    v.Estado = false;
                }
            }
        }
Exemplo n.º 2
0
        /// <summary>
        /// Get the routes with cost-distance conditions
        /// </summary>
        /// <param name="lstvertex"></param>
        /// <param name="origin"></param>
        /// <param name="destiny"></param>
        /// <param name="stopsNumber"></param>
        /// <param name="condition"></param>
        /// <param name="caminos"></param>
        /// <param name="path"></param>
        /// <param name="stops"></param>

        public void getRouteByCost(List<clsVertex> lstvertex, string origin, string destiny, int stopsNumber, string condition, List<clsCamino> caminos, string path, int? stops = 0)
        {
            lstVertex.Where(x => x.Name.Equals(origin)).FirstOrDefault().Estado = true;

            path = string.Concat(path, origin);

            foreach (var item in lstVertex.Where(x => x.Name.Equals(origin)).FirstOrDefault().lstEdge)
            {
                clsVertex v = lstVertex.Where(x => x.Name.Equals(item.Vertex2.ToString())).FirstOrDefault();

                if (path.Length > 1 && int.Parse(this.getDistance(path)) <= stopsNumber)
                {
                    path = string.Concat(path, v.Name);
                    caminos.Add(new clsCamino() { path = path, stops = (int)stops });
                    lstVertex.Where(x => x.Name.Equals(item.Vertex2.ToString())).FirstOrDefault().Estado = false;

                    return;
                }

                if (!v.Estado)
                {
                    stops += 1;
                    getRouteByCost(lstVertex, v.Name, destiny, stopsNumber, condition, caminos, path, stops);
                    lstVertex.Where(x => x.Name.Equals(item.Vertex2.ToString())).FirstOrDefault().Estado = false;

                }
            }
        }
Exemplo n.º 3
0
        /// <summary>
        /// Get the routes with stops conditions
        /// </summary>
        /// <param name="lstvertex"></param>
        /// <param name="origin"></param>
        /// <param name="destiny"></param>
        /// <param name="stopsNumber"></param>
        /// <param name="condition"></param>
        /// <param name="caminos"></param>
        /// <param name="path"></param>
        /// <param name="stops"></param>
        public void getRouteByStops(List<clsVertex> lstvertex, string origin, string destiny, int stopsNumber, string condition, List<clsCamino> caminos, string path, int? stops = 0)
        {
            lstVertex.Where(x => x.Name.Equals(origin)).FirstOrDefault().Estado = true;

            path = string.Concat(path, origin);

            foreach (var item in lstVertex.Where(x => x.Name.Equals(origin)).FirstOrDefault().lstEdge)
            {
                clsVertex v = lstVertex.Where(x => x.Name.Equals(item.Vertex2.ToString())).FirstOrDefault();
                switch (condition)
                {
                    case "MAX":
                        {
                            if (v.Name.Equals(destiny) && stops <= stopsNumber)
                            {
                                caminos.Add(new clsCamino() { path = path, stops = (int)stops });
                                v.Estado = false;

                                return;
                            }
                            break;
                        }
                    case "EQUAL":
                        {
                            if (stops == stopsNumber)
                            {
                                caminos.Add(new clsCamino() { path = path, stops = (int)stops });
                                v.Estado = false;
                                return;
                            }
                            break;
                        }
                }
                if (!v.Estado)
                {
                    stops += 1;
                    getRouteByStops(lstVertex, v.Name, destiny, stopsNumber, condition, caminos, path, stops);
                    v.Estado = false;
                }
            }
        }
Exemplo n.º 4
0
 public void addVertex(clsVertex oVertex)
 {
     this.lstVertex.Add(oVertex);
 }