예제 #1
0
        /// <summary>
        /// Konstruktor
        /// </summary>
        /// <param name="label">Label des Punktes</param>
        public CTSPPoint(string label = "")
        {
            mLabel = label;

            // es wurde ein Punkt erzeugt .. also ein Schritt erfolgreich abgearbeteitet
            CProgressManager.stepDone();
        }
예제 #2
0
        /// <summary>
        /// Konstruktor
        /// </summary>
        /// <param name="tspPoint1">Punkt 1 der Verbindung</param>
        /// <param name="tspPoint2">Punkt 2 der Verbindung</param>
        /// <param name="distanceCalculation">Gibt an auf welche Art die Entfernung zwischen den Punkten berechnet werden soll</param>
        /// <param name="initialPheromone">Pheromon das die Verbindung von Beginn an haben soll</param>
        public CConnection(CTSPPoint tspPoint1, CTSPPoint tspPoint2, CTSPLibFileParser.E_EDGE_WEIGHT_TYPE distanceCalculation, float initialPheromone = 0)
        {
            mTSPPoint1           = tspPoint1;
            mTSPPoint2           = tspPoint2;
            mDistanceCalculation = distanceCalculation;

            if (initialPheromone <= 0)
            {
                mPheromone = MIN_PHEROMONE;
            }
            else
            {
                mPheromone = initialPheromone;
            }

            calculateDistance();

            // es wurde eine Verbindung erzeugt .. also ein Schritt erfolgreich abgearbeteitet
            CProgressManager.stepDone();
        }
예제 #3
0
        public void startAlgorithm()
        {
            CProgressManager.setStepsIteration(mMaxIterations);

            mConnectionList.SetInitialPheromone(mInitialPheromone);

            mItertationsTextbox.Invoke(new Action(delegate()
            {
                mItertationsTextbox.Text = "0/" + mMaxIterations;
            }));

            DateTime startTime = DateTime.Now;

            int  iteration      = 0;
            bool bStopAlgorithm = false;

            while ((iteration < mMaxIterations) && (bStopAlgorithm == false))
            {
                NewIteration();

                // Evaporation (verdunstung)
                //--------------------------------
                // Dazu iterieren wir durch alle Verbindungen und lassen das Pheromon verdunsten
                foreach (CConnection connection in mConnectionList)
                {
                    connection.evaporate(mEvaporationFactor);
                }

                // Pheromon-Update
                //--------------------------------
                // Dazu durch alle Touren von allen Ameisen nachgehen und für jede Verbindung die
                // Pheromonwerte neu berechnen
                // Formel: delta(t ij) = Q / (distance ij)
                foreach (CAnt ant in arrayOfAnts)
                {
                    CTour antTour = ant.GetTour();

                    // wir fangen mit Index 1 an! Damit die Punkte der Verbindungen mit den Indizies
                    // index -1 und index geholt werden können
                    for (int pointIndex = 1; pointIndex < antTour.getListLength(); pointIndex++)
                    {
                        CTSPPoint fromPoint = antTour.getPoint(pointIndex - 1);
                        CTSPPoint toPoint   = antTour.getPoint(pointIndex);

                        CConnection tourConnection = mConnectionList.getConnection(fromPoint, toPoint);
                        tourConnection.addPheromone(mPhermomoneUpdate);
                    }
                }

                CIterationList.getInstance().refreshStatisticNumbers();
                mRenderWindow.Invoke(mRenderWindow.refreshDelegate);
                CProgressManager.stepDone();

                mItertationsTextbox.Invoke(new Action(delegate()
                {
                    mItertationsTextbox.Text = (iteration + 1) + "/" + mMaxIterations;
                }));

                Debug.WriteLine("Iteration done: " + (iteration + 1));


                // Stopkriterien testen
                bStopAlgorithm = checkStopCriteria();

                // Iterationszähler erhöhen
                iteration++;
            }

            Debug.WriteLine("Dauer: " + (DateTime.Now - startTime).TotalSeconds + " sek");
        }