Beispiel #1
0
        static MediaFactory CreateDiskFactory(bool changable = false)
        {
            MusicTrack[] tracks = new MusicTrack[]
            {
                new MusicTrack("Music Track 1", "Noone", new byte[1]),
                new MusicTrack("Music Track 2", "Someone", new byte[1]),
                new MusicTrack("Music Track 3", "Noone", new byte[1])
            };

            Photo[] photoes = new Photo[]
            {
                new Photo("Photo 1", "Some author", new System.Drawing.Bitmap(1, 1)),
                new Photo("Photo 2", "No author", new System.Drawing.Bitmap(1, 1)),
                new PhotoReference("Photo 3", "Some author", new Uri("file:///nothing.bmp"))
            };

            MediaFactory factory;

            if (changable)
            {
                factory = new SelectionFactory(tracks, photoes);
            }
            else
            {
                factory = new DiskFactory(tracks, photoes);
            }
            return(factory);
        }
        public static int RunGAMapFinder(GAFinderOption option)
        {
            var map = _loadMap(option.MapFileName, option.Diagonal);

            if (map == null)
            {
                return(1);
            }


            var heuristic = (new HeuristicFactory()).GetImplementation(option.Heuristic);

            var mutate    = new MutateFactory().GetImplementation(option.Mutate);
            var crossover = new CrossoverFactory().GetImplementation(option.Crossover);
            var selection = new SelectionFactory().GetImplementation(option.Selection);
            var fitness   = new FitnessFactory().GetImplementation(option.Fitness);

            fitness.Heuristic = heuristic;

            var finder = FinderFactory.GetGAImplementation(
                crossover,
                mutate,
                fitness,
                selection,
                option.Population,
                option.GenerationLimit,
                option.BestToPick
                );



            return(_runFinder(finder, heuristic, map, option.Window, option.NoShowSteps, option.BlockSize, option.UISleep));
        }
        /// <summary>
        /// Constructor
        /// </summary>
        /// <param name="CR"></param>
        /// <param name="F"></param>
        public DifferentialEvolutionOffspring(double CR, double F)
        {
            Dictionary <string, object> parameters = null;

            this.CR = CR;
            this.F  = F;
            try
            {
                // Crossover operator
                parameters = new Dictionary <string, object>();
                parameters.Add("CR", CR);
                parameters.Add("F", F);
                crossover = new DifferentialEvolutionCrossover(parameters);

                // Selecion operator
                parameters = null;
                selection  = SelectionFactory.GetSelectionOperator("DifferentialEvolutionSelection", parameters);
            }
            catch (Exception ex)
            {
                Logger.Log.Error("Exception in " + this.GetType().FullName + ".Execute()", ex);
                Console.Error.WriteLine("Error in: " + this.GetType().FullName + "\r\n" + ex.StackTrace);
            }
            Id = "DE";
        }
        public PolynomialMutationOffspring(double mutationProbability, double distributionIndexForMutation)
        {
            Dictionary <string, object> parameters;            // Operator parameters

            parameters = new Dictionary <string, object>();
            parameters.Add("probability", this.mutationProbability     = mutationProbability);
            parameters.Add("distributionIndex", this.distributionIndex = distributionIndexForMutation);
            mutation = MutationFactory.GetMutationOperator("PolynomialMutation", parameters);

            selection = SelectionFactory.GetSelectionOperator("BinaryTournament", null);
            Id        = "PolynomialMutation";
        }
 private void Register()
 {
     SelectionFactory.Register("roulette", () => new RouletteSelection());
     CrossoverOperatorFactory.Register("OX", () => new OrderCrossover());
     CrossoverOperatorFactory.Register("CX", () => new CycleCrossover());
     CrossoverOperatorFactory.Register("PMX", () => new PartiallyMatchedCrossover());
     CrossoverOperatorFactory.Register("UOX", () => new UniformBasedOrderCrossover());
     MutationOperatorFactory.Register("swap", () => new SwapOperator());
     MutationOperatorFactory.Register("insertion", () => new InsertionOperator());
     MutationOperatorFactory.Register("inversion", () => new InversionOperator());
     MutationOperatorFactory.Register("displacement", () => new DisplacementOperator());
     HeuristicsFactory.Register("SA", () => new SimulatedAnnealing());
 }
        public void RegisterAlgorithm(string problemName, ParametersWebsite webParameters)
        {
            string       filePath = HttpContext.Current.Server.MapPath("~/Data/Homberger/" + problemName.ToUpper() + @".txt");
            VrptwProblem problem  = new VrptwProblemReader().ReadFromFile(filePath);

            string connecionId = Context.ConnectionId;

            Register();
            MemeticAlgorithm ma;

            if (algorithms.ContainsKey(connecionId))
            {
                ma = algorithms[connecionId];
                ma.Stop();
            }
            else
            {
                ma = new MemeticAlgorithm();
            }
            Parameters parameters = new Parameters
            {
                Heuristics           = HeuristicsFactory.Create(webParameters.Heuristics),
                PopulationSize       = webParameters.PopulationSize,
                Selection            = SelectionFactory.Create(webParameters.Selection),
                CrossoverOperators   = new List <CrossoverOperator>(),
                MutationOperators    = new List <MutationOperator>(),
                CrossoverProbability = webParameters.CrossoverProbability,
                MutationProbability  = webParameters.MutationProbability,
                Fitness                    = new FitnessFunction(webParameters.FitnessRoutes, webParameters.FitnesDistance),
                EliteChildrenCount         = webParameters.EliteChildrenCount,
                GeneCount                  = problem.Customers.Count,
                FitnessStrategy            = FitnessStrategy.MINIMIZE,
                ConvergenceLimit           = webParameters.ConvergenceLimit,
                PreservedChromosomesNumber = webParameters.PreservedChromosomeNumber,
                MaxIterations              = webParameters.Iterations,
                ChromosomeFactory          = new SolutionFactory(),
                HeuristicsParameters       = webParameters.HeuristicsParameters
            };

            parameters.CrossoverOperators.Add(CrossoverOperatorFactory.Create(webParameters.Crossover));
            parameters.MutationOperators.Add(MutationOperatorFactory.Create(webParameters.Mutation));
            algorithms.TryAdd(connecionId, ma);
            var    result         = ma.Run(problem, parameters, UpdateSolution, connecionId);
            var    solution       = result.Result as Solution;
            string outputPath     = HttpContext.Current.Server.MapPath("~/Results/Memetic");
            string outputFilePath = outputPath + @"/" + problem.Name + ".txt";

            File.WriteAllText(outputFilePath, solution.ToFileText());
        }
Beispiel #7
0
        public Operator GetSelection()
        {
            Dictionary <string, object> parameters = new Dictionary <string, object>();

            switch (s)
            {
            case "BinaryTournament2":
                parameters = null;
                selection  = SelectionFactory.GetSelectionOperator("BinaryTournament2", parameters);
                break;

            default:
                break;
            }

            return(selection);
        }
Beispiel #8
0
        public GeneticAlgorithm(
            int mutatorValue,
            int generationCount,
            int populationSize,
            CrossoverType crossoverType,
            SelectionType selectionType,
            List <City> cities)
        {
            this.mutationProbability = 1.0 / (TourManager.Cities.Count * mutatorValue);
            this.generationCount     = generationCount;
            this.populationSize      = populationSize;

            this.crossover = CrossoverFactory.Get(crossoverType);
            this.selection = SelectionFactory.Get(selectionType);

            TourManager.Cities = cities;
            this.distances     = Distance.Calculate(TourManager.Cities);
        }
        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";
        }
        /// <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
        ///     - 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();
        }
        /// <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));
            }
        }
Beispiel #14
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  }));
        }
Beispiel #15
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();
        }