예제 #1
0
파일: Search.cs 프로젝트: Nerond32/PSI
        public void Start()
        {
            RandomizeLocations();
            State alpha = new State();

            alpha.AddCityToPath(SearchInfo.AllCities[0]);
            switch ((Algorithm)method)
            {
            case Algorithm.BruteForceDSF:
            {
                tspAlg = new BruteForceDFS_TSPAlgorithm(SearchInfo, DrawingBoard);
                break;
            }

            case Algorithm.BruteForceBSF:
            {
                tspAlg = new BruteForceBFS_TSPAlgorithm(SearchInfo, DrawingBoard);
                break;
            }

            case Algorithm.GreedyAlgorithm:
            {
                tspAlg = new TSPGreedyAlgorithm(SearchInfo, DrawingBoard);
                break;
            }

            case Algorithm.GeneticAlgorithm:
            {
                tspAlg = new TSPGeneticAlgorithm(SearchInfo, DrawingBoard);
                break;
            }
            }
            states = tspAlg.ChildStates(alpha);
        }
예제 #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);
            }
        }
예제 #3
0
 protected List <State> ReturnBottomChild(State parentState, List <State> childStates)
 {
     if (SearchInfo.ReturnToStart)
     {
         parentState.AddCityToPath(SearchInfo.AllCities[0]);
         parentState.Cost += City.TravelCostBetweenCities(SearchInfo.AllCities[parentState.path[parentState.path.Count - 2]], SearchInfo.AllCities[0]);
     }
     childStates.Add(parentState);
     return(childStates);
 }