示例#1
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  }));
        }
示例#2
0
    public void RunSimulation(object sender, EventArgs e)
    {
        var options = CreateAlgorithmOptions();

        var problem = new ConfigurationProblem();

        var algorithm = new NSGAII(problem);

        algorithm.SetInputParameter("populationSize", options.NumberOfCromozoms);
        algorithm.SetInputParameter("maxEvaluations", options.NumberOfCromozoms * options.NumberOfGenerations);

        // Mutation and Crossover for Real codification
        var parameters = new Dictionary <string, object>();

        parameters.Add(ConfigurationCrossOver.CrossOverPercentageKey, options.CrossOverPercentage);
        var crossover = new ConfigurationCrossOver(parameters);          // Nobody cares about the factory

        parameters = new Dictionary <string, object>();
        parameters.Add(ConfigurationMutation.MutationPercentageKey, options.MutationPercentage);
        var mutation = new ConfigurationMutation(parameters);          // Nobody cares about the factory.

        // Selection Operator
        parameters = null;
        var selection = new BinaryTournament2(parameters);          // Nobody cares about the factory.

        // 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
        // nope
        //algorithm.SetInputParameter("indicators", null);

        var solution = algorithm.Execute();

        var solutionsList = solution.SolutionsList;

        var output = "";

        using (var writer = new System.IO.StreamWriter("output.txt")) {
            foreach (var sol in solutionsList)
            {
                var line = sol.Objective [0] + "\t" + sol.Objective [1];
                output += line;
                output += "\n";
                writer.WriteLine(line);
            }

            output += "\n";
            output += "\n";
            writer.WriteLine();
            writer.WriteLine();

            var rank = new Ranking(solution);
            var n    = rank.GetNumberOfSubfronts();
            for (var i = 0; i < n; i++)
            {
                var f = rank.GetSubfront(i);
                foreach (var sol in f.SolutionsList)
                {
                    var line = sol.Objective [0] + "\t" + sol.Objective [1];
                    output += line;
                    output += "\n";
                    writer.WriteLine(line);
                }

                output += "\n";
                output += "\n";
                writer.WriteLine();
                writer.WriteLine();
            }
        }

        resultsText.Buffer.Clear();
        resultsText.Buffer.Text = output;
    }