public SBXCrossoverOffspring(double crossoverProbability, double distributionIndexForCrossover)
        {
            Dictionary <string, object> parameters;

            this.crossoverProbability          = crossoverProbability;
            this.distributionIndexForCrossover = distributionIndexForCrossover;

            // Crossover operator
            parameters = new Dictionary <string, object>();
            parameters.Add("probability", crossoverProbability);
            parameters.Add("distributionIndex", distributionIndexForCrossover);

            crossover = CrossoverFactory.GetCrossoverOperator("SBXCrossover", parameters);

            selection = SelectionFactory.GetSelectionOperator("BinaryTournament", null);

            Id = "SBXCrossover";
        }
Exemplo n.º 2
0
        public Operator GetCrossover2()
        {
            string filepath = DirPath + "/Parameter.txt";

            Dictionary <string, object> parameters = new Dictionary <string, object>();

            string[] line7 = { Co + " " + Ra, Co2 + " " + (1 - double.Parse(Ra)) };
            string[] line8 = { "gamma " + Gamma };
            File.AppendAllLines(filepath, line7);
            File.AppendAllLines(filepath, line8);

            switch (Co2)
            {
            case "SBXCrossover":
                parameters.Add("probability", double.Parse(poc));
                parameters.Add("distributionIndex", double.Parse(dioc));
                crossover2 = CrossoverFactory.GetCrossoverOperator("SBXCrossover", parameters);
                break;

            case "DifferentialEvolutionCrossover":
                parameters.Add("CR", double.Parse(cr));
                parameters.Add("F", double.Parse(f));
                parameters.Add("K", double.Parse(k));
                crossover2 = CrossoverFactory.GetCrossoverOperator("DifferentialEvolutionCrossover", parameters);
                break;

            case "ACOR":
                parameters.Add("zeta", double.Parse(zeta));
                crossover2 = CrossoverFactory.GetCrossoverOperator("ACOR", parameters);
                break;

            case null:
                parameters.Add("probability", double.Parse(poc));
                parameters.Add("distributionIndex", double.Parse(dioc));
                parameters.Add("zeta", double.Parse(zeta));
                crossover2 = CrossoverFactory.GetCrossoverOperator("null", parameters);
                break;

            default:
                break;
            }

            return(crossover2);
        }
Exemplo n.º 3
0
        public Operator[] GetCrossover()
        {
            string filepath = DirPath + "/Parameter.txt";

            string[] line6 = { "ACOR " + ACORa, "SBXCrossover " + SBXRa, "DECrossover " + DERa };
            string[] line3 = { "probabilityOfCrossover " + poc, "distributionIndexOfCrossover " + dioc };
            string[] line4 = { "CR " + cr, "F " + f, "K " + k };
            string[] line5 = { "zeta " + zeta, "q " + q };

            Dictionary <string, object> parameters = new Dictionary <string, object>();

            parameters.Add("probability", double.Parse(poc));
            parameters.Add("distributionIndex", double.Parse(dioc));
            crossover[1] = CrossoverFactory.GetCrossoverOperator("SBXCrossover", parameters);

            parameters = new Dictionary <string, object>();
            parameters.Add("CR", double.Parse(cr));
            parameters.Add("F", double.Parse(f));
            parameters.Add("K", double.Parse(k));
            crossover[0] = CrossoverFactory.GetCrossoverOperator("DifferentialEvolutionCrossover", parameters);

            parameters = new Dictionary <string, object>();
            parameters.Add("zeta", double.Parse(zeta));
            crossover[2] = CrossoverFactory.GetCrossoverOperator("ACOR", parameters);

            File.AppendAllLines(filepath, line6);
            if (DERa != "0.0")
            {
                File.AppendAllLines(filepath, line4);
            }
            if (SBXRa != "0.0")
            {
                File.AppendAllLines(filepath, line3);
            }
            if (ACORa != "0.0")
            {
                File.AppendAllLines(filepath, line5);
            }

            return(crossover);
        }
        /// <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 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: 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");
            }
        }
        /// <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();
        }
