protected RankAndCrowdingSorter(RankAndCrowdingSorter original, Cloner cloner) : base(original, cloner)
 {
 }
 protected RankAndCrowdingSorter(RankAndCrowdingSorter original, Cloner cloner) : base(original, cloner) { }
示例#3
0
        public NSGA2()
        {
            Parameters.Add(new ValueParameter <IntValue>("Seed", "The random seed used to initialize the new pseudo random number generator.", new IntValue(0)));
            Parameters.Add(new ValueParameter <BoolValue>("SetSeedRandomly", "True if the random seed should be set to a random value, otherwise false.", new BoolValue(true)));
            Parameters.Add(new ValueParameter <IntValue>("PopulationSize", "The size of the population of solutions.", new IntValue(100)));
            Parameters.Add(new ConstrainedValueParameter <ISelector>("Selector", "The operator used to select solutions for reproduction."));
            Parameters.Add(new ValueParameter <PercentValue>("CrossoverProbability", "The probability that the crossover operator is applied on two parents.", new PercentValue(0.9)));
            Parameters.Add(new ConstrainedValueParameter <ICrossover>("Crossover", "The operator used to cross solutions."));
            Parameters.Add(new ValueParameter <PercentValue>("MutationProbability", "The probability that the mutation operator is applied on a solution.", new PercentValue(0.05)));
            Parameters.Add(new ConstrainedValueParameter <IManipulator>("Mutator", "The operator used to mutate solutions."));
            Parameters.Add(new ValueParameter <MultiAnalyzer>("Analyzer", "The operator used to analyze each generation.", new MultiAnalyzer()));
            Parameters.Add(new ValueParameter <IntValue>("MaximumGenerations", "The maximum number of generations which should be processed.", new IntValue(1000)));
            Parameters.Add(new ValueParameter <IntValue>("SelectedParents", "Each two parents form a new child, typically this value should be twice the population size, but because the NSGA-II is maximally elitist it can be any multiple of 2 greater than 0.", new IntValue(200)));
            Parameters.Add(new FixedValueParameter <BoolValue>("DominateOnEqualQualities", "Flag which determines wether solutions with equal quality values should be treated as dominated.", new BoolValue(false)));

            RandomCreator         randomCreator         = new RandomCreator();
            SolutionsCreator      solutionsCreator      = new SolutionsCreator();
            SubScopesCounter      subScopesCounter      = new SubScopesCounter();
            RankAndCrowdingSorter rankAndCrowdingSorter = new RankAndCrowdingSorter();
            ResultsCollector      resultsCollector      = new ResultsCollector();
            NSGA2MainLoop         mainLoop = new NSGA2MainLoop();

            OperatorGraph.InitialOperator = randomCreator;

            randomCreator.RandomParameter.ActualName          = "Random";
            randomCreator.SeedParameter.ActualName            = SeedParameter.Name;
            randomCreator.SeedParameter.Value                 = null;
            randomCreator.SetSeedRandomlyParameter.ActualName = SetSeedRandomlyParameter.Name;
            randomCreator.SetSeedRandomlyParameter.Value      = null;
            randomCreator.Successor = solutionsCreator;

            solutionsCreator.NumberOfSolutionsParameter.ActualName = PopulationSizeParameter.Name;
            solutionsCreator.Successor = subScopesCounter;

            subScopesCounter.Name = "Initialize EvaluatedSolutions";
            subScopesCounter.ValueParameter.ActualName = "EvaluatedSolutions";
            subScopesCounter.Successor = rankAndCrowdingSorter;

            rankAndCrowdingSorter.DominateOnEqualQualitiesParameter.ActualName = DominateOnEqualQualitiesParameter.Name;
            rankAndCrowdingSorter.CrowdingDistanceParameter.ActualName         = "CrowdingDistance";
            rankAndCrowdingSorter.RankParameter.ActualName = "Rank";
            rankAndCrowdingSorter.Successor = resultsCollector;

            resultsCollector.CollectedValues.Add(new LookupParameter <IntValue>("Evaluated Solutions", null, "EvaluatedSolutions"));
            resultsCollector.ResultsParameter.ActualName = "Results";
            resultsCollector.Successor = mainLoop;

            mainLoop.PopulationSizeParameter.ActualName       = PopulationSizeParameter.Name;
            mainLoop.SelectorParameter.ActualName             = SelectorParameter.Name;
            mainLoop.CrossoverParameter.ActualName            = CrossoverParameter.Name;
            mainLoop.CrossoverProbabilityParameter.ActualName = CrossoverProbabilityParameter.Name;
            mainLoop.MaximumGenerationsParameter.ActualName   = MaximumGenerationsParameter.Name;
            mainLoop.MutatorParameter.ActualName             = MutatorParameter.Name;
            mainLoop.MutationProbabilityParameter.ActualName = MutationProbabilityParameter.Name;
            mainLoop.RandomParameter.ActualName             = RandomCreator.RandomParameter.ActualName;
            mainLoop.AnalyzerParameter.ActualName           = AnalyzerParameter.Name;
            mainLoop.ResultsParameter.ActualName            = "Results";
            mainLoop.EvaluatedSolutionsParameter.ActualName = "EvaluatedSolutions";

            foreach (ISelector selector in ApplicationManager.Manager.GetInstances <ISelector>().Where(x => !(x is ISingleObjectiveSelector)).OrderBy(x => x.Name))
            {
                SelectorParameter.ValidValues.Add(selector);
            }
            ISelector tournamentSelector = SelectorParameter.ValidValues.FirstOrDefault(x => x.GetType().Name.Equals("CrowdedTournamentSelector"));

            if (tournamentSelector != null)
            {
                SelectorParameter.Value = tournamentSelector;
            }

            ParameterizeSelectors();

            paretoFrontAnalyzer = new RankBasedParetoFrontAnalyzer();
            paretoFrontAnalyzer.RankParameter.ActualName    = "Rank";
            paretoFrontAnalyzer.RankParameter.Depth         = 1;
            paretoFrontAnalyzer.ResultsParameter.ActualName = "Results";
            ParameterizeAnalyzers();
            UpdateAnalyzers();

            RegisterEventhandlers();
        }
