Example #1
0
        //-------------------------------------------------------------------\
        private List <int> GetPseudoRoute(ref MeshEnvironment env)
        {
            //Pseudo route //Random Process
            List <int> pseudo_route = new List <int>();

            pseudo_route.Add(env.start_node);

            int    i                 = 0;
            int    random_idx        = -1;
            Double current_proximity = env.CalculateProximity(env.start_node);

            //Init the loop from the initial node and chose a node randomly
            while (i < num_random_nodes && random_idx != env.final_node - 1)
            {
                //In each step, I verify that the new random node is farther than the previous one, checking the proximity value of that node.
                random_idx = random.Next(pseudo_route[pseudo_route.Count - 1], env.final_node);
                Double next_proximity = env.CalculateProximity(random_idx);
                if (!env.obstacles.Contains(random_idx) && !pseudo_route.Contains(random_idx) && next_proximity < current_proximity)
                {
                    //Only add the a new random node that it is further that the previous one
                    pseudo_route.Add(random_idx);
                    i++;
                    current_proximity = next_proximity;
                }
            }

            //At the end, add the final node
            pseudo_route.Add(env.final_node);

            return(pseudo_route);
        }
Example #2
0
        //-------------------------------------------------------------------\
        private List <int> GetPseudoRoute(ref MeshEnvironment env)
        {
            //Pseudo ruta //Random Process
            List <int> pseudo_route = new List <int>();

            pseudo_route.Add(env.start_node);

            int    i                 = 0;
            int    random_idx        = -1;
            Double current_proximity = env.CalculateProximity(env.start_node);


            while (i < num_random_nodes && random_idx != env.final_node - 1)
            {
                random_idx = random.Next(pseudo_route[pseudo_route.Count - 1], env.final_node);
                Double next_proximity = env.CalculateProximity(random_idx);
                if (!env.obstacles.Contains(random_idx) && !pseudo_route.Contains(random_idx) && next_proximity < current_proximity)
                {
                    pseudo_route.Add(random_idx);
                    i++;
                    current_proximity = next_proximity;
                }
            }

            pseudo_route.Add(env.final_node);

            return(pseudo_route);
        }
Example #3
0
        //---------------------------------------------------------------------
        //This function returns the neighbor node that has the best proximity value
        private int FindBestNode(ref MeshEnvironment env, ref List <int> fragment_route, ref List <int> current_route, int current_node, int node2)
        {
            List <int>    neighboors  = env.world[current_node].neighboors;
            List <Double> proximities = new List <Double>();

            for (int i = 0; i < neighboors.Count; i++)
            {
                int    neigh_node = neighboors[i];
                Double proximity;
                if (!fragment_route.Contains(neigh_node) && !current_route.Contains(neigh_node) && !env.obstacles.Contains(neigh_node))
                {
                    proximity = env.CalculateProximity(current_node, neigh_node, node2);
                }
                else
                {
                    proximity = -1;
                }

                proximities.Add(proximity);
            }

            Double max_proximity = proximities.Max();

            if (max_proximity != -1)
            {
                int index_max1 = proximities.IndexOf(max_proximity);

                return(neighboors[index_max1]);
            }
            else
            {
                return(-1);
            }
        }