private bool checkStopCriteria() { CTour bestGlobalTour = CIterationList.getInstance().getBestGlobalTour(); // haben wir eine bessere Lösung als die Optimale Lösung gefunden? // dann können wir abbrechen if (mOptTour != null) { if (bestGlobalTour != null) { if ((bestGlobalTour.getTourLength() <= mOptTour.getTourLength()) && (mAlgorithmParam.bBestTourStop == true)) { return(true); } } } // Haben wir den Schwellenwert unterschritten? if (bestGlobalTour != null) { if ((bestGlobalTour.getTourLength() <= mAlgorithmParam.iLimitStop) && (mAlgorithmParam.bLimitStop == true)) { return(true); } } return(false); }
public void NewIteration() { CreateNewAnts(); List <Thread> antThreadList = new List <Thread>(); // Ameisen laufen lassen foreach (CAnt ant in arrayOfAnts) { Thread antThread = new Thread(new ParameterizedThreadStart(this.handleAnt)); antThreadList.Add(antThread); antThread.Name = "AntThread" + antThreadList.Count.ToString(); antThread.Priority = ThreadPriority.Highest; antThread.Start(ant); } // Prüfen ob alle Threads fertig sind bool bAllThreadsFinished = false; while (bAllThreadsFinished == false) { Thread.Sleep(1); bAllThreadsFinished = true; foreach (Thread antThread in antThreadList) { if (antThread.ThreadState == System.Threading.ThreadState.Running) { bAllThreadsFinished = false; } } } // kürzeste Tour ermitteln und die durchschnittliche Länge CTour shortestTour = new CTour(); double averageTourLength = 0; foreach (CAnt ant in arrayOfAnts) { averageTourLength += ant.GetTour().getTourLength() / arrayOfAnts.Length; if ((ant.GetTour().getTourLength() < shortestTour.getTourLength()) || (shortestTour.getTourLength() == 0)) { shortestTour = ant.GetTour(); } } Debug.WriteLine(shortestTour.getTourLength()); // Iteration in die Liste zurückspeichern CIterationList.getInstance().Add(new CIteration(shortestTour, averageTourLength)); }
public CTour getBestGlobalTour() { if (mIterationList.Count > 0) { bestTour = mIterationList[0].ShortestTour; for (var i = 1; i < mIterationList.Count; i++) { var currentTour = mIterationList[i].ShortestTour; if (currentTour.getTourLength() < bestTour.getTourLength()) { bestTour = currentTour; } } return(bestTour); } return(null); }