/// <summary>
        ///Usage: three choices
        ///     - AbYSS
        ///     - AbYSS problemName
        ///     - AbYSS problemName paretoFrontFile
        /// </summary>
        /// <param name="args">Command line arguments.</param>
        public static void Main(string[] args)
        {
            Problem   problem;                      // The problem to solve
            Algorithm algorithm;                    // The algorithm to use
            Operator  crossover;                    // Crossover operator
            Operator  mutation;                     // Mutation operator
            Operator  improvement;                  // Operator for improvement

            Dictionary <string, object> parameters; // Operator parameters

            QualityIndicator indicators;            // Object to get quality indicators

            // Logger object and file to store log messages
            var logger       = Logger.Log;
            var appenders    = logger.Logger.Repository.GetAppenders();
            var fileAppender = appenders[0] as log4net.Appender.FileAppender;

            fileAppender.File = "AbYSS.log";
            fileAppender.ActivateOptions();


            indicators = null;
            if (args.Length == 1)
            {
                object[] param = { "Real" };
                problem = ProblemFactory.GetProblem(args[0], param);
            }
            else if (args.Length == 2)
            {
                object[] param = { "Real" };
                problem    = ProblemFactory.GetProblem(args[0], param);
                indicators = new QualityIndicator(problem, args[1]);
            }
            else
            {             // Default problem
                problem = new Kursawe("Real", 3);
                //problem = new Kursawe("BinaryReal", 3);
                //problem = new Water("Real");
                //problem = new ZDT4("ArrayReal", 10);
                //problem = new ConstrEx("Real");
                //problem = new DTLZ1("Real");
                //problem = new OKA2("Real") ;
            }

            // STEP 2. Select the algorithm (AbYSS)
            algorithm = new JMetalCSharp.Metaheuristics.AbYSS.AbYSS(problem);

            // STEP 3. Set the input parameters required by the metaheuristic
            algorithm.SetInputParameter("populationSize", 20);
            algorithm.SetInputParameter("refSet1Size", 10);
            algorithm.SetInputParameter("refSet2Size", 10);
            algorithm.SetInputParameter("archiveSize", 100);
            algorithm.SetInputParameter("maxEvaluations", 25000);

            // STEP 4. Specify and configure the crossover operator, used in the
            //         solution combination method of the scatter search
            parameters = new Dictionary <string, object>();
            parameters.Add("probability", 0.9);
            parameters.Add("distributionIndex", 20.0);
            crossover = CrossoverFactory.GetCrossoverOperator("SBXCrossover", parameters);

            // STEP 5. Specify and configure the improvement method. We use by default
            //         a polynomial mutation in this method.
            parameters = new Dictionary <string, object>();
            parameters.Add("probability", 1.0 / problem.NumberOfVariables);
            parameters.Add("distributionIndex", 20.0);
            mutation = MutationFactory.GetMutationOperator("PolynomialMutation", parameters);

            parameters = new Dictionary <string, object>();
            parameters.Add("improvementRounds", 1);
            parameters.Add("problem", problem);
            parameters.Add("mutation", mutation);
            improvement = new MutationLocalSearch(parameters);

            // STEP 6. Add the operators to the algorithm
            algorithm.AddOperator("crossover", crossover);
            algorithm.AddOperator("improvement", improvement);

            long initTime = Environment.TickCount;

            // STEP 7. Run the algorithm
            SolutionSet population    = algorithm.Execute();
            long        estimatedTime = Environment.TickCount - initTime;

            // STEP 8. Print the results
            logger.Info("Total execution time: " + estimatedTime + "ms");
            logger.Info("Variables values have been writen to file VAR");
            population.PrintVariablesToFile("VAR");
            logger.Info("Objectives values have been writen to file FUN");
            population.PrintObjectivesToFile("FUN");

            Console.WriteLine("Total execution time: " + estimatedTime + "ms");
            Console.ReadLine();
            if (indicators != null)
            {
                logger.Info("Quality indicators");
                logger.Info("Hypervolume: " + indicators.GetHypervolume(population));
                logger.Info("GD         : " + indicators.GetGD(population));
                logger.Info("IGD        : " + indicators.GetIGD(population));
                logger.Info("Spread     : " + indicators.GetSpread(population));
                logger.Info("Epsilon    : " + indicators.GetEpsilon(population));
            }
        }
        /// <summary>
        /// Usage:
        ///     - NSGAIImTSP
        /// </summary>
        /// <param name="args">Command line arguments.</param>
        public static void Main(string[] args)
        {
            Problem   problem;                      // The problem to solve
            Algorithm algorithm;                    // The algorithm to use
            Operator  crossover;                    // Crossover operator
            Operator  mutation;                     // Mutation operator
            Operator  selection;                    // Selection operator

            Dictionary <string, object> parameters; // Operator parameters

            QualityIndicator indicators;            // Object to get quality indicators

            // Logger object and file to store log messages
            var logger = Logger.Log;

            var appenders    = logger.Logger.Repository.GetAppenders();
            var fileAppender = appenders[0] as log4net.Appender.FileAppender;

            fileAppender.File = "NSGAIImTSP.log";
            fileAppender.ActivateOptions();

            indicators = null;
            problem    = new MTSP("Permutation", "kroA150.tsp", "kroB150.tsp");

            algorithm = new JMetalCSharp.Metaheuristics.NSGAII.NSGAII(problem);
            //algorithm = new ssNSGAII(problem);

            // Algorithm parameters
            algorithm.SetInputParameter("populationSize", 100);
            algorithm.SetInputParameter("maxEvaluations", 10000000);

            /* Crossver operator */
            parameters = new Dictionary <string, object>();
            parameters.Add("probability", 0.95);
            //crossover = CrossoverFactory.getCrossoverOperator("TwoPointsCrossover", parameters);
            crossover = CrossoverFactory.GetCrossoverOperator("PMXCrossover", parameters);

            /* Mutation operator */
            parameters = new Dictionary <string, object>();
            parameters.Add("probability", 0.2);
            mutation = MutationFactory.GetMutationOperator("SwapMutation", parameters);

            /* Selection Operator */
            parameters = null;
            selection  = SelectionFactory.GetSelectionOperator("BinaryTournament", parameters);

            // Add the operators to the algorithm
            algorithm.AddOperator("crossover", crossover);
            algorithm.AddOperator("mutation", mutation);
            algorithm.AddOperator("selection", selection);

            // Add the indicator object to the algorithm
            algorithm.SetInputParameter("indicators", indicators);

            // Execute the Algorithm
            long        initTime      = Environment.TickCount;
            SolutionSet population    = algorithm.Execute();
            long        estimatedTime = Environment.TickCount - initTime;

            // Result messages
            logger.Info("Total execution time: " + estimatedTime + "ms");
            logger.Info("Variables values have been writen to file VAR");
            population.PrintVariablesToFile("VAR");
            logger.Info("Objectives values have been writen to file FUN");
            population.PrintObjectivesToFile("FUN");

            if (indicators != null)
            {
                logger.Info("Quality indicators");
                logger.Info("Hypervolume: " + indicators.GetHypervolume(population));
                logger.Info("GD         : " + indicators.GetGD(population));
                logger.Info("IGD        : " + indicators.GetIGD(population));
                logger.Info("Spread     : " + indicators.GetSpread(population));
                logger.Info("Epsilon    : " + indicators.GetEpsilon(population));

                int evaluations = (int)algorithm.GetOutputParameter("evaluations");
                logger.Info("Speed      : " + evaluations + " evaluations");
            }
        }
        /// <summary>
        /// Usage: three options
        ///    - SPEA2
        ///    - SPEA2 problemName
        ///    - SPEA2 problemName ParetoFrontFile
        /// </summary>
        /// <param name="args">Command line arguments. The first (optional) argument specifies the problem to solve.</param>
        public static void Main(string[] args)
        {
            Problem   problem;                      // The problem to solve
            Algorithm algorithm;                    // The algorithm to use
            Operator  crossover;                    // Crossover operator
            Operator  mutation;                     // Mutation operator
            Operator  selection;                    // Selection operator

            QualityIndicator indicators;            // Object to get quality indicators

            Dictionary <string, object> parameters; // Operator parameters

            // Logger object and file to store log messages
            var logger = Logger.Log;

            var appenders    = logger.Logger.Repository.GetAppenders();
            var fileAppender = appenders[0] as log4net.Appender.FileAppender;

            fileAppender.File = "SPEA2.log";
            fileAppender.ActivateOptions();

            indicators = null;
            if (args.Length == 1)
            {
                object[] param = { "Real" };
                problem = ProblemFactory.GetProblem(args[0], param);
            }
            else if (args.Length == 2)
            {
                object[] param = { "Real" };
                problem    = ProblemFactory.GetProblem(args[0], param);
                indicators = new QualityIndicator(problem, args[1]);
            }
            else
            {             // Default problem
                problem = new Kursawe("Real", 3);
                //problem = new Water("Real");
                //problem = new ZDT1("ArrayReal", 1000);
                //problem = new ZDT4("BinaryReal");
                //problem = new WFG1("Real");
                //problem = new DTLZ1("Real");
                //problem = new OKA2("Real") ;
            }

            algorithm = new JMetalCSharp.Metaheuristics.SPEA2.SPEA2(problem);

            // Algorithm parameters
            algorithm.SetInputParameter("populationSize", 100);
            algorithm.SetInputParameter("archiveSize", 100);
            algorithm.SetInputParameter("maxEvaluations", 25000);

            // Mutation and Crossover for Real codification
            parameters = new Dictionary <string, object>();
            parameters.Add("probability", 0.9);
            parameters.Add("distributionIndex", 20.0);
            crossover = CrossoverFactory.GetCrossoverOperator("SBXCrossover", parameters);

            parameters = new Dictionary <string, object>();
            parameters.Add("probability", 1.0 / problem.NumberOfVariables);
            parameters.Add("distributionIndex", 20.0);
            mutation = MutationFactory.GetMutationOperator("PolynomialMutation", parameters);

            // Selection operator
            parameters = null;
            selection  = SelectionFactory.GetSelectionOperator("BinaryTournament", parameters);

            // Add the operators to the algorithm
            algorithm.AddOperator("crossover", crossover);
            algorithm.AddOperator("mutation", mutation);
            algorithm.AddOperator("selection", selection);

            // Execute the algorithm
            long        initTime      = Environment.TickCount;
            SolutionSet population    = algorithm.Execute();
            long        estimatedTime = Environment.TickCount - initTime;

            // Result messages
            logger.Info("Total execution time: " + estimatedTime + "ms");
            logger.Info("Objectives values have been writen to file FUN");
            population.PrintObjectivesToFile("FUN");
            logger.Info("Variables values have been writen to file VAR");
            population.PrintVariablesToFile("VAR");

            if (indicators != null)
            {
                logger.Info("Quality indicators");
                logger.Info("Hypervolume: " + indicators.GetHypervolume(population));
                logger.Info("GD         : " + indicators.GetGD(population));
                logger.Info("IGD        : " + indicators.GetIGD(population));
                logger.Info("Spread     : " + indicators.GetSpread(population));
                logger.Info("Epsilon    : " + indicators.GetEpsilon(population));
            }
            Console.WriteLine("Total execution time: " + estimatedTime + "ms");
            Console.ReadLine();
        }
        /// <summary>
        /// Usage: three options
        ///     - NSGAII
        ///     - NSGAII problemName
        ///     - NSGAII problemName paretoFrontFile
        /// </summary>
        /// <param name="args"></param>
        public NSGAIIRunner(string[] args, Problem p, string Path, MOO comp)
        {
            Problem   problem = p; // The problem to solve
            Algorithm algorithm;   // The algorithm to use
            Operator  crossover;   // Crossover operator
            Operator  mutation;    // Mutation operator
            Operator  selection;   // Selection operator

            this.comp = comp;

            Dictionary <string, object> parameters; // Operator parameters

            QualityIndicator indicators;            // Object to get quality indicators

            // Logger object and file to store log messages
            //var logger = Logger.Log;

            //var appenders = logger.Logger.Repository.GetAppenders();
            //var fileAppender = appenders[0] as log4net.Appender.FileAppender;
            //fileAppender.File = "NSGAII.log";
            //fileAppender.ActivateOptions();

            indicators = null;
            //if (args.Length == 1)
            //{
            //    object[] param = { "Real" };
            //    problem = ProblemFactory.GetProblem(args[0], param);
            //}
            //else if (args.Length == 2)
            //{
            //    object[] param = { "Real" };
            //    problem = ProblemFactory.GetProblem(args[0], param);
            //    indicators = new QualityIndicator(problem, args[1]);
            //}
            //else
            //{ // Default problem
            //    //problem = ;
            //    //problem = new Kursawe("BinaryReal", 3);
            //    //problem = new Water("Real");
            //    //problem = new ZDT3("ArrayReal", 30);
            //    //problem = new ConstrEx("Real");
            //    //problem = new DTLZ1("Real");
            //    //problem = new OKA2("Real") ;
            //}

            algorithm = new NSGAII(problem, comp);
            //algorithm = new ssNSGAII(problem);

            // Algorithm parameters
            algorithm.SetInputParameter("populationSize", comp.popSize);
            algorithm.SetInputParameter("maxEvaluations", comp.maxEvals);
            comp.LogAddMessage("Population Size = " + comp.popSize);
            comp.LogAddMessage("Max Evaluations = " + comp.maxEvals);

            // Mutation and Crossover for Real codification
            parameters = new Dictionary <string, object>();
            parameters.Add("probability", 0.9);
            parameters.Add("distributionIndex", 20.0);
            crossover = CrossoverFactory.GetCrossoverOperator("SBXCrossover", parameters);
            comp.LogAddMessage("Crossover Type = " + "SBXCrossover");
            comp.LogAddMessage("Crossover Probability = " + 0.9);
            comp.LogAddMessage("Crossover Distribution Index = " + 20);

            parameters = new Dictionary <string, object>();
            parameters.Add("probability", 1.0 / problem.NumberOfVariables);
            parameters.Add("distributionIndex", 20.0);
            mutation = MutationFactory.GetMutationOperator("PolynomialMutation", parameters);
            comp.LogAddMessage("Mutation Type = " + "Polynomial Mutation");
            comp.LogAddMessage("Mutation Probability = " + (1 / problem.NumberOfVariables));
            comp.LogAddMessage("Mutation Distribution Index = " + 20);

            // Selection Operator
            parameters = null;
            selection  = SelectionFactory.GetSelectionOperator("BinaryTournament2", parameters);
            comp.LogAddMessage("Selection Type = " + "Binary Tournament 2");

            // Add the operators to the algorithm
            algorithm.AddOperator("crossover", crossover);
            algorithm.AddOperator("mutation", mutation);
            algorithm.AddOperator("selection", selection);

            // Add the indicator object to the algorithm
            algorithm.SetInputParameter("indicators", indicators);

            // Execute the Algorithm
            long        initTime      = Environment.TickCount;
            SolutionSet population    = algorithm.Execute();
            long        estimatedTime = Environment.TickCount - initTime;

            comp.LogAddMessage("Total Execution Time = " + estimatedTime + "ms");

            // Result messages
            //logger.Info("Total execution time: " + estimatedTime + "ms");
            //logger.Info("Variables values have been writen to file VAR");

            //population.PrintVariablesToFile(@"C:\Users\Jonathas\Desktop\text.txt");
            population.PrintVariablesToFile(@"" + comp.fileName + "VAR-" + comp.fileName);
            //logger.Info("Objectives values have been writen to file FUN");
            population.PrintObjectivesToFile(@"" + comp.fileName + "OBJ-" + comp.fileName);
            // Saving all solutions to file


            //Console.WriteLine("Time: " + estimatedTime);
            //Console.ReadLine();
            if (indicators != null)
            {
                //logger.Info("Quality indicators");
                //logger.Info("Hypervolume: " + indicators.GetHypervolume(population));
                //logger.Info("GD         : " + indicators.GetGD(population));
                //logger.Info("IGD        : " + indicators.GetIGD(population));
                //logger.Info("Spread     : " + indicators.GetSpread(population));
                //logger.Info("Epsilon    : " + indicators.GetEpsilon(population));

                int evaluations = (int)algorithm.GetOutputParameter("evaluations");
                //logger.Info("Speed      : " + evaluations + " evaluations");
            }
        }