Exemplo n.º 8
0
        public Operator GetCrossover()
        {
            if (Co2 != "")
            {
                DirPath = "Result/" + Al + "_" + Co + "_" + Co2 + "/" + Pb + "_" + St;
            }
            else
            {
                DirPath = "Result/" + Al + "_" + Co + "/" + Pb + "_" + St;
            }
            if (Directory.Exists(DirPath))
            {
                Console.WriteLine("The directory {0} already exists.", DirPath);
            }
            else
            {
                Directory.CreateDirectory(DirPath);
                Console.WriteLine("The directory {0} was created.", DirPath);
            }

            string filepath = DirPath + "/Parameter.txt";

            string[] line3 = { "probabilityOfCrossover " + poc, "distributionIndexOfCrossover " + dioc };
            string[] line4 = { "CR " + cr, "F " + f, "K " + k };
            string[] line5 = { "zeta " + zeta, "q " + q };

            Dictionary <string, object> parameters = new Dictionary <string, object>();

            switch (Co)
            {
            case "SBXCrossover":
                parameters.Add("probability", double.Parse(poc));
                parameters.Add("distributionIndex", double.Parse(dioc));
                crossover = CrossoverFactory.GetCrossoverOperator("SBXCrossover", parameters);
                File.AppendAllLines(filepath, line3);
                break;

            case "DifferentialEvolutionCrossover":
                parameters.Add("CR", double.Parse(cr));
                parameters.Add("F", double.Parse(f));
                parameters.Add("K", double.Parse(k));
                crossover = CrossoverFactory.GetCrossoverOperator("DifferentialEvolutionCrossover", parameters);
                File.AppendAllLines(filepath, line4);
                break;

            case "ACOR":
                parameters.Add("zeta", double.Parse(zeta));
                crossover = CrossoverFactory.GetCrossoverOperator("ACOR", parameters);
                File.AppendAllLines(filepath, line5);
                break;

            case null:
                parameters.Add("probability", double.Parse(poc));
                parameters.Add("distributionIndex", double.Parse(dioc));
                parameters.Add("zeta", double.Parse(zeta));
                crossover = CrossoverFactory.GetCrossoverOperator("null", parameters);
                File.AppendAllLines(filepath, line3);
                File.AppendAllLines(filepath, line5);
                break;

            default:
                break;
            }

            return(crossover);
        }
Exemplo n.º 9
0
        static void Main()
        {
            Application.EnableVisualStyles();
            Application.SetCompatibleTextRenderingDefault(false);

            Application.Run(new LoadConfig());

            // VariabilityModel model = new VariabilityModel("Model1");
            //  InfluenceModel infModel = new InfluenceModel(model, new NFProperty("Test"));

            //  BettyFileParser bfp = new BettyFileParser(model, infModel);

            String[] file = System.IO.File.ReadAllLines(@"C:\Users\Tom\Desktop\Masterarbeit\SPLConqueror\SPLConqueror\BettyConqueror\FeatureModel0.afm");

            //  bfp.readConfiguration(file);
            //ILArray<float> A = ILMath.tosingle()
            //ILArray<float> A = ILMath.tosingle(ILMath.rand(3, 100));


            // RDotNet.NativeLibrary.UnmanagedDll.SetDllDirectory(@"C:\Program Files\R\R-3.2.0\bin\i386\R.dll");


            engine = REngine.GetInstance();

            NumericVector group1 = engine.CreateNumericVector(new double[] { 30.02, 29.99, 30.11, 29.97, 30.01, 29.99 });

            engine.SetSymbol("group1", group1);

            // e.Evaluate("hist(group1)");
            // e.Evaluate("hist(group1)");

            Problem  problem;
            Operator crossover; // Crossover operator
            Operator mutation;  // Mutation operator
            Operator selection; // Selection operator

            var logger = Logger.Log;

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

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

            QualityIndicator indicators;            // Object to get quality indicators

            problem = new GeneratorProblem("Real", 30);


            NSGAII algorithm = new NSGAII(problem);

            indicators = null;

            algorithm.SetInputParameter("populationSize", 200);
            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("BinaryTournament2", 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;

            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();
            //Application.Run(new Form1(e, group1, new double[] { 30.02, 29.99, 30.11, 29.97, 30.01, 29.99, 1.3, 1.7, 9.4, 11.1  }));
        }
Exemplo n.º 10
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));
            }
        }