예제 #1
0
        public bool Cycle()
        {
            CalcEdgesWkt();

            for (int i = 0; i < m_Ants.Count; i++)
            {
                Ant a = (Ant)m_Ants[i];
                a.SetToStart();
            }

            for (int j = 0; j < m_iftcAntTsp.Nodes.Count - 1; j++)
            {
                for (int i = 0; i < m_Ants.Count; i++)
                {
                    Ant a = (Ant)m_Ants[i];
                    a.MoveToNextNode();
                }
            }

            for (int i = 0; i < m_Ants.Count; i++)
            {
                Ant a = (Ant)m_Ants[i];
                a.CalcAntRoute();
                a.UpDateEdges(ConstQ);
            }

            UpdateEdgeWeights();

            Ant Speedy = FindFastestAnt();

            m_SpeedRoute = Speedy.GetAntRoute;

            return(TestEnd());
        }
예제 #2
0
        private Ant FindFastestAnt()
        {
            int   AntNr = 0;
            float WaLen = 0;

            for (int i = 0; i < m_Ants.Count; i++)
            {
                Ant a = (Ant)m_Ants[i];
                a.CalcAntRoute();
                float tmpRoute = a.Length;
                if (i > 0)
                {
                    if (tmpRoute < WaLen)
                    {
                        WaLen = tmpRoute;
                        AntNr = i;
                    }
                }
                else
                {
                    WaLen = tmpRoute;
                    AntNr = i;
                }
            }

            if (m_ShortestPath < 0)
            {
                m_ShortestPath = WaLen;
            }
            else
            {
                if (WaLen < m_ShortestPath)
                {
                    m_ShortestPath = WaLen;
                    m_FastestAnt   = AntNr;
                }
            }
            return((Ant)m_Ants[m_FastestAnt]);
        }