Ejemplo n.º 5
0
        private void Button_Click_2(object sender, RoutedEventArgs e)
        {
            FileRead read = new FileRead();

            read.fileread();
            Problem          problem    = read.GetProblem();
            Algorithm        algorithm  = read.GetAlgorithm();
            QualityIndicator indicators = new QualityIndicator(problem, read.Qi);

            NewAlgorithmTest test = new NewAlgorithmTest();

            for (int i = 1; i <= int.Parse(read.Rt); i++)
            {
                // Logger object and file to store log messages
                var logger = Logger.Log;

                var appenders    = logger.Logger.Repository.GetAppenders();
                var fileAppender = appenders[0] as log4net.Appender.FileAppender;
                fileAppender.File = read.DirPath + "/" + read.Al + i + ".log";
                fileAppender.ActivateOptions();

                string filevar = read.DirPath + "/VAR" + i;
                string filefun = read.DirPath + "/FUN" + i;

                FileStream   file      = new FileStream(read.DirPath + "/MOEADnew" + i + ".txt", FileMode.OpenOrCreate, FileAccess.ReadWrite);
                StreamWriter newlogger = new StreamWriter(file);

                // Execute the Algorithm
                long        initTime      = Environment.TickCount;
                SolutionSet population    = test.Mix();
                long        estimatedTime = Environment.TickCount - initTime;

                // Result messages
                logger.Info("Total execution time: " + estimatedTime + "ms");
                logger.Info("Variables values have been writen to file " + filevar);
                newlogger.WriteLine("Total execution time: " + estimatedTime + "ms" + "\n");
                newlogger.WriteLine("Variables values have been writen to file " + filevar + "\n");
                population.PrintVariablesToFile(filevar);
                logger.Info("Objectives values have been writen to file " + filefun);
                population.PrintObjectivesToFile(filefun);
                Console.WriteLine("Time: " + estimatedTime);
                newlogger.WriteLine("Time: " + estimatedTime + "\n");
                Console.ReadLine();
                if (indicators != null)
                {
                    logger.Info("Quality indicators");
                    logger.Info("Hypervolume: " + indicators.GetHypervolume(population));
                    logger.Info("GD         : " + indicators.GetGD(population));
                    logger.Info("IGD        : " + indicators.GetIGD(population));
                    logger.Info("Spread     : " + indicators.GetSpread(population));
                    logger.Info("Epsilon    : " + indicators.GetEpsilon(population));

                    newlogger.WriteLine("Quality indicators");
                    newlogger.WriteLine("Hypervolume: " + indicators.GetHypervolume(population).ToString("F18") + "\n");
                    newlogger.WriteLine("GD         : " + indicators.GetGD(population).ToString("F18") + "\n");
                    newlogger.WriteLine("IGD        : " + indicators.GetIGD(population).ToString("F18") + "\n");
                    newlogger.WriteLine("Spread     : " + indicators.GetSpread(population).ToString("F18") + "\n");
                    newlogger.WriteLine("Epsilon    : " + indicators.GetEpsilon(population).ToString("F18") + "\n");

                    int evaluations = test.GetEvaluations();
                    logger.Info("Speed      : " + evaluations + "     evaluations");
                    newlogger.WriteLine("Speed      : " + evaluations + "     evaluations" + "\n");
                }
                newlogger.Close();
                file.Close();
            }
        }
