public async Task Classify()
        {
            var         problemFactory = new ProblemFactory(threeClassDataset);
            SvmTraining training       = new SvmTraining(problemFactory, threeClassDataset);
            var         parameters     = training.SelectParameters(TrainingHeader.CreateDefault(), CancellationToken.None);
            var         results        = await training.Train(parameters).ConfigureAwait(false);

            results.Model.Write(Path.Combine(TestContext.CurrentContext.TestDirectory, "classify.dat"));
            var testSet = ArffDataSet.Create <PositivityType>("Test");

            testSet.UseTotal = true;

            var positive = testSet.AddDocument();

            positive.AddRecord("Good");

            var negative = testSet.AddDocument();

            negative.AddRecord("Bad");

            SvmTesting testing = new SvmTesting(results.Model, problemFactory);

            testing.Classify(testSet);
            Assert.AreEqual(PositivityType.Positive, positive.Class.Value);
            Assert.AreEqual(PositivityType.Negative, negative.Class.Value);
        }
示例#2
0
        /// <summary>
        /// This is the main program.
        /// </summary>
        ///
        static void Main()
        {
            int problemNumber;

            // ProblemFactory problemFactory = new ProblemFactory();
            totalTime = new Stopwatch();

            problemNumber = GetUserInput();

            while (problemNumber > 0)
            {
                totalTime.Reset();
                totalTime.Start();
                string result = ProblemFactory.GetSolution(problemNumber).Compute();
                totalTime.Stop();

                Console.WriteLine("\n-----------------------------------------------------------------------");
                Console.WriteLine("Solution to problem " + problemNumber + " = " + result);
                Console.WriteLine("Execution time was " + Utilities.FormatMilliseconds(totalTime.ElapsedMilliseconds));
                Console.WriteLine("-----------------------------------------------------------------------");
                Console.WriteLine();
                problemNumber = GetUserInput();
            }

            Console.WriteLine("Goodbye. Press any key to continue");
            Console.ReadKey();
        }
示例#3
0
        public async Task <ActionResult> Query([FromQuery] BlueprintQueryParameters queryParameters)
        {
            if (queryParameters == null)
            {
                return(this.Problem(ProblemFactory.BadParameters()));
            }

            var blueprintQuery = new BlueprintsQuery
            {
                MaxProductionEfford = queryParameters.MaxProductionEfford,
                NameContains        = queryParameters.ModelName
            };

            var result = await CommandHandler.Query(blueprintQuery);

            return(result.Match(
                       success =>
            {
                var resultHto = Ok(new BlueprintQueryResultHto(success.Result, queryParameters));
                return resultHto;
            },
                       notReachable => this.Problem(ProblemFactory.ServiceUnavailable()),
                       invalidQuery => this.Problem(ProblemFactory.BadParameters()),
                       error => this.Problem(ProblemFactory.Exception(error.Exception))
                       ));
        }
示例#4
0
文件: GUI.cs 项目: hergin/SortingOOP
 public GUI(SortAlgorithm s)
 {
     theProblem   = ProblemFactory.createActualProblem();
     theAlgorithm = s;
     InitializeComponent();
     initializeGUI();
 }
        public void Setup()
        {
            dataSet = ArffDataSet.CreateSimple("Test");
            dataSet.Header.RegisterNominalClass("One");
            var problemFactory = new ProblemFactory(dataSet);

            factory = new ParametersSelectionFactory(Task.Factory, problemFactory);
        }
示例#6
0
        public async Task <ActionResult> GetProductionLines()
        {
            var getAllResult = await CommandHandler.GetAllProductionLines();

            return(getAllResult.Match(
                       success => Ok(new ProductionHto(success.Result)),
                       notReachable => this.Problem(ProblemFactory.ServiceUnavailable()),
                       error => this.Problem(ProblemFactory.Exception(error.Exception))));
        }
示例#7
0
        public void LessThan6NumbersThrowsError()
        {
            var p       = new ConstantNumberProvider();
            var factory = new ProblemFactory(p);

            Assert.Throws <ArgumentException>(() =>
            {
                var problem = factory.Create();
            });
        }
示例#8
0
文件: GUI.cs 项目: hergin/SortingOOP
 private void toolStripMenuItem7_Click(object sender, EventArgs e)
 {
     clearOldStuff();
     theProblem = ProblemFactory.createTestProblem();
     if (problemChangedListener != null)
     {
         problemChangedListener.onProblemChanged(theProblem.getDataForAlgorithm());
     }
     initializeGUI();
 }
