Пример #1
0
 public static void Start(SearchParameter input, int method)
 {
     tsp = new Search(drawingBoard, input, method);
     tsp.Start();
     tsp.Sort(1);
     drawingBoard.DrawPath(tsp.states[0], tsp.SearchInfo.AllCities);
     PrintOptimalPath(tsp.states[0]);
 }
Пример #2
0
        public override List <State> ChildStates(State parentState)
        {
            List <Int16> unvisitedCities = FilterUnvisitedCities(parentState.path, SearchInfo.AllCities);
            List <State> childStates     = new List <State>();

            if (unvisitedCities.Count == 0)
            {
                return(ReturnBottomChild(parentState, childStates));
            }
            else
            {
                foreach (Int16 c in unvisitedCities)
                {
                    State child = (State)State.DeepClone(parentState);
                    child.AddCityToPath(SearchInfo.AllCities[c]);
                    if (SearchInfo.Visualize)
                    {
                        DrawingBoard.DrawPath(child, SearchInfo.AllCities);
                        Thread.Sleep(500);
                    }
                    child.Cost += City.TravelCostBetweenCities(SearchInfo.AllCities[child.path[child.path.Count - 2]], SearchInfo.AllCities[c]);
                    List <State> tmp = ChildStates(child);
                    foreach (State s in tmp)
                    {
                        childStates.Add(s);
                    }
                }
                return(childStates);
            }
        }