示例#4
0
        private void Initialize()
        {
            #region Create parameters
            Parameters.Add(new ValueLookupParameter <IRandom>("Random", "A pseudo random number generator."));
            Parameters.Add(new ValueLookupParameter <BoolArray>("Maximization", "True if an objective should be maximized, or false if it should be minimized."));
            Parameters.Add(new ScopeTreeLookupParameter <DoubleArray>("Qualities", "The vector of quality values."));
            Parameters.Add(new ValueLookupParameter <IntValue>("PopulationSize", "The population size."));
            Parameters.Add(new ValueLookupParameter <IOperator>("Selector", "The operator used to select solutions for reproduction."));
            Parameters.Add(new ValueLookupParameter <PercentValue>("CrossoverProbability", "The probability that the crossover operator is applied on a solution."));
            Parameters.Add(new ValueLookupParameter <IOperator>("Crossover", "The operator used to cross solutions."));
            Parameters.Add(new ValueLookupParameter <PercentValue>("MutationProbability", "The probability that the mutation operator is applied on a solution."));
            Parameters.Add(new ValueLookupParameter <IOperator>("Mutator", "The operator used to mutate solutions."));
            Parameters.Add(new ValueLookupParameter <IOperator>("Evaluator", "The operator used to evaluate solutions. This operator is executed in parallel, if an engine is used which supports parallelization."));
            Parameters.Add(new ValueLookupParameter <IntValue>("MaximumGenerations", "The maximum number of generations which should be processed."));
            Parameters.Add(new ValueLookupParameter <VariableCollection>("Results", "The variable collection where results should be stored."));
            Parameters.Add(new ValueLookupParameter <IOperator>("Analyzer", "The operator used to analyze each generation."));
            Parameters.Add(new LookupParameter <IntValue>("EvaluatedSolutions", "The number of times solutions have been evaluated."));
            Parameters.Add(new ValueLookupParameter <BoolValue>("DominateOnEqualQualities", "Flag which determines wether solutions with equal quality values should be treated as dominated."));
            #endregion

            #region Create operators
            VariableCreator           variableCreator            = new VariableCreator();
            ResultsCollector          resultsCollector1          = new ResultsCollector();
            Placeholder               analyzer1                  = new Placeholder();
            Placeholder               selector                   = new Placeholder();
            SubScopesProcessor        subScopesProcessor1        = new SubScopesProcessor();
            ChildrenCreator           childrenCreator            = new ChildrenCreator();
            UniformSubScopesProcessor uniformSubScopesProcessor1 = new UniformSubScopesProcessor();
            StochasticBranch          crossoverStochasticBranch  = new StochasticBranch();
            Placeholder               crossover                  = new Placeholder();
            ParentCopyCrossover       noCrossover                = new ParentCopyCrossover();
            StochasticBranch          mutationStochasticBranch   = new StochasticBranch();
            Placeholder               mutator                    = new Placeholder();
            SubScopesRemover          subScopesRemover           = new SubScopesRemover();
            UniformSubScopesProcessor uniformSubScopesProcessor2 = new UniformSubScopesProcessor();
            Placeholder               evaluator                  = new Placeholder();
            SubScopesCounter          subScopesCounter           = new SubScopesCounter();
            MergingReducer            mergingReducer             = new MergingReducer();
            RankAndCrowdingSorter     rankAndCrowdingSorter      = new RankAndCrowdingSorter();
            LeftSelector              leftSelector               = new LeftSelector();
            RightReducer              rightReducer               = new RightReducer();
            IntCounter        intCounter        = new IntCounter();
            Comparator        comparator        = new Comparator();
            Placeholder       analyzer2         = new Placeholder();
            ConditionalBranch conditionalBranch = new ConditionalBranch();

            variableCreator.CollectedValues.Add(new ValueParameter <IntValue>("Generations", new IntValue(0)));

            resultsCollector1.CollectedValues.Add(new LookupParameter <IntValue>("Generations"));
            resultsCollector1.ResultsParameter.ActualName = ResultsParameter.Name;

            analyzer1.Name = "Analyzer";
            analyzer1.OperatorParameter.ActualName = AnalyzerParameter.Name;

            selector.Name = "Selector";
            selector.OperatorParameter.ActualName = SelectorParameter.Name;

            childrenCreator.ParentsPerChild = new IntValue(2);

            crossoverStochasticBranch.ProbabilityParameter.ActualName = CrossoverProbabilityParameter.Name;
            crossoverStochasticBranch.RandomParameter.ActualName      = RandomParameter.Name;

            crossover.Name = "Crossover";
            crossover.OperatorParameter.ActualName = CrossoverParameter.Name;

            noCrossover.Name = "Clone parent";
            noCrossover.RandomParameter.ActualName = RandomParameter.Name;

            mutationStochasticBranch.ProbabilityParameter.ActualName = MutationProbabilityParameter.Name;
            mutationStochasticBranch.RandomParameter.ActualName      = RandomParameter.Name;

            mutator.Name = "Mutator";
            mutator.OperatorParameter.ActualName = MutatorParameter.Name;

            subScopesRemover.RemoveAllSubScopes = true;

            uniformSubScopesProcessor2.Parallel.Value = true;

            evaluator.Name = "Evaluator";
            evaluator.OperatorParameter.ActualName = EvaluatorParameter.Name;

            subScopesCounter.Name = "Increment EvaluatedSolutions";
            subScopesCounter.ValueParameter.ActualName = EvaluatedSolutionsParameter.Name;

            rankAndCrowdingSorter.DominateOnEqualQualitiesParameter.ActualName = DominateOnEqualQualitiesParameter.Name;
            rankAndCrowdingSorter.CrowdingDistanceParameter.ActualName         = "CrowdingDistance";
            rankAndCrowdingSorter.RankParameter.ActualName = "Rank";

            leftSelector.CopySelected = new BoolValue(false);
            leftSelector.NumberOfSelectedSubScopesParameter.ActualName = PopulationSizeParameter.Name;

            intCounter.Increment = new IntValue(1);
            intCounter.ValueParameter.ActualName = "Generations";

            comparator.Comparison = new Comparison(ComparisonType.GreaterOrEqual);
            comparator.LeftSideParameter.ActualName  = "Generations";
            comparator.ResultParameter.ActualName    = "Terminate";
            comparator.RightSideParameter.ActualName = MaximumGenerationsParameter.Name;

            analyzer2.Name = "Analyzer";
            analyzer2.OperatorParameter.ActualName = "Analyzer";

            conditionalBranch.ConditionParameter.ActualName = "Terminate";
            #endregion

            #region Create operator graph
            OperatorGraph.InitialOperator = variableCreator;
            variableCreator.Successor     = resultsCollector1;
            resultsCollector1.Successor   = analyzer1;
            analyzer1.Successor           = selector;
            selector.Successor            = subScopesProcessor1;
            subScopesProcessor1.Operators.Add(new EmptyOperator());
            subScopesProcessor1.Operators.Add(childrenCreator);
            subScopesProcessor1.Successor          = mergingReducer;
            childrenCreator.Successor              = uniformSubScopesProcessor1;
            uniformSubScopesProcessor1.Operator    = crossoverStochasticBranch;
            uniformSubScopesProcessor1.Successor   = uniformSubScopesProcessor2;
            crossoverStochasticBranch.FirstBranch  = crossover;
            crossoverStochasticBranch.SecondBranch = noCrossover;
            crossoverStochasticBranch.Successor    = mutationStochasticBranch;
            crossover.Successor   = null;
            noCrossover.Successor = null;
            mutationStochasticBranch.FirstBranch  = mutator;
            mutationStochasticBranch.SecondBranch = null;
            mutationStochasticBranch.Successor    = subScopesRemover;
            mutator.Successor                    = null;
            subScopesRemover.Successor           = null;
            uniformSubScopesProcessor2.Operator  = evaluator;
            uniformSubScopesProcessor2.Successor = subScopesCounter;
            evaluator.Successor                  = null;
            subScopesCounter.Successor           = null;
            mergingReducer.Successor             = rankAndCrowdingSorter;
            rankAndCrowdingSorter.Successor      = leftSelector;
            leftSelector.Successor               = rightReducer;
            rightReducer.Successor               = intCounter;
            intCounter.Successor                 = comparator;
            comparator.Successor                 = analyzer2;
            analyzer2.Successor                  = conditionalBranch;
            conditionalBranch.FalseBranch        = selector;
            conditionalBranch.TrueBranch         = null;
            conditionalBranch.Successor          = null;
            #endregion
        }