Ejemplo n.º 6
0
        public void MyAlgorithm()
        {
            Problem   problem   = null;  // The problem to solve
            Algorithm algorithm = null;  // The algorithm to use
            Operator  crossover = null;  // Crossover operator
            Operator  mutation  = null;  // Mutation operator
            Operator  selection = null;  // Selection operator

            QualityIndicator indicators; // Object to get quality indicators

            FileRead fileRead = new FileRead();

            fileRead.fileread();
            problem   = fileRead.GetProblem();
            algorithm = fileRead.GetAlgorithm();
            //crossover = fileRead.GetCrossover();
            mutation  = fileRead.GetMutation();
            selection = fileRead.GetSelection();

            // Quality Indicators Operator
            //indicators = new QualityIndicator(problem, "DTLZ1.3D.pf");
            indicators = new QualityIndicator(problem, fileRead.Qi);
            //indicators = new QualityIndicator(problem, "LZ09_F1.pf");

            // Add the operators to the algorithm
            algorithm.AddOperator("crossover", crossover);
            algorithm.AddOperator("mutation", mutation);
            algorithm.AddOperator("selection", selection);

            // Add the indicator object to the algorithm
            algorithm.SetInputParameter("indicators", indicators);

            for (int i = 1; i <= int.Parse(fileRead.Rt); i++)
            {
                // Logger object and file to store log messages
                var logger = Logger.Log;

                var appenders    = logger.Logger.Repository.GetAppenders();
                var fileAppender = appenders[0] as log4net.Appender.FileAppender;
                fileAppender.File = fileRead.DirPath + "/" + fileRead.Al + i + ".log";
                fileAppender.ActivateOptions();

                string filevar = fileRead.DirPath + "/VAR" + i;
                string filefun = fileRead.DirPath + "/FUN" + i;

                FileStream   file      = new FileStream(fileRead.DirPath + "/" + fileRead.Al + "new" + i + ".txt", FileMode.OpenOrCreate, FileAccess.ReadWrite);
                StreamWriter newlogger = new StreamWriter(file);

                // Execute the Algorithm
                long        initTime      = Environment.TickCount;
                SolutionSet population    = algorithm.Execute();
                long        estimatedTime = Environment.TickCount - initTime;

                // Result messages
                logger.Info("Total execution time: " + estimatedTime + "ms");
                logger.Info("Variables values have been writen to file " + filevar);
                newlogger.WriteLine("Total execution time: " + estimatedTime + "ms" + "\n");
                newlogger.WriteLine("Variables values have been writen to file " + filevar + "\n");
                population.PrintVariablesToFile(filevar);
                logger.Info("Objectives values have been writen to file " + filefun);
                population.PrintObjectivesToFile(filefun);
                Console.WriteLine("Time: " + estimatedTime);
                newlogger.WriteLine("Time: " + estimatedTime + "\n");
                Console.ReadLine();
                if (indicators != null)
                {
                    logger.Info("Quality indicators");
                    logger.Info("Hypervolume: " + indicators.GetHypervolume(population));
                    logger.Info("GD         : " + indicators.GetGD(population));
                    logger.Info("IGD        : " + indicators.GetIGD(population));
                    logger.Info("Spread     : " + indicators.GetSpread(population));
                    logger.Info("Epsilon    : " + indicators.GetEpsilon(population));

                    newlogger.WriteLine("Quality indicators");
                    newlogger.WriteLine("Hypervolume: " + indicators.GetHypervolume(population).ToString("F18") + "\n");
                    newlogger.WriteLine("GD         : " + indicators.GetGD(population).ToString("F18") + "\n");
                    newlogger.WriteLine("IGD        : " + indicators.GetIGD(population).ToString("F18") + "\n");
                    newlogger.WriteLine("Spread     : " + indicators.GetSpread(population).ToString("F18") + "\n");
                    newlogger.WriteLine("Epsilon    : " + indicators.GetEpsilon(population).ToString("F18") + "\n");

                    int evaluations = (int)algorithm.GetOutputParameter("evaluations");
                    logger.Info("Speed      : " + evaluations + "     evaluations");
                    newlogger.WriteLine("Speed      : " + evaluations + "     evaluations" + "\n");
                }
                newlogger.Close();
                file.Close();
                algorithm.AddOperator("mutation", mutation);
            }
        }
        /// <summary>
        /// Usage: three options
        ///     - NSGAIIAdaptive
        ///     - NSGAIIAdaptive problemName
        ///     - NSGAIIAdaptive problemName paretoFrontFile
        /// </summary>
        /// <param name="args">Command line arguments.</param>
        public static void Main(string[] args)
        {
            Problem   problem;                      // The problem to solve
            Algorithm algorithm;                    // The algorithm to use
            Operator  selection;                    // Selection operator

            Dictionary <string, object> parameters; // Operator parameters

            QualityIndicator indicators;            // Object to get quality indicators

            // Logger object and file to store log messages
            var logger = Logger.Log;

            var appenders    = logger.Logger.Repository.GetAppenders();
            var fileAppender = appenders[0] as log4net.Appender.FileAppender;

            fileAppender.File = "NSGAIIAdaptive.log";
            fileAppender.ActivateOptions();

            indicators = null;
            if (args.Length == 1)
            {
                object[] param = { "Real" };
                problem = ProblemFactory.GetProblem(args[0], param);
            }
            else if (args.Length == 2)
            {
                object[] param = { "Real" };
                problem    = ProblemFactory.GetProblem(args[0], param);
                indicators = new QualityIndicator(problem, args[1]);
            }
            else
            {             // Default problem
                problem = new Kursawe("Real", 3);
                //problem = new Kursawe("BinaryReal", 3);
                //problem = new Water("Real");
                //problem = new ZDT1("ArrayReal", 100);
                //problem = new ConstrEx("Real");
                //problem = new DTLZ1("Real");
                //problem = new OKA2("Real") ;
            }
            problem   = new LZ09_F3("Real");
            algorithm = new JMetalCSharp.Metaheuristics.NSGAII.NSGAIIAdaptive(problem);
            //algorithm = new ssNSGAIIAdaptive(problem);

            // Algorithm parameters
            algorithm.SetInputParameter("populationSize", 100);
            algorithm.SetInputParameter("maxEvaluations", 150000);

            // Selection Operator
            parameters = null;
            selection  = SelectionFactory.GetSelectionOperator("BinaryTournament2", parameters);

            // Add the operators to the algorithm
            algorithm.AddOperator("selection", selection);

            // Add the indicator object to the algorithm
            algorithm.SetInputParameter("indicators", indicators);

            Offspring[] getOffspring = new Offspring[3];
            double      CR, F;

            CR = 1.0;
            F  = 0.5;
            getOffspring[0] = new DifferentialEvolutionOffspring(CR, F);

            getOffspring[1] = new SBXCrossoverOffspring(1.0, 20);
            //getOffspring[1] = new BLXAlphaCrossoverOffspring(1.0, 0.5);

            getOffspring[2] = new PolynomialMutationOffspring(1.0 / problem.NumberOfVariables, 20);
            //getOffspring[2] = new NonUniformMutationOffspring(1.0/problem.getNumberOfVariables(), 0.5, 150000);

            algorithm.SetInputParameter("offspringsCreators", getOffspring);

            // Execute the Algorithm
            long        initTime      = Environment.TickCount;
            SolutionSet population    = algorithm.Execute();
            long        estimatedTime = Environment.TickCount - initTime;

            // Result messages
            logger.Info("Total execution time: " + estimatedTime + "ms");
            logger.Info("Variables values have been writen to file VAR");
            population.PrintVariablesToFile("VAR");
            logger.Info("Objectives values have been writen to file FUN");
            population.PrintObjectivesToFile("FUN");

            Console.WriteLine("Time: " + estimatedTime);
            Console.ReadLine();
            if (indicators != null)
            {
                logger.Info("Quality indicators");
                logger.Info("Hypervolume: " + indicators.GetHypervolume(population));
                logger.Info("GD         : " + indicators.GetGD(population));
                logger.Info("IGD        : " + indicators.GetIGD(population));
                logger.Info("Spread     : " + indicators.GetSpread(population));
                logger.Info("Epsilon    : " + indicators.GetEpsilon(population));
            }
        }
