コード例 #1
0
        private void ReemplazamientoGeneracional()
        {
            poblacionH = poblacionI;


            QAP peorH = poblacionH[0];
            int it    = 0;


            for (int i = 0; i < poblacion.Count; i++)
            {
                if (poblacionH[i].GetCoste() > peorH.GetCoste())
                {
                    peorH = poblacionH[i];
                    it    = i;
                }
            }

            poblacionH[it] = new QAP(mejorPob);


            poblacion.Clear();
            poblacion.AddRange(poblacionH);
            poblacionH.Clear();
            poblacionP.Clear();
        }
コード例 #2
0
ファイル: ILS.cs プロジェクト: juliofgx17/Metaheuristicas-UNI
        private void EjecutarILS()
        {
            QAP qap = new QAP(bestSolution);

            BusquedaLocal bl = new BusquedaLocal(qap);

            qap = bl.ResolverBL();
            QAP best = new QAP(qap);

            for (int i = 0; i < 24; i++)
            {
                Mutar(qap);
                bl  = new BusquedaLocal(qap);
                qap = bl.ResolverBL();

                if (qap.GetCoste() < best.GetCoste())
                {
                    best = new QAP(qap);
                }
                else
                {
                    qap = new QAP(best);
                }
            }


            bestSolution = new QAP(best);
        }
コード例 #3
0
        private void EjecutarILS()
        {
            QAP qap = new QAP(bestSolution);

            ES es = new ES(qap);

            qap = es.GetQAP();
            QAP best = new QAP(qap);

            for (int i = 0; i < 24; i++)
            {
                Mutar(qap);
                es  = new ES(qap);
                qap = es.GetQAP();

                if (qap.GetCoste() < best.GetCoste())
                {
                    best = new QAP(qap);
                }
                else
                {
                    qap = new QAP(best);
                }
            }


            bestSolution = new QAP(best);
        }
コード例 #4
0
        public ES(QAP qap)
        {
            tamProblema = qap.GetTamProblema();

            localizacionesEnUnidades.AddRange(qap.GetLocalizacionesEnUnidades());
            flujosUnidades.AddRange(qap.GetFlujosUnidades());
            distanciasLocalizaciones.AddRange(qap.GetDistanciasLocalizaciones());
            coste = qap.GetCoste();

            ResolverES();
        }
コード例 #5
0
        protected void Evolucionar()
        {
            mutados = 0;
            llamadasFuncionObjetivo = 0;


            for (int i = 0; i < numIteraciones && llamadasFuncionObjetivo < maxLlamadasFuncionObjetivo; i++)
            {
                QAP mejor = poblacion[0];
                for (int j = 0; j < poblacion.Count; j++)
                {
                    if (poblacion[j].GetCoste() < mejor.GetCoste())
                    {
                        mejor = poblacion[j];
                    }
                }

                mejorPob = new QAP(mejor);



                if (estacionario)
                {
                    SeleccionEstacionario();
                    CruceEstacionario();
                    MutacionEstacionario();
                    ReemplazamientoEstacionario();
                }
                else
                {
                    if (memetico && i % ciclosMeme == 0)
                    {
                        AplicarMemetico();
                    }
                    SeleccionGeneracional();
                    CruceGeneracional();
                    MutacionGeneracional();
                    ReemplazamientoGeneracional();
                }



                /*if (i % 100 == 0)
                 * {
                 *  Console.WriteLine("Iteracion " + i);
                 *  Console.WriteLine("Mejor sol " + GetBestSolution().GetCoste());
                 *  Console.WriteLine();
                 *
                 *  Console.WriteLine();
                 *
                 * }*/
            }
        }
コード例 #6
0
        private void AplicarMemetico()
        {
            int llam;

            if (mejorPorcentajeMeme)
            {
                List <QAP> copia = new List <QAP>();
                copia.AddRange(poblacion);
                List <int> mejores     = new List <int>();
                QAP        mejor       = copia[0];
                int        indicemejor = 0;
                for (int i = 0; i < porcentajeMeme * numCromosomas; i++)
                {
                    for (int j = 0; j < copia.Count; j++)
                    {
                        if (mejor.GetCoste() < copia[i].GetCoste())
                        {
                            mejor       = copia[i];
                            indicemejor = i;
                        }
                    }
                    mejores.Add(indicemejor);
                    copia.Remove(mejor);
                }

                for (int i = 0; i < mejores.Count; i++)
                {
                    bl.SetQAP(poblacion[mejores[i]]);
                    llam = llamadasFuncionObjetivo;
                    poblacion[mejores[i]].SetQAP(bl.ResolverBL(ref llam));
                    llamadasFuncionObjetivo = llam;
                }
            }
            else
            {
                for (int i = 0; i < porcentajeMeme * numCromosomas; i++)
                {
                    bl.SetQAP(poblacion[i]);
                    llam = llamadasFuncionObjetivo;
                    poblacion[i].SetQAP(bl.ResolverBL(ref llam));
                    llamadasFuncionObjetivo = llam;
                }
            }
        }
コード例 #7
0
ファイル: BMB.cs プロジェクト: juliofgx17/Metaheuristicas-UNI
        public BMB(int numMultiarranque, string ruta)
        {
            QAP           qap  = new QAP(ruta);
            BusquedaLocal bl   = new BusquedaLocal(qap);
            QAP           best = bl.ResolverBL();

            for (int i = 1; i < numMultiarranque; i++)
            {
                qap = new QAP(ruta);
                bl  = new BusquedaLocal(qap);
                qap = bl.ResolverBL();
                if (qap.GetCoste() < best.GetCoste())
                {
                    best.SetQAP(qap);
                }
            }

            solucion = best;
        }