示例#9
0
文件: GUI.cs 项目: hergin/SortingOOP
 private void gradingProblemMenuClicked(object sender, EventArgs e)
 {
     clearOldStuff();
     theProblem = ProblemFactory.createGradingProblem();
     if (problemChangedListener != null)
     {
         problemChangedListener.onProblemChanged(theProblem.getDataForAlgorithm());
     }
     initializeGUI();
 }
示例#10
0
        static void Main(string[] args)
        {
            Console.WriteLine(
                ProblemFactory.Create(ProblemId.Day25A)
                .SendToClipboard()
                .AppendTime()
                .Solve());

            Console.ReadKey();
        }
    static void Main(string[] args)
    {
        ProblemFactory           problemFactory    = new ProblemFactory();
        BinaryLevelConfiguration binaryLevelConfig = new BinaryLevelConfiguration();

        // register your factory functions
        problemFactory.RegisterProblem <BinaryProblem>((level) => new BinaryProblem(binaryLevelConfig.GetProblemConfiguration(level)));
        // consume them
        IProblem problem1 = problemFactory.GenerateProblem <BinaryProblem>(Level.Easy);
        IProblem problem2 = problemFactory.GenerateProblem <BinaryProblem>(Level.Hard);
    }
        private Problem LoadData(bool withScaling = false)
        {
            var             file    = Path.Combine(TestContext.CurrentContext.TestDirectory, @".\Data\data.arff");
            var             arff    = ArffDataSet.Load <PositivityType>(file);
            IProblemFactory factory = new ProblemFactory(arff);

            if (withScaling)
            {
                factory = factory.WithRangeScaling();
            }

            return(factory.Construct(arff).GetProblem());
        }
        public void Execute()
        {
            ProblemFactory.Execute <Day01A>();
            ProblemFactory.Execute <Day01B>();

            ProblemFactory.Execute <Day02A>();
            ProblemFactory.Execute <Day02B>();

            ProblemFactory.Execute <Day03A>();
            ProblemFactory.Execute <Day03B>();

            ProblemFactory.Execute <Day04A>();
            ProblemFactory.Execute <Day04B>();
        }
示例#14
0
 private void displayNextProblem()
 {
     //get the next problem
     _CurrentProblem = ProblemFactory.GetArithmeticProblem <int>(getNextOperation(), 2, 20, false);
     string[] lines = _CurrentProblem.Display().ToArray();
     if (lines.Length > 0)
     {
         lines[0] = lines.First().Remove(0, 1);                   //remove the first symbol
     }
     ProblemBox.Lines = lines;
     AnswerBox.Text   = string.Empty;
     AnswerBox.Focus();
     _Timer.Restart();
 }
        public async Task TestTwoClass()
        {
            var         problemFactory = new ProblemFactory(twoClassDataset);
            SvmTraining training       = new SvmTraining(problemFactory, twoClassDataset);
            var         parameters     = training.SelectParameters(TrainingHeader.CreateDefault(), CancellationToken.None);
            var         results        = await training.Train(parameters).ConfigureAwait(false);

            var file = Path.Combine(TestContext.CurrentContext.TestDirectory, "data.arff");

            threeClassDataset.Save(file);
            var        testFile = ArffDataSet.LoadSimple(file);
            SvmTesting testing  = new SvmTesting(results.Model, problemFactory);
            var        result   = testing.Test(testFile, Path.Combine(TestContext.CurrentContext.TestDirectory, "."));

            Assert.AreEqual(1, result);
        }
