Example #1
0
        private static Dictionary <Point, List <Point> > DivideLocationsToCenters(List <Point> lstLocs,
                                                                                  Dictionary <Point, int> dicCentersVehicles,
                                                                                  int ants,
                                                                                  double alpha,
                                                                                  double beta,
                                                                                  double q0,
                                                                                  double tao0)
        {
            const int ITERATIONS = 5;

            Dictionary <KeyValuePair <Point, Point>, double> dicPhTrails =
                MultiVRP.InitPheromoneTrails(dicCentersVehicles.Keys.ToList(), lstLocs);

            List <Dictionary <Point, List <Point> > > lstSolutions =
                new List <Dictionary <Point, List <Point> > >();

            Dictionary <Point, List <Point> > dicReallyBestSolution = null;

            for (int nIter = 0; nIter < ITERATIONS; nIter++)
            {
                lstSolutions.Clear();
                for (int nAnt = 0; nAnt < ants; nAnt++)
                {
                    lstSolutions.Add(MVRPAnt.MatchLocsToCenter(dicPhTrails, beta, q0));
                }

                for (int nInd = 0; nInd < lstSolutions.Count; nInd++)
                {
                    TrailUpdating(dicPhTrails, lstSolutions[nInd], alpha, tao0);
                }

                double dBestSolLength =
                    (from sol in lstSolutions
                     select GetTotalDist(sol)).Min();
                Dictionary <Point, List <Point> > dicBestSol =
                    (from sol in lstSolutions
                     where GetTotalDist(sol) == dBestSolLength
                     select sol).First();

                TrailUpdating(dicPhTrails, dicBestSol, alpha, 1 / dBestSolLength);

                if (dicReallyBestSolution == null || dBestSolLength < GetTotalDist(dicReallyBestSolution))
                {
                    dicReallyBestSolution = dicBestSol;
                }
            }

            return(dicReallyBestSolution);
        }