Ejemplo n.º 8
0
        /// <summary>
        ///Usage: three choices
        ///     - GDE3
        ///     - GDE3 problemName
        ///     - GDE3 problemName paretoFrontFile
        /// </summary>
        /// <param name="args">Command line arguments.</param>
        public static void Main(string[] args)
        {
            Problem   problem;           // The problem to solve
            Algorithm algorithm;         // The algorithm to use
            Operator  selection;
            Operator  crossover;

            Dictionary <string, object> parameters;  // Operator parameters

            QualityIndicator indicators;             // Object to get quality indicators

            // Logger object and file to store log messages
            var logger = Logger.Log;

            var appenders    = logger.Logger.Repository.GetAppenders();
            var fileAppender = appenders[0] as log4net.Appender.FileAppender;

            fileAppender.File = "GDE3.log";
            fileAppender.ActivateOptions();

            indicators = null;
            if (args.Length == 1)
            {
                object[] param = { "Real" };
                problem = ProblemFactory.GetProblem(args[0], param);
            }
            else if (args.Length == 2)
            {
                object[] param = { "Real" };
                problem    = ProblemFactory.GetProblem(args[0], param);
                indicators = new QualityIndicator(problem, args[1]);
            }
            else
            {             // Default problem
                problem = new Kursawe("Real", 3);
                //problem = new Water("Real");
                //problem = new ZDT1("ArrayReal", 100);
                //problem = new ConstrEx("Real");
                //problem = new DTLZ1("Real");
                //problem = new OKA2("Real") ;
            }

            algorithm = new JMetalCSharp.Metaheuristics.GDE3.GDE3(problem);

            // Algorithm parameters
            algorithm.SetInputParameter("populationSize", 100);
            algorithm.SetInputParameter("maxIterations", 250);

            // Crossover operator
            parameters = new Dictionary <string, object>();
            parameters.Add("CR", 0.5);
            parameters.Add("F", 0.5);
            crossover = CrossoverFactory.GetCrossoverOperator("DifferentialEvolutionCrossover", parameters);

            // Add the operators to the algorithm
            parameters = null;
            selection  = SelectionFactory.GetSelectionOperator("DifferentialEvolutionSelection", parameters);

            algorithm.AddOperator("crossover", crossover);
            algorithm.AddOperator("selection", selection);

            // Execute the Algorithm
            long        initTime      = Environment.TickCount;
            SolutionSet population    = algorithm.Execute();
            long        estimatedTime = Environment.TickCount - initTime;

            // Result messages
            logger.Info("Total execution time: " + estimatedTime + "ms");
            logger.Info("Objectives values have been writen to file FUN");
            population.PrintObjectivesToFile("FUN");
            logger.Info("Variables values have been writen to file VAR");
            population.PrintVariablesToFile("VAR");

            if (indicators != null)
            {
                logger.Info("Quality indicators");
                logger.Info("Hypervolume: " + indicators.GetHypervolume(population));
                logger.Info("GD         : " + indicators.GetGD(population));
                logger.Info("IGD        : " + indicators.GetIGD(population));
                logger.Info("Spread     : " + indicators.GetSpread(population));
                logger.Info("Epsilon    : " + indicators.GetEpsilon(population));
            }

            Console.WriteLine("Total execution time gde: moead" + estimatedTime + "ms");
            Console.ReadLine();
        }
        /// <summary>
        /// Usage: three options
        ///      - PMOEAD
        ///      - PMOEAD problemName
        ///      - PMOEAD problemName ParetoFrontFile
        ///      - PMOEAD problemName numberOfThreads dataDirectory
        /// </summary>
        /// <param name="args">Command line arguments. The first (optional) argument specifies the problem to solve.</param>
        public static void Main(string[] args)
        {
            Problem   problem;                      // The problem to solve
            Algorithm algorithm;                    // The algorithm to use
            Operator  crossover;                    // Crossover operator
            Operator  mutation;                     // Mutation operator

            QualityIndicator indicators;            // Object to get quality indicators

            Dictionary <string, object> parameters; // Operator parameters

            int    numberOfThreads = 4;
            string dataDirectory   = "";

            // Logger object and file to store log messages
            var logger = Logger.Log;

            var appenders    = logger.Logger.Repository.GetAppenders();
            var fileAppender = appenders[0] as log4net.Appender.FileAppender;

            fileAppender.File = "PMOEAD.log";
            fileAppender.ActivateOptions();

            indicators = null;
            if (args.Length == 1)
            {             // args[0] = problem name
                object[] paramsList = { "Real" };
                problem = ProblemFactory.GetProblem(args[0], paramsList);
            }
            else if (args.Length == 2)
            {             // args[0] = problem name, [1] = pareto front file
                object[] paramsList = { "Real" };
                problem    = ProblemFactory.GetProblem(args[0], paramsList);
                indicators = new QualityIndicator(problem, args[1]);
            }
            else if (args.Length == 3)
            {             // args[0] = problem name, [1] = threads, [2] = data directory
                object[] paramsList = { "Real" };
                problem         = ProblemFactory.GetProblem(args[0], paramsList);
                numberOfThreads = int.Parse(args[1]);
                dataDirectory   = args[2];
            }
            else
            {             // Problem + number of threads + data directory
                problem = new Kursawe("Real", 3);
                //problem = new Kursawe("BinaryReal", 3);
                //problem = new Water("Real");
                //problem = new ZDT1("ArrayReal", 100);
                //problem = new ConstrEx("Real");
                //problem = new DTLZ1("Real");
                //problem = new OKA2("Real") ;
            }

            algorithm = new JMetalCSharp.Metaheuristics.MOEAD.PMOEAD(problem);

            // Algorithm parameters
            algorithm.SetInputParameter("populationSize", 300);
            algorithm.SetInputParameter("maxEvaluations", 150000);
            algorithm.SetInputParameter("numberOfThreads", numberOfThreads);

            // Directory with the files containing the weight vectors used in
            // Q. Zhang,  W. Liu,  and H Li, The Performance of a New Version of MOEA/D
            // on CEC09 Unconstrained MOP Test Instances Working Report CES-491, School
            // of CS & EE, University of Essex, 02/2009.
            // http://dces.essex.ac.uk/staff/qzhang/MOEAcompetition/CEC09final/code/ZhangMOEADcode/moead0305.rar
            algorithm.SetInputParameter("dataDirectory", "Data/Parameters/Weight");

            algorithm.SetInputParameter("T", 20);
            algorithm.SetInputParameter("delta", 0.9);
            algorithm.SetInputParameter("nr", 2);

            // Crossover operator
            parameters = new Dictionary <string, object>();
            parameters.Add("CR", 1.0);
            parameters.Add("F", 0.5);
            crossover = CrossoverFactory.GetCrossoverOperator("DifferentialEvolutionCrossover", parameters);

            // Mutation operator
            parameters = new Dictionary <string, object>();
            parameters.Add("probability", 1.0 / problem.NumberOfVariables);
            parameters.Add("distributionIndex", 20.0);
            mutation = MutationFactory.GetMutationOperator("PolynomialMutation", parameters);

            algorithm.AddOperator("crossover", crossover);
            algorithm.AddOperator("mutation", mutation);

            // Execute the Algorithm
            long        initTime      = Environment.TickCount;
            SolutionSet population    = algorithm.Execute();
            long        estimatedTime = Environment.TickCount - initTime;

            // Result messages
            logger.Info("Total execution time: " + estimatedTime + " ms");
            logger.Info("Objectives values have been writen to file FUN");
            population.PrintObjectivesToFile("FUN");
            logger.Info("Variables values have been writen to file VAR");
            population.PrintVariablesToFile("VAR");
            Console.ReadLine();

            if (indicators != null)
            {
                logger.Info("Quality indicators");
                logger.Info("Hypervolume: " + indicators.GetHypervolume(population));
                logger.Info("GD         : " + indicators.GetGD(population));
                logger.Info("IGD        : " + indicators.GetIGD(population));
                logger.Info("Spread     : " + indicators.GetSpread(population));
            }
        }