示例#16
0
        public ActionResult NewQuery(BlueprintQueryParameters queryParameters)
        {
            if (queryParameters == null)
            {
                return(this.Problem(ProblemFactory.BadParameters()));
            }

            var canQueryResult = CommandHandler.CanQueryBlueprints();

            return(canQueryResult.Match(
                       // Will create a Location header with a URI to the result.
                       available => this.CreatedQuery(typeof(BlueprintQueryResultHto), queryParameters),
                       notAvailable => this.Problem(ProblemFactory.OperationNotAvailable()),
                       notReachable => this.Problem(ProblemFactory.ServiceUnavailable()),
                       error => this.Problem(ProblemFactory.Exception(error.Exception))
                       ));
        }
        public void Classify(string arff, string modelName, object result)
        {
            var file    = Path.Combine(TestContext.CurrentContext.TestDirectory, "data", arff);
            var dataSet = result.GetType() == typeof(PositivityType)
                              ? ArffDataSet.Load <PositivityType>(file)
                              : ArffDataSet.LoadSimple(file);

            file = Path.Combine(TestContext.CurrentContext.TestDirectory, "data", modelName);
            var model = Model.Read(file);

            IProblemFactory factory = new ProblemFactory(dataSet);
            var             client  = new SvmTesting(model, factory);

            var dataHolder = dataSet.CreateDataSet("Test");
            var review     = dataHolder.AddDocument();

            review.AddRecord("Good").Value = 2;
            review.AddRecord("Bad").Value  = 1;
            client.Classify(dataHolder);
            Assert.AreEqual(result, review.Class.Value);
        }
        public void Setup()
        {
            training = new Mock <ITrainingModel>();
            var scheduler = new ConcurrentExclusiveSchedulerPair(TaskScheduler.Default, 2)
                            .ConcurrentScheduler;

            taskFactory = new TaskFactory(scheduler);
            parameters  = new GridSearchParameters(5, new double[] { 1, 2, 3, 4 }, new double[] { 1, 2, 3, 4 }, new Parameter());
            instance    = new GridParameterSelection(taskFactory, training.Object, parameters);

            var dataSet = ArffDataSet.CreateSimple("Test");

            dataSet.Header.RegisterNominalClass("One", "Two", "Three");
            dataSet.UseTotal = true;
            var one = dataSet.AddDocument();

            one.Class.Value = "One";
            one.AddRecord("Good");
            IProblemFactory factory = new ProblemFactory(dataSet);

            problem    = factory.Construct(dataSet).GetProblem();
            resetEvent = new ManualResetEvent(false);
        }
示例#19
0
        static void Main(string[] args)
        {
            var aProblem = ProblemFactory.Get(ProblemEnmu.Rotate, SizeEnum.Small);

            var fileManger = new FileManager(aProblem.FileName);
            var input      = fileManger.ReadFile();

            var initializer = new ObjectInitializer(aProblem);

            dynamic inputProblems = typeof(ObjectInitializer)
                                    .GetMethod("InitializeObject")
                                    .MakeGenericMethod(aProblem.GetType())
                                    .Invoke(initializer, new object[] { aProblem, input });

            var printSolutions = new List <string>();

            for (var index = 0; index < inputProblems.Cases; index++)
            {
                printSolutions.Add(string.Format("Case #{0}: {1}", (index + 1).ToString(), inputProblems.Problems[index].PrintSolution()));
            }

            fileManger.WriteFile(printSolutions);
        }
        static IEnumerable <Route> ServeRequest(Request request)
        {
            if (!CheckRequest(request))
            {
                return(null);
            }
            (IGraphDatabase cars, IGraphDatabase trains) = MockData.InitDatabases();
            List <IGraphDatabase> databases = new List <IGraphDatabase>();

            databases.Add(cars);
            databases.Add(trains);

            IGraphDatabase database = new VehicleDatabase(databases, request.Filter.AllowedVehicles);

            database = new PopulationDatabase(database, request.Filter.MinPopulation);
            database = new HasRestaurantDatabase(database, request.Filter.RestaurantRequired);

            List <ISolver> solvers = new List <ISolver>();

            solvers.Add(new BFS());
            solvers.Add(new DFS());
            solvers.Add(new DijkstraCost());
            solvers.Add(new DijkstraTime());

            IRouteProblem problem = ProblemFactory.MakeProblem(request.Problem, request.From, request.To);

            problem.Graph = database;
            foreach (ISolver solver in solvers)
            {
                if (solver.Name == request.Solver && problem.TrySolveBySolver(solver, out IEnumerable <Route> routes))
                {
                    return(routes);
                }
            }
            Console.WriteLine("Cannot find algorithm to solve this problem");
            return(null);
        }
        public async Task TestMultiClass()
        {
            var dataSet = ArffDataSet.CreateSimple("Test");

            dataSet.Header.RegisterNominalClass("One", "Two", "Three");
            dataSet.UseTotal = true;
            for (int i = 0; i < 20; i++)
            {
                var one = dataSet.AddDocument();
                one.Class.Value = "One";
                one.AddRecord("Good");

                var two = dataSet.AddDocument();
                two.Class.Value = "Two";
                two.AddRecord("Bad");

                var three = dataSet.AddDocument();
                three.Class.Value = "Three";
                three.AddRecord("Some");
            }

            var         problemFactory = new ProblemFactory(dataSet);
            SvmTraining training       = new SvmTraining(problemFactory, dataSet);
            var         parameters     = training.SelectParameters(TrainingHeader.CreateDefault(), CancellationToken.None);
            var         results        = await training.Train(parameters).ConfigureAwait(false);

            var file = Path.Combine(TestContext.CurrentContext.TestDirectory, "data.arff");

            dataSet.Save(file);
            results.Model.Write(Path.Combine(TestContext.CurrentContext.TestDirectory, "label.dat"));
            var testFile = ArffDataSet.LoadSimple(file);

            SvmTesting testing = new SvmTesting(results.Model, problemFactory);
            var        result  = testing.Test(testFile, Path.Combine(TestContext.CurrentContext.TestDirectory, "."));

            Assert.AreEqual(1, result);
        }
        /// <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
        ///    - 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();
        }
        public void Execute()
        {
            ProblemFactory.Execute <Day01A>();
            ProblemFactory.Execute <Day01B>();

            ProblemFactory.Execute <Day02A>();
            ProblemFactory.Execute <Day02B>();

            ProblemFactory.Execute <Day03A>();
            ProblemFactory.Execute <Day03B>();

            ProblemFactory.Execute <Day04A>();
            ProblemFactory.Execute <Day04B>();

            ProblemFactory.Execute <Day05A>();
            ProblemFactory.Execute <Day05B>();

            ProblemFactory.Execute <Day06A>();
            ProblemFactory.Execute <Day06B>();

            ProblemFactory.Execute <Day07A>();
            ProblemFactory.Execute <Day07B>();

            ProblemFactory.Execute <Day08A>();
            ProblemFactory.Execute <Day08B>();

            ProblemFactory.Execute <Day09A>();
            ProblemFactory.Execute <Day09B>();
            //
            // ProblemFactory.Execute<Day10A>();
            // ProblemFactory.Execute<Day10B>();
            //
            // ProblemFactory.Execute<Day11A>();
            // ProblemFactory.Execute<Day11B>();
            //
            // ProblemFactory.Execute<Day12A>();
            // ProblemFactory.Execute<Day12B>();
            //
            // ProblemFactory.Execute<Day13A>();
            // ProblemFactory.Execute<Day13B>();
            //
            // ProblemFactory.Execute<Day14A>();
            // ProblemFactory.Execute<Day14B>();
            //
            // ProblemFactory.Execute<Day15A>();
            // ProblemFactory.Execute<Day15B>();
            //
            // ProblemFactory.Execute<Day16A>();
            // ProblemFactory.Execute<Day16B>();
            //
            // ProblemFactory.Execute<Day17A>();
            // ProblemFactory.Execute<Day17B>();
            //
            // ProblemFactory.Execute<Day18A>();
            // ProblemFactory.Execute<Day18B>();
            //
            // ProblemFactory.Execute<Day19A>();
            // ProblemFactory.Execute<Day19B>();
            //
            // ProblemFactory.Execute<Day20A>();
            // ProblemFactory.Execute<Day20B>();
            //
            // ProblemFactory.Execute<Day21A>();
            // ProblemFactory.Execute<Day21B>();
            //
            // ProblemFactory.Execute<Day22A>();
            // ProblemFactory.Execute<Day22B>();
            //
            // ProblemFactory.Execute<Day23A>();
            // ProblemFactory.Execute<Day23B>();
            //
            // ProblemFactory.Execute<Day24A>();
            // ProblemFactory.Execute<Day24B>();
            //
            // ProblemFactory.Execute<Day25A>();
        }
