示例#1
0
        public NodeState MakeChild(ref NodeState parentNode, int i)
        {
            //FROM and TO city indices
            int cityCount = Cities.Length;
            int fromCity  = parentNode.GetLastCityInRouteIndex();
            int toCity    = i;

            //Make a child matrix from parent
            double[,] copyMatrix  = CopyMatrix(parentNode.GetMatrix(), cityCount);
            double[,] childMatrix = MakeChildMatrix(copyMatrix, fromCity, toCity);

            //Inherit and add to lower bound for the child
            double childLB = parentNode.GetLowerBound() + parentNode.GetMatrix()[toCity, fromCity];

            //Inherit and add to route for the child
            ArrayList childRoute = (ArrayList)parentNode.GetRoute().Clone();

            childRoute.Add(Cities[toCity]);

            //Inherit the cities already visited by the parent and add the city the child is going to be in.
            List <bool> childCitiesVisited = CopyCitiesVisited(parentNode.GetCitiesVisited());

            childCitiesVisited[toCity] = true;

            return(new NodeState(childMatrix, childLB, childRoute, toCity, childCitiesVisited));
        }
示例#2
0
 public bool BetterBSSFExists(ref NodeState node, int startCity)
 {
     if (node.HasVisitedAllCities())
     {
         //check if it can go back to it's first city
         int currentCity = node.GetLastCityInRouteIndex();
         double[,] nodeMatrix = node.GetMatrix();
         if (nodeMatrix[startCity, currentCity] != Double.PositiveInfinity)
         {
             //We can go back.
             return(true);
         }
         else
         {
             return(false);
         }
     }
     else
     {
         return(false);
     }
 }