//Methods to determinate the shorter route. /// <summary> /// Method to get a route. /// </summary> /// <param name="originCity"></param> /// <param name="destinyCity"></param> public void getRoute(string aeropuerto_origen, string aeropuerto_destino, string scale, int _scaleN) { treeNode root = new treeNode(aeropuerto_origen, 0, null); //Load Child Nodes. root.LoadChildNodes(); if (!scale.Equals("")) { scales.Add(new treeNode(scale, 0, null)); } //Method to determinate the full route. Routes(root, aeropuerto_destino, List, scales, _scaleN); }
/// <summary> /// Recursive method to obtain the route. /// </summary> /// <param name="_current"></param> /// <param name="destinyCity"></param> /// <param name="_currentList"></param> /// <param name="_scales"></param> public void Routes(treeNode _current, string destinyCity, List <treeNode> _currentList, List <treeNode> _scales, int _scaleN) { //Stop if found destiny city. if (_current.origen.Equals(destinyCity)) { _currentList.Add(_current); finish = 1; _currentfinish = 1; return; } //Stop if the node is in the list. if (findNode(_current, _currentList)) { _currentList.Add(_current); return; } //Load accesibles nodes. _current.LoadChildNodes(); //Sorts ascending nodes duration. sortChildNodes(_current); //Add current node to principal nodes list. _currentList.Add(_current); int cont = _current.ChildNodes.Count; //Return method if is a ChildNode. if (cont == 0) { return; } for (int i = 0; i < cont; i++) { //Already exist a route. if (_currentfinish == 1) { //Check if current route is shorter than min cost. if (_current.costo > minimumcost) { return; } } _current.ChildNodes[i].LoadChildNodes(); //Recursive call to get full route. Routes(_current.ChildNodes[i], destinyCity, _currentList, _scales, _scaleN); //If found destiny city. if (finish == 1) { finish = 0; if (_currentList.Count <= _scaleN) //Number of scales. 2=no escale, 3= a escale. { //check if all the scales are in the route. and If current route is shorter than minimun cost remplace this route. if (compareScales(_currentList, _scales) == true && _current.ChildNodes[i].costo < minimumcost) { minimumcost = _current.ChildNodes[i].costo; //Create a list with the new route. listClone(_currentList); } } _currentList.RemoveAt(_currentList.Count - 1); continue; //continue; } _currentList.RemoveAt(_currentList.Count - 1); } }