示例#25
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
        ///     - 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));
            }
        }
示例#27
0
        static void Main()
        {
            /** /
            *  ProblemFactory.Create<Day1A>()
            *   .SendToClipboard()
            *   .AppendTime()
            *   .Solve()
            *   .ToConsole("Day 1A");
            *
            *  ProblemFactory.Create<Day1B>()
            *   .SendToClipboard()
            *   .AppendTime()
            *   .Solve()
            *   .ToConsole("Day 1B");
            *
            *  ProblemFactory.Create<Day2A>()
            *   .SendToClipboard()
            *   .AppendTime()
            *   .Solve()
            *   .ToConsole("Day 2A");
            *
            *  ProblemFactory.Create<Day2B>()
            *   .SendToClipboard()
            *   .AppendTime()
            *   .Solve()
            *   .ToConsole("Day 2B");
            *
            *  ProblemFactory.Create<Day3A>()
            *   .SendToClipboard()
            *   .AppendTime()
            *   .Solve()
            *   .ToConsole("Day 3A");
            *
            *  ProblemFactory.Create<Day3B>()
            *   .SendToClipboard()
            *   .AppendTime()
            *   .Solve()
            *   .ToConsole("Day 3B");
            *
            *  ProblemFactory.Create<Day4A>()
            *   .SendToClipboard()
            *   .AppendTime()
            *   .Solve()
            *   .ToConsole("Day 4A");
            *
            *  ProblemFactory.Create<Day4B>()
            *   .SendToClipboard()
            *   .AppendTime()
            *   .Solve()
            *   .ToConsole("Day 4B");
            *
            *  ProblemFactory.Create<Day5A>()
            *   .SendToClipboard()
            *   .AppendTime()
            *   .Solve()
            *   .ToConsole("Day 5A");
            *
            *  ProblemFactory.Create<Day5B>()
            *   .SendToClipboard()
            *   .AppendTime()
            *   .Solve()
            *   .ToConsole("Day 5B");
            *
            *  ProblemFactory.Create<Day6A>()
            *   .SendToClipboard()
            *   .AppendTime()
            *   .Solve()
            *   .ToConsole("Day 6A");
            *
            *  ProblemFactory.Create<Day6B>()
            *   .SendToClipboard()
            *   .AppendTime()
            *   .Solve()
            *   .ToConsole("Day 6B");
            *
            *
            *  ProblemFactory.Create<Day7A>()
            *   .SendToClipboard()
            *   .AppendTime()
            *   .Solve()
            *   .ToConsole("Day 7A");
            *
            *  ProblemFactory.Create<Day7B>()
            *  .SendToClipboard()
            *  .AppendTime()
            *  .Solve()
            *  .ToConsole("Day 7B");
            *
            *  ProblemFactory.Create<Day8A>()
            *   .SendToClipboard()
            *   .AppendTime()
            *   .Solve()
            *   .ToConsole("Day 8A");
            *
            *  ProblemFactory.Create<Day8B>()
            *   .SendToClipboard()
            *   .AppendTime()
            *   .Solve()
            *   .ToConsole("Day 8B");
            *
            *
            *  ProblemFactory.Create<Day9A>()
            *  .SendToClipboard()
            *  .AppendTime()
            *  .Solve()
            *  .ToConsole("Day 9A");
            *
            *  ProblemFactory.Create<Day9B>()
            *   .SendToClipboard()
            *   .AppendTime()
            *   .Solve()
            *   .ToConsole("Day 9B");
            *
            *  ProblemFactory.Create<Day10A>()
            *  .SendToClipboard()
            *  .AppendTime()
            *  .Solve()
            *  .ToConsole("Day 10A");
            *
            *  ProblemFactory.Create<Day10B>()
            *   .SendToClipboard()
            *   .AppendTime()
            *   .Solve()
            *   .ToConsole("Day 10B");
            *
            *  ProblemFactory.Create<Day11A>()
            *   .SendToClipboard()
            *   .AppendTime()
            *   .Solve()
            *   .ToConsole("Day 11A");
            *
            *  ProblemFactory.Create<Day11B>()
            *   .SendToClipboard()
            *   .AppendTime()
            *   .Solve()
            *   .ToConsole("Day 11B");
            *  // */

            //ProblemFactory.Create<Day12A>()
            //    .SendToClipboard()
            //    .AppendTime()
            //    .Solve()
            //    .ToConsole("Day 12A");

            //ProblemFactory.Create<Day12B>()
            //    .SendToClipboard()
            //    .AppendTime()
            //    .Solve()
            //    .ToConsole("Day 12B");

            ProblemFactory.Create <Day13A>()
            .SendToClipboard()
            .AppendTime()
            .Solve()
            .ToConsole("Day 13A");

            ProblemFactory.Create <Day13B>()
            .SendToClipboard()
            .AppendTime()
            .Solve()
            .ToConsole("Day 13B");

            /** /
            *
            *
            *
            *  ProblemFactory.Create<Day14A>()
            *  .SendToClipboard()
            *  .AppendTime()
            *  .Solve()
            *  .ToConsole("Day 14A");
            *
            *  ProblemFactory.Create<Day14B>()
            *  .SendToClipboard()
            *  .AppendTime()
            *  .Solve()
            *  .ToConsole("Day 14B");
            *
            *  ProblemFactory.Create<Day16A>()
            *  .SendToClipboard()
            *  .AppendTime()
            *  .Solve()
            *  .ToConsole("Day 16A");
            *
            *  ProblemFactory.Create<Day16B>()
            *  .SendToClipboard()
            *  .AppendTime()
            *  .Solve()
            *  .ToConsole("Day 16B");
            *
            *  ProblemFactory.Create<Day17A>()
            *  .SendToClipboard()
            *  .AppendTime()
            *  .Solve()
            *  .ToConsole("Day 17A");
            *
            *  ProblemFactory.Create<Day17B>()
            *  .SendToClipboard()
            *  .AppendTime()
            *  .Solve()
            *  .ToConsole("Day 17B");
            *  // */

            Console.ReadKey();
        }
        /// <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));
            }
        }