public RankAndCrowdingSorter()
            : base()
        {
            Parameters.Add(new ValueLookupParameter <BoolArray>("Maximization", "For each objective a value that is true if that objective should be maximized, or false if it should be minimized."));
            Parameters.Add(new ValueLookupParameter <BoolValue>("DominateOnEqualQualities", "Flag which determines wether solutions with equal quality values should be treated as dominated."));
            Parameters.Add(new ScopeTreeLookupParameter <DoubleArray>("Qualities", "The vector of quality values."));
            Parameters.Add(new ScopeTreeLookupParameter <IntValue>("Rank", "The rank of a solution (to which front it belongs)."));
            Parameters.Add(new ScopeTreeLookupParameter <DoubleValue>("CrowdingDistance", "The crowding distance of a solution in a population."));

            FastNonDominatedSort       fastNonDominatedSort       = new FastNonDominatedSort();
            UniformSubScopesProcessor  subScopesProcessor         = new UniformSubScopesProcessor();
            CrowdingDistanceAssignment crowdingDistanceAssignment = new CrowdingDistanceAssignment();
            CrowdedComparisonSorter    crowdedComparisonSorter    = new CrowdedComparisonSorter();
            MergingReducer             mergingReducer             = new MergingReducer();

            fastNonDominatedSort.MaximizationParameter.ActualName             = MaximizationParameter.Name;
            fastNonDominatedSort.DominateOnEqualQualitiesParameter.ActualName = DominateOnEqualQualitiesParameter.Name;
            fastNonDominatedSort.QualitiesParameter.ActualName = QualitiesParameter.Name;
            fastNonDominatedSort.RankParameter.ActualName      = RankParameter.Name;

            crowdingDistanceAssignment.CrowdingDistanceParameter.ActualName = CrowdingDistanceParameter.Name;
            crowdingDistanceAssignment.QualitiesParameter.ActualName        = QualitiesParameter.Name;

            crowdedComparisonSorter.CrowdingDistanceParameter.ActualName = CrowdingDistanceParameter.Name;
            crowdedComparisonSorter.RankParameter.ActualName             = RankParameter.Name;

            OperatorGraph.InitialOperator        = fastNonDominatedSort;
            fastNonDominatedSort.Successor       = subScopesProcessor;
            subScopesProcessor.Operator          = crowdingDistanceAssignment;
            crowdingDistanceAssignment.Successor = crowdedComparisonSorter;
            crowdedComparisonSorter.Successor    = null;
            subScopesProcessor.Successor         = mergingReducer;
            mergingReducer.Successor             = null;
        }
Esempio n. 2
0
        private void Initialize()
        {
            #region Create parameters
            Parameters.Add(new ValueLookupParameter <IRandom>("Random", "A pseudo random number generator."));
            Parameters.Add(new ValueLookupParameter <BoolValue>("Maximization", "True if the problem is a maximization problem, otherwise false."));
            Parameters.Add(new LookupParameter <DoubleValue>("Quality", "The value which represents the quality of a solution."));
            Parameters.Add(new ValueLookupParameter <DoubleValue>("BestKnownQuality", "The best known quality value found so far."));
            Parameters.Add(new LookupParameter <DoubleValue>("MoveQuality", "The value which represents the quality of a move."));
            Parameters.Add(new LookupParameter <BoolValue>("MoveTabu", "The value that indicates if a move is tabu or not."));
            Parameters.Add(new ValueLookupParameter <IntValue>("MaximumIterations", "The maximum number of generations which should be processed."));
            Parameters.Add(new ValueLookupParameter <IntValue>("TabuTenure", "The length of the tabu list, and also means the number of iterations a move is kept tabu"));

            Parameters.Add(new ValueLookupParameter <IOperator>("MoveGenerator", "The operator that generates the moves."));
            Parameters.Add(new ValueLookupParameter <IOperator>("MoveMaker", "The operator that performs a move and updates the quality."));
            Parameters.Add(new ValueLookupParameter <IOperator>("MoveEvaluator", "The operator that evaluates a move."));
            Parameters.Add(new ValueLookupParameter <IOperator>("TabuChecker", "The operator that checks whether a move is tabu."));
            Parameters.Add(new ValueLookupParameter <IOperator>("TabuMaker", "The operator that declares a move tabu."));

            Parameters.Add(new ValueLookupParameter <IOperator>("Analyzer", "The operator used to analyze the solution and moves."));
            Parameters.Add(new ValueLookupParameter <VariableCollection>("Results", "The variable collection where results should be stored."));
            Parameters.Add(new LookupParameter <IntValue>("EvaluatedMoves", "The number of evaluated moves."));
            #endregion

            #region Create operators
            VariableCreator           variableCreator        = new VariableCreator();
            SubScopesProcessor        subScopesProcessor0    = new SubScopesProcessor();
            Assigner                  bestQualityInitializer = new Assigner();
            Placeholder               analyzer1                  = new Placeholder();
            ResultsCollector          resultsCollector1          = new ResultsCollector();
            SubScopesProcessor        solutionProcessor          = new SubScopesProcessor();
            Placeholder               moveGenerator              = new Placeholder();
            UniformSubScopesProcessor moveEvaluationProcessor    = new UniformSubScopesProcessor();
            Placeholder               moveEvaluator              = new Placeholder();
            Placeholder               tabuChecker                = new Placeholder();
            SubScopesCounter          subScopesCounter           = new SubScopesCounter();
            SubScopesSorter           moveQualitySorter          = new SubScopesSorter();
            TabuSelector              tabuSelector               = new TabuSelector();
            ConditionalBranch         emptyNeighborhoodBranch1   = new ConditionalBranch();
            SubScopesProcessor        moveMakingProcessor        = new SubScopesProcessor();
            UniformSubScopesProcessor selectedMoveMakingProcesor = new UniformSubScopesProcessor();
            Placeholder               tabuMaker                  = new Placeholder();
            Placeholder               moveMaker                  = new Placeholder();
            MergingReducer            mergingReducer             = new MergingReducer();
            Placeholder               analyzer2                  = new Placeholder();
            SubScopesRemover          subScopesRemover           = new SubScopesRemover();
            ConditionalBranch         emptyNeighborhoodBranch2   = new ConditionalBranch();
            BestQualityMemorizer      bestQualityUpdater         = new BestQualityMemorizer();
            IntCounter                iterationsCounter          = new IntCounter();
            Comparator                iterationsComparator       = new Comparator();
            ConditionalBranch         iterationsTermination      = new ConditionalBranch();

            variableCreator.CollectedValues.Add(new ValueParameter <IntValue>("Iterations", new IntValue(0))); // Class TabuSearch expects this to be called Iterations
            variableCreator.CollectedValues.Add(new ValueParameter <BoolValue>("EmptyNeighborhood", new BoolValue(false)));
            variableCreator.CollectedValues.Add(new ValueParameter <ItemList <IItem> >("TabuList", new ItemList <IItem>()));
            variableCreator.CollectedValues.Add(new ValueParameter <VariableCollection>("Memories", new VariableCollection()));
            variableCreator.CollectedValues.Add(new ValueParameter <DoubleValue>("BestQuality", new DoubleValue(0)));

            bestQualityInitializer.Name = "Initialize BestQuality";
            bestQualityInitializer.LeftSideParameter.ActualName  = "BestQuality";
            bestQualityInitializer.RightSideParameter.ActualName = QualityParameter.Name;

            analyzer1.Name = "Analyzer (placeholder)";
            analyzer1.OperatorParameter.ActualName = AnalyzerParameter.Name;

            resultsCollector1.CopyValue = new BoolValue(false);
            resultsCollector1.CollectedValues.Add(new LookupParameter <IntValue>("Iterations"));
            resultsCollector1.CollectedValues.Add(new LookupParameter <DoubleValue>("Best Quality", null, "BestQuality"));
            resultsCollector1.ResultsParameter.ActualName = ResultsParameter.Name;

            moveGenerator.Name = "MoveGenerator (placeholder)";
            moveGenerator.OperatorParameter.ActualName = MoveGeneratorParameter.Name;

            moveEvaluationProcessor.Parallel = new BoolValue(true);

            moveEvaluator.Name = "MoveEvaluator (placeholder)";
            moveEvaluator.OperatorParameter.ActualName = MoveEvaluatorParameter.Name;

            tabuChecker.Name = "TabuChecker (placeholder)";
            tabuChecker.OperatorParameter.ActualName = TabuCheckerParameter.Name;

            subScopesCounter.Name = "Increment EvaluatedMoves";
            subScopesCounter.ValueParameter.ActualName = EvaluatedMovesParameter.Name;

            moveQualitySorter.DescendingParameter.ActualName = MaximizationParameter.Name;
            moveQualitySorter.ValueParameter.ActualName      = MoveQualityParameter.Name;

            tabuSelector.AspirationParameter.Value       = new BoolValue(true);
            tabuSelector.BestQualityParameter.ActualName = "BestQuality";
            tabuSelector.CopySelected = new BoolValue(false);
            tabuSelector.EmptyNeighborhoodParameter.ActualName = "EmptyNeighborhood";
            tabuSelector.MaximizationParameter.ActualName      = MaximizationParameter.Name;
            tabuSelector.MoveQualityParameter.ActualName       = MoveQualityParameter.Name;
            tabuSelector.MoveTabuParameter.ActualName          = MoveTabuParameter.Name;

            moveMakingProcessor.Name = "MoveMaking processor (UniformSubScopesProcessor)";

            emptyNeighborhoodBranch1.Name = "Neighborhood empty?";
            emptyNeighborhoodBranch1.ConditionParameter.ActualName = "EmptyNeighborhood";

            tabuMaker.Name = "TabuMaker (placeholder)";
            tabuMaker.OperatorParameter.ActualName = TabuMakerParameter.Name;

            moveMaker.Name = "MoveMaker (placeholder)";
            moveMaker.OperatorParameter.ActualName = MoveMakerParameter.Name;

            analyzer2.Name = "Analyzer (placeholder)";
            analyzer2.OperatorParameter.ActualName = AnalyzerParameter.Name;

            subScopesRemover.RemoveAllSubScopes = true;

            bestQualityUpdater.Name = "Update BestQuality";
            bestQualityUpdater.MaximizationParameter.ActualName = MaximizationParameter.Name;
            bestQualityUpdater.QualityParameter.ActualName      = QualityParameter.Name;
            bestQualityUpdater.BestQualityParameter.ActualName  = "BestQuality";

            iterationsCounter.Name      = "Iterations Counter";
            iterationsCounter.Increment = new IntValue(1);
            iterationsCounter.ValueParameter.ActualName = "Iterations";

            iterationsComparator.Name       = "Iterations >= MaximumIterations";
            iterationsComparator.Comparison = new Comparison(ComparisonType.GreaterOrEqual);
            iterationsComparator.LeftSideParameter.ActualName  = "Iterations";
            iterationsComparator.RightSideParameter.ActualName = MaximumIterationsParameter.Name;
            iterationsComparator.ResultParameter.ActualName    = "Terminate";

            emptyNeighborhoodBranch2.Name = "Neighborhood empty?";
            emptyNeighborhoodBranch2.ConditionParameter.ActualName = "EmptyNeighborhood";

            iterationsTermination.Name = "Iterations Termination Condition";
            iterationsTermination.ConditionParameter.ActualName = "Terminate";
            #endregion

            #region Create operator graph
            OperatorGraph.InitialOperator = variableCreator;
            variableCreator.Successor     = subScopesProcessor0;
            subScopesProcessor0.Operators.Add(bestQualityInitializer);
            subScopesProcessor0.Successor    = resultsCollector1;
            bestQualityInitializer.Successor = analyzer1;
            analyzer1.Successor         = null;
            resultsCollector1.Successor = solutionProcessor;
            solutionProcessor.Operators.Add(moveGenerator);
            solutionProcessor.Successor          = iterationsCounter;
            moveGenerator.Successor              = moveEvaluationProcessor;
            moveEvaluationProcessor.Operator     = moveEvaluator;
            moveEvaluationProcessor.Successor    = subScopesCounter;
            moveEvaluator.Successor              = tabuChecker;
            tabuChecker.Successor                = null;
            subScopesCounter.Successor           = moveQualitySorter;
            moveQualitySorter.Successor          = tabuSelector;
            tabuSelector.Successor               = emptyNeighborhoodBranch1;
            emptyNeighborhoodBranch1.FalseBranch = moveMakingProcessor;
            emptyNeighborhoodBranch1.TrueBranch  = null;
            emptyNeighborhoodBranch1.Successor   = subScopesRemover;
            moveMakingProcessor.Operators.Add(new EmptyOperator());
            moveMakingProcessor.Operators.Add(selectedMoveMakingProcesor);
            moveMakingProcessor.Successor        = mergingReducer;
            selectedMoveMakingProcesor.Operator  = tabuMaker;
            selectedMoveMakingProcesor.Successor = null;
            tabuMaker.Successor                  = moveMaker;
            moveMaker.Successor                  = null;
            mergingReducer.Successor             = analyzer2;
            analyzer2.Successor                  = null;
            subScopesRemover.Successor           = null;
            iterationsCounter.Successor          = iterationsComparator;
            iterationsComparator.Successor       = emptyNeighborhoodBranch2;
            emptyNeighborhoodBranch2.TrueBranch  = null;
            emptyNeighborhoodBranch2.FalseBranch = iterationsTermination;
            emptyNeighborhoodBranch2.Successor   = null;
            iterationsTermination.TrueBranch     = null;
            iterationsTermination.FalseBranch    = solutionProcessor;
            #endregion
        }
        public IslandGeneticAlgorithmMainLoop()
            : base()
        {
            #region Create parameters
            Parameters.Add(new ValueLookupParameter <IRandom>("Random", "A pseudo random number generator."));
            Parameters.Add(new ValueLookupParameter <BoolValue>("Maximization", "True if the problem is a maximization problem, otherwise false."));
            Parameters.Add(new ScopeTreeLookupParameter <DoubleValue>("Quality", "The value which represents the quality of a solution."));
            Parameters.Add(new ValueLookupParameter <DoubleValue>("BestKnownQuality", "The best known quality value found so far."));
            Parameters.Add(new ValueLookupParameter <IntValue>("NumberOfIslands", "The number of islands."));
            Parameters.Add(new ValueLookupParameter <IntValue>("MigrationInterval", "The number of generations that should pass between migration phases."));
            Parameters.Add(new ValueLookupParameter <PercentValue>("MigrationRate", "The proportion of individuals that should migrate between the islands."));
            Parameters.Add(new ValueLookupParameter <IOperator>("Migrator", "The migration strategy."));
            Parameters.Add(new ValueLookupParameter <IOperator>("EmigrantsSelector", "Selects the individuals that will be migrated."));
            Parameters.Add(new ValueLookupParameter <IOperator>("ImmigrationReplacer", "Replaces some of the original population with the immigrants."));
            Parameters.Add(new ValueLookupParameter <IntValue>("PopulationSize", "The size of the population of solutions."));
            Parameters.Add(new ValueLookupParameter <IntValue>("MaximumGenerations", "The maximum number of generations that the algorithm should process."));
            Parameters.Add(new ValueLookupParameter <IOperator>("Selector", "The operator used to select solutions for reproduction."));
            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."));
            Parameters.Add(new ValueLookupParameter <IntValue>("Elites", "The numer of elite solutions which are kept in each generation."));
            Parameters.Add(new ValueLookupParameter <BoolValue>("ReevaluateElites", "Flag to determine if elite individuals should be reevaluated (i.e., if stochastic fitness functions are used.)"));
            Parameters.Add(new ValueLookupParameter <ResultCollection>("Results", "The results collection to store the results."));
            Parameters.Add(new ValueLookupParameter <IOperator>("Analyzer", "The operator used to the analyze the islands."));
            Parameters.Add(new ValueLookupParameter <IOperator>("IslandAnalyzer", "The operator used to analyze each island."));
            Parameters.Add(new LookupParameter <IntValue>("EvaluatedSolutions", "The number of times a solution has been evaluated."));
            Parameters.Add(new LookupParameter <IntValue>("IslandGenerations", "The number of generations calculated on one island."));
            Parameters.Add(new LookupParameter <IntValue>("IslandEvaluatedSolutions", "The number of times a solution has been evaluated on one island."));
            Parameters.Add(new ValueLookupParameter <BoolValue>("Migrate", "Migrate the island?"));
            #endregion

            #region Create operators
            VariableCreator           variableCreator            = new VariableCreator();
            UniformSubScopesProcessor uniformSubScopesProcessor0 = new UniformSubScopesProcessor();
            VariableCreator           islandVariableCreator      = new VariableCreator();
            Placeholder               islandAnalyzer1            = new Placeholder();
            LocalRandomCreator        localRandomCreator         = new LocalRandomCreator();
            Placeholder               analyzer1                  = new Placeholder();
            ResultsCollector          resultsCollector1          = new ResultsCollector();
            UniformSubScopesProcessor uniformSubScopesProcessor1 = new UniformSubScopesProcessor();
            Assigner                  generationsAssigner        = new Assigner();
            Assigner                  evaluatedSolutionsAssigner = new Assigner();
            Placeholder               selector                   = new Placeholder();
            SubScopesProcessor        subScopesProcessor1        = new SubScopesProcessor();
            ChildrenCreator           childrenCreator            = new ChildrenCreator();
            UniformSubScopesProcessor uniformSubScopesProcessor2 = new UniformSubScopesProcessor();
            Placeholder               crossover                  = new Placeholder();
            StochasticBranch          stochasticBranch           = new StochasticBranch();
            Placeholder               mutator                              = new Placeholder();
            SubScopesRemover          subScopesRemover                     = new SubScopesRemover();
            UniformSubScopesProcessor uniformSubScopesProcessor3           = new UniformSubScopesProcessor();
            Placeholder               evaluator                            = new Placeholder();
            SubScopesCounter          subScopesCounter                     = new SubScopesCounter();
            SubScopesProcessor        subScopesProcessor2                  = new SubScopesProcessor();
            BestSelector              bestSelector                         = new BestSelector();
            RightReducer              rightReducer                         = new RightReducer();
            MergingReducer            mergingReducer                       = new MergingReducer();
            IntCounter                islandGenerationsCounter             = new IntCounter();
            Comparator                checkIslandGenerationsReachedMaximum = new Comparator();
            ConditionalBranch         checkContinueEvolution               = new ConditionalBranch();
            DataReducer               generationsReducer                   = new DataReducer();
            DataReducer               evaluatedSolutionsReducer            = new DataReducer();
            Placeholder               islandAnalyzer2                      = new Placeholder();
            UniformSubScopesProcessor uniformSubScopesProcessor5           = new UniformSubScopesProcessor();
            Placeholder               emigrantsSelector                    = new Placeholder();
            IntCounter                migrationsCounter                    = new IntCounter();
            Placeholder               migrator                             = new Placeholder();
            UniformSubScopesProcessor uniformSubScopesProcessor6           = new UniformSubScopesProcessor();
            Placeholder               immigrationReplacer                  = new Placeholder();
            Comparator                generationsComparator                = new Comparator();
            Placeholder               analyzer2                            = new Placeholder();
            ConditionalBranch         generationsTerminationCondition      = new ConditionalBranch();
            ConditionalBranch         reevaluateElitesBranch               = new ConditionalBranch();


            variableCreator.CollectedValues.Add(new ValueParameter <IntValue>("Migrations", new IntValue(0)));
            variableCreator.CollectedValues.Add(new ValueParameter <IntValue>("GenerationsSinceLastMigration", new IntValue(0)));
            variableCreator.CollectedValues.Add(new ValueParameter <IntValue>("Generations", new IntValue(0))); // Class IslandGeneticAlgorithm expects this to be called Generations

            islandVariableCreator.CollectedValues.Add(new ValueParameter <ResultCollection>("Results", new ResultCollection()));
            islandVariableCreator.CollectedValues.Add(new ValueParameter <IntValue>("IslandGenerations", new IntValue(0)));
            islandVariableCreator.CollectedValues.Add(new ValueParameter <IntValue>("IslandEvaluatedSolutions", new IntValue(0)));

            islandAnalyzer1.Name = "Island Analyzer (placeholder)";
            islandAnalyzer1.OperatorParameter.ActualName = IslandAnalyzerParameter.Name;

            analyzer1.Name = "Analyzer (placeholder)";
            analyzer1.OperatorParameter.ActualName = AnalyzerParameter.Name;

            resultsCollector1.CollectedValues.Add(new LookupParameter <IntValue>("Migrations"));
            resultsCollector1.CollectedValues.Add(new LookupParameter <IntValue>("Generations"));
            resultsCollector1.CollectedValues.Add(new ScopeTreeLookupParameter <ResultCollection>("IslandResults", "Result set for each island", "Results"));
            resultsCollector1.ResultsParameter.ActualName = ResultsParameter.Name;

            uniformSubScopesProcessor1.Parallel.Value = true;

            generationsAssigner.Name = "Initialize Island Generations";
            generationsAssigner.LeftSideParameter.ActualName = IslandGenerations.Name;
            generationsAssigner.RightSideParameter.Value     = new IntValue(0);

            evaluatedSolutionsAssigner.Name = "Initialize Island evaluated solutions";
            evaluatedSolutionsAssigner.LeftSideParameter.ActualName = IslandEvaluatedSolutions.Name;
            evaluatedSolutionsAssigner.RightSideParameter.Value     = new IntValue(0);

            selector.Name = "Selector (placeholder)";
            selector.OperatorParameter.ActualName = SelectorParameter.Name;

            childrenCreator.ParentsPerChild = new IntValue(2);

            crossover.Name = "Crossover (placeholder)";
            crossover.OperatorParameter.ActualName = CrossoverParameter.Name;

            stochasticBranch.ProbabilityParameter.ActualName = MutationProbabilityParameter.Name;
            //set it to the random number generator of the island
            stochasticBranch.RandomParameter.ActualName = "LocalRandom";

            mutator.Name = "Mutator (placeholder)";
            mutator.OperatorParameter.ActualName = MutatorParameter.Name;

            subScopesRemover.RemoveAllSubScopes = true;

            evaluator.Name = "Evaluator (placeholder)";
            evaluator.OperatorParameter.ActualName = EvaluatorParameter.Name;

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

            bestSelector.CopySelected = new BoolValue(false);
            bestSelector.MaximizationParameter.ActualName = MaximizationParameter.Name;
            bestSelector.NumberOfSelectedSubScopesParameter.ActualName = ElitesParameter.Name;
            bestSelector.QualityParameter.ActualName = QualityParameter.Name;

            islandGenerationsCounter.Name = "Increment island generatrions";
            islandGenerationsCounter.ValueParameter.ActualName = IslandGenerations.Name;
            islandGenerationsCounter.Increment = new IntValue(1);

            checkIslandGenerationsReachedMaximum.LeftSideParameter.ActualName  = IslandGenerations.Name;
            checkIslandGenerationsReachedMaximum.RightSideParameter.ActualName = MigrationIntervalParameter.Name;
            checkIslandGenerationsReachedMaximum.Comparison = new Comparison(ComparisonType.GreaterOrEqual);
            checkIslandGenerationsReachedMaximum.ResultParameter.ActualName = Migrate.Name;

            checkContinueEvolution.Name = "Migrate?";
            checkContinueEvolution.ConditionParameter.ActualName = Migrate.Name;
            checkContinueEvolution.FalseBranch = selector;

            islandAnalyzer2.Name = "Island Analyzer (placeholder)";
            islandAnalyzer2.OperatorParameter.ActualName = IslandAnalyzerParameter.Name;

            generationsReducer.Name = "Increment Generations";
            generationsReducer.ParameterToReduce.ActualName = islandGenerationsCounter.ValueParameter.ActualName;
            generationsReducer.TargetParameter.ActualName   = "Generations";
            generationsReducer.ReductionOperation.Value     = new ReductionOperation(ReductionOperations.Min);
            generationsReducer.TargetOperation.Value        = new ReductionOperation(ReductionOperations.Sum);

            evaluatedSolutionsReducer.Name = "Increment Evaluated Solutions";
            evaluatedSolutionsReducer.ParameterToReduce.ActualName = IslandEvaluatedSolutions.Name;
            evaluatedSolutionsReducer.TargetParameter.ActualName   = EvaluatedSolutionsParameter.Name;
            evaluatedSolutionsReducer.ReductionOperation.Value     = new ReductionOperation(ReductionOperations.Sum);
            evaluatedSolutionsReducer.TargetOperation.Value        = new ReductionOperation(ReductionOperations.Sum);

            emigrantsSelector.Name = "Emigrants Selector (placeholder)";
            emigrantsSelector.OperatorParameter.ActualName = EmigrantsSelectorParameter.Name;

            migrationsCounter.Name = "Increment number of Migrations";
            migrationsCounter.ValueParameter.ActualName = "Migrations";
            migrationsCounter.Increment = new IntValue(1);

            migrator.Name = "Migrator (placeholder)";
            migrator.OperatorParameter.ActualName = MigratorParameter.Name;

            immigrationReplacer.Name = "Immigration Replacer (placeholder)";
            immigrationReplacer.OperatorParameter.ActualName = ImmigrationReplacerParameter.Name;

            generationsComparator.Name       = "Generations >= MaximumGenerations ?";
            generationsComparator.Comparison = new Comparison(ComparisonType.GreaterOrEqual);
            generationsComparator.LeftSideParameter.ActualName  = "Generations";
            generationsComparator.ResultParameter.ActualName    = "TerminateGenerations";
            generationsComparator.RightSideParameter.ActualName = MaximumGenerationsParameter.Name;

            analyzer2.Name = "Analyzer (placeholder)";
            analyzer2.OperatorParameter.ActualName = AnalyzerParameter.Name;

            generationsTerminationCondition.Name = "Terminate?";
            generationsTerminationCondition.ConditionParameter.ActualName = "TerminateGenerations";

            reevaluateElitesBranch.ConditionParameter.ActualName = "ReevaluateElites";
            reevaluateElitesBranch.Name = "Reevaluate elites ?";
            #endregion

            #region Create operator graph
            OperatorGraph.InitialOperator        = variableCreator;
            variableCreator.Successor            = uniformSubScopesProcessor0;
            uniformSubScopesProcessor0.Operator  = islandVariableCreator;
            uniformSubScopesProcessor0.Successor = analyzer1;
            islandVariableCreator.Successor      = islandAnalyzer1;
            // BackwardsCompatibility3.3
            //the local randoms are created by the island GA itself and are only here to ensure same algorithm results
            #region Backwards compatible code, remove local random creator with 3.4 and rewire the operator graph
            islandAnalyzer1.Successor    = localRandomCreator;
            localRandomCreator.Successor = null;
            #endregion
            analyzer1.Successor                  = resultsCollector1;
            resultsCollector1.Successor          = uniformSubScopesProcessor1;
            uniformSubScopesProcessor1.Operator  = generationsAssigner;
            uniformSubScopesProcessor1.Successor = generationsReducer;
            generationsReducer.Successor         = evaluatedSolutionsReducer;
            evaluatedSolutionsReducer.Successor  = migrationsCounter;
            migrationsCounter.Successor          = uniformSubScopesProcessor5;
            generationsAssigner.Successor        = evaluatedSolutionsAssigner;
            evaluatedSolutionsAssigner.Successor = selector;
            selector.Successor = subScopesProcessor1;
            subScopesProcessor1.Operators.Add(new EmptyOperator());
            subScopesProcessor1.Operators.Add(childrenCreator);
            subScopesProcessor1.Successor        = subScopesProcessor2;
            childrenCreator.Successor            = uniformSubScopesProcessor2;
            uniformSubScopesProcessor2.Operator  = crossover;
            uniformSubScopesProcessor2.Successor = uniformSubScopesProcessor3;
            crossover.Successor                  = stochasticBranch;
            stochasticBranch.FirstBranch         = mutator;
            stochasticBranch.SecondBranch        = null;
            stochasticBranch.Successor           = subScopesRemover;
            mutator.Successor                    = null;
            subScopesRemover.Successor           = null;
            uniformSubScopesProcessor3.Operator  = evaluator;
            uniformSubScopesProcessor3.Successor = subScopesCounter;
            evaluator.Successor                  = null;
            subScopesCounter.Successor           = null;
            subScopesProcessor2.Operators.Add(bestSelector);
            subScopesProcessor2.Operators.Add(new EmptyOperator());
            subScopesProcessor2.Successor                  = mergingReducer;
            mergingReducer.Successor                       = islandAnalyzer2;
            bestSelector.Successor                         = rightReducer;
            rightReducer.Successor                         = reevaluateElitesBranch;
            reevaluateElitesBranch.TrueBranch              = uniformSubScopesProcessor3;
            reevaluateElitesBranch.FalseBranch             = null;
            reevaluateElitesBranch.Successor               = null;
            islandAnalyzer2.Successor                      = islandGenerationsCounter;
            islandGenerationsCounter.Successor             = checkIslandGenerationsReachedMaximum;
            checkIslandGenerationsReachedMaximum.Successor = checkContinueEvolution;
            uniformSubScopesProcessor5.Operator            = emigrantsSelector;
            emigrantsSelector.Successor                    = null;
            uniformSubScopesProcessor5.Successor           = migrator;
            migrator.Successor = uniformSubScopesProcessor6;
            uniformSubScopesProcessor6.Operator  = immigrationReplacer;
            uniformSubScopesProcessor6.Successor = generationsComparator;
            generationsComparator.Successor      = analyzer2;
            analyzer2.Successor = generationsTerminationCondition;
            generationsTerminationCondition.TrueBranch  = null;
            generationsTerminationCondition.FalseBranch = uniformSubScopesProcessor1;
            generationsTerminationCondition.Successor   = null;
            #endregion
        }
Esempio n. 4
0
        private void Initialize()
        {
            #region Create parameters
            Parameters.Add(new ValueLookupParameter <IRandom>("Random", "A pseudo random number generator."));
            Parameters.Add(new ValueLookupParameter <BoolValue>("Maximization", "True if the problem is a maximization problem, otherwise false."));
            Parameters.Add(new ScopeTreeLookupParameter <DoubleValue>("Quality", "The value which represents the quality of a solution."));
            Parameters.Add(new ValueLookupParameter <IOperator>("Selector", "The operator used to select solutions for reproduction."));
            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>("Elites", "The numer of elite solutions which are kept in each generation."));
            Parameters.Add(new ValueLookupParameter <BoolValue>("ReevaluateElites", "Flag to determine if elite individuals should be reevaluated (i.e., if stochastic fitness functions are used.)"));
            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 ValueLookupParameter <IntValue>("EvaluatedSolutions", "The number of times solutions have been evaluated."));
            Parameters.Add(new ValueLookupParameter <IntValue>("PopulationSize", "The size of the population."));
            Parameters.Add(new ValueLookupParameter <IntValue>("MinimumPopulationSize", "The minimum size of the population of solutions."));
            Parameters.Add(new ValueLookupParameter <IntValue>("MaximumPopulationSize", "The maximum size of the population of solutions."));
            Parameters.Add(new ValueLookupParameter <DoubleValue>("ComparisonFactor", "The comparison factor."));
            Parameters.Add(new ValueLookupParameter <IntValue>("Effort", "The maximum number of offspring created in each generation."));
            Parameters.Add(new ValueLookupParameter <IntValue>("BatchSize", "The number of children that should be created during one iteration of the offspring creation process."));
            Parameters.Add(new ValueLookupParameter <ISolutionSimilarityCalculator>("SimilarityCalculator", "The operator used to calculate the similarity between two solutions."));
            Parameters.Add(new ScopeParameter("CurrentScope", "The current scope which represents a population of solutions on which the genetic algorithm should be applied."));
            #endregion

            #region Create operators
            VariableCreator                  variableCreator           = new VariableCreator();
            Assigner                         assigner1                 = new Assigner();
            ResultsCollector                 resultsCollector          = new ResultsCollector();
            Placeholder                      analyzer1                 = new Placeholder();
            Placeholder                      selector                  = new Placeholder();
            SubScopesProcessor               subScopesProcessor1       = new SubScopesProcessor();
            ChildrenCreator                  childrenCreator           = new ChildrenCreator();
            UniformSubScopesProcessor        uniformSubScopesProcessor = new UniformSubScopesProcessor();
            Placeholder                      crossover                 = new Placeholder();
            StochasticBranch                 stochasticBranch          = new StochasticBranch();
            Placeholder                      mutator   = new Placeholder();
            Placeholder                      evaluator = new Placeholder();
            WeightedParentsQualityComparator weightedParentsQualityComparator = new WeightedParentsQualityComparator();
            SubScopesRemover                 subScopesRemover             = new SubScopesRemover();
            IntCounter                       intCounter1                  = new IntCounter();
            IntCounter                       intCounter2                  = new IntCounter();
            ConditionalSelector              conditionalSelector          = new ConditionalSelector();
            RightReducer                     rightReducer1                = new RightReducer();
            DuplicatesSelector               duplicateSelector            = new DuplicatesSelector();
            LeftReducer                      leftReducer1                 = new LeftReducer();
            ProgressiveOffspringPreserver    progressiveOffspringSelector = new ProgressiveOffspringPreserver();
            SubScopesCounter                 subScopesCounter2            = new SubScopesCounter();
            ExpressionCalculator             calculator1                  = new ExpressionCalculator();
            ConditionalBranch                conditionalBranch1           = new ConditionalBranch();
            Comparator                       comparator1                  = new Comparator();
            ConditionalBranch                conditionalBranch2           = new ConditionalBranch();
            LeftReducer                      leftReducer2                 = new LeftReducer();
            SubScopesProcessor               subScopesProcessor2          = new SubScopesProcessor();
            BestSelector                     bestSelector                 = new BestSelector();
            RightReducer                     rightReducer2                = new RightReducer();
            ScopeCleaner                     scopeCleaner                 = new ScopeCleaner();
            ScopeRestorer                    scopeRestorer                = new ScopeRestorer();
            MergingReducer                   mergingReducer               = new MergingReducer();
            IntCounter                       intCounter3                  = new IntCounter();
            SubScopesCounter                 subScopesCounter3            = new SubScopesCounter();
            ExpressionCalculator             calculator2                  = new ExpressionCalculator();
            Comparator                       comparator2                  = new Comparator();
            ConditionalBranch                conditionalBranch3           = new ConditionalBranch();
            Placeholder                      analyzer2                  = new Placeholder();
            Comparator                       comparator3                = new Comparator();
            ConditionalBranch                conditionalBranch4         = new ConditionalBranch();
            Comparator                       comparator4                = new Comparator();
            ConditionalBranch                conditionalBranch5         = new ConditionalBranch();
            Assigner                         assigner3                  = new Assigner();
            Assigner                         assigner4                  = new Assigner();
            Assigner                         assigner5                  = new Assigner();
            ConditionalBranch                reevaluateElitesBranch     = new ConditionalBranch();
            UniformSubScopesProcessor        uniformSubScopesProcessor2 = new UniformSubScopesProcessor();
            Placeholder                      evaluator2                 = new Placeholder();
            SubScopesCounter                 subScopesCounter4          = new SubScopesCounter();

            variableCreator.CollectedValues.Add(new ValueParameter <IntValue>("Generations", new IntValue(0))); // Class RAPGA expects this to be called Generations
            variableCreator.CollectedValues.Add(new ValueParameter <IntValue>("CurrentPopulationSize", new IntValue(0)));
            variableCreator.CollectedValues.Add(new ValueParameter <IntValue>("NumberOfCreatedOffspring", new IntValue(0)));
            variableCreator.CollectedValues.Add(new ValueParameter <IntValue>("NumberOfSuccessfulOffspring", new IntValue(0)));
            variableCreator.CollectedValues.Add(new ValueParameter <ScopeList>("OffspringList", new ScopeList()));

            assigner1.Name = "Initialize CurrentPopulationSize";
            assigner1.LeftSideParameter.ActualName  = "CurrentPopulationSize";
            assigner1.RightSideParameter.ActualName = PopulationSizeParameter.Name;

            resultsCollector.CollectedValues.Add(new LookupParameter <IntValue>("Generations"));
            resultsCollector.CollectedValues.Add(new LookupParameter <IntValue>("CurrentPopulationSize"));
            resultsCollector.ResultsParameter.ActualName = "Results";

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

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

            childrenCreator.ParentsPerChild = new IntValue(2);

            uniformSubScopesProcessor.Parallel.Value = true;

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

            stochasticBranch.ProbabilityParameter.ActualName = "MutationProbability";
            stochasticBranch.RandomParameter.ActualName      = "Random";

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

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

            weightedParentsQualityComparator.ComparisonFactorParameter.ActualName = ComparisonFactorParameter.Name;
            weightedParentsQualityComparator.LeftSideParameter.ActualName         = QualityParameter.Name;
            weightedParentsQualityComparator.MaximizationParameter.ActualName     = MaximizationParameter.Name;
            weightedParentsQualityComparator.RightSideParameter.ActualName        = QualityParameter.Name;
            weightedParentsQualityComparator.ResultParameter.ActualName           = "SuccessfulOffspring";

            subScopesRemover.RemoveAllSubScopes = true;

            intCounter1.Name = "Increment NumberOfCreatedOffspring";
            intCounter1.ValueParameter.ActualName = "NumberOfCreatedOffspring";
            intCounter1.Increment = null;
            intCounter1.IncrementParameter.ActualName = BatchSizeParameter.Name;

            intCounter2.Name = "Increment EvaluatedSolutions";
            intCounter2.ValueParameter.ActualName = EvaluatedSolutionsParameter.Name;
            intCounter2.Increment = null;
            intCounter2.IncrementParameter.ActualName = BatchSizeParameter.Name;

            conditionalSelector.ConditionParameter.ActualName = "SuccessfulOffspring";
            conditionalSelector.ConditionParameter.Depth      = 1;
            conditionalSelector.CopySelected.Value            = false;

            duplicateSelector.CopySelected.Value = false;

            progressiveOffspringSelector.OffspringListParameter.ActualName         = "OffspringList";
            progressiveOffspringSelector.ElitesParameter.ActualName                = ElitesParameter.Name;
            progressiveOffspringSelector.MaximumPopulationSizeParameter.ActualName = MaximumPopulationSizeParameter.Name;

            subScopesCounter2.Name = "Count Successful Offspring";
            subScopesCounter2.ValueParameter.ActualName = "NumberOfSuccessfulOffspring";

            calculator1.Name = "NumberOfSuccessfulOffspring == MaximumPopulationSize - Elites";
            calculator1.CollectedValues.Add(new ValueLookupParameter <IntValue>("NumberOfSuccessfulOffspring"));
            calculator1.CollectedValues.Add(new ValueLookupParameter <IntValue>("MaximumPopulationSize"));
            calculator1.CollectedValues.Add(new ValueLookupParameter <IntValue>("Elites"));
            calculator1.ExpressionParameter.Value            = new StringValue("NumberOfSuccessfulOffspring MaximumPopulationSize Elites - ==");
            calculator1.ExpressionResultParameter.ActualName = "Break";

            conditionalBranch1.Name = "Break?";
            conditionalBranch1.ConditionParameter.ActualName = "Break";

            comparator1.Name       = "NumberOfCreatedOffspring >= Effort";
            comparator1.Comparison = new Comparison(ComparisonType.GreaterOrEqual);
            comparator1.LeftSideParameter.ActualName  = "NumberOfCreatedOffspring";
            comparator1.RightSideParameter.ActualName = EffortParameter.Name;
            comparator1.ResultParameter.ActualName    = "Break";

            conditionalBranch2.Name = "Break?";
            conditionalBranch2.ConditionParameter.ActualName = "Break";

            bestSelector.CopySelected = new BoolValue(false);
            bestSelector.MaximizationParameter.ActualName = MaximizationParameter.Name;
            bestSelector.NumberOfSelectedSubScopesParameter.ActualName = "Elites";
            bestSelector.QualityParameter.ActualName = QualityParameter.Name;

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

            subScopesCounter3.Name = "Update CurrentPopulationSize";
            subScopesCounter3.ValueParameter.ActualName = "CurrentPopulationSize";
            subScopesCounter3.AccumulateParameter.Value = new BoolValue(false);

            calculator2.Name = "Evaluate ActualSelectionPressure";
            calculator2.CollectedValues.Add(new ValueLookupParameter <IntValue>("NumberOfCreatedOffspring"));
            calculator2.CollectedValues.Add(new ValueLookupParameter <IntValue>("Elites"));
            calculator2.CollectedValues.Add(new ValueLookupParameter <IntValue>("CurrentPopulationSize"));
            calculator2.ExpressionParameter.Value            = new StringValue("NumberOfCreatedOffspring Elites + CurrentPopulationSize /");
            calculator2.ExpressionResultParameter.ActualName = "ActualSelectionPressure";

            comparator2.Name       = "CurrentPopulationSize < 1";
            comparator2.Comparison = new Comparison(ComparisonType.Less);
            comparator2.LeftSideParameter.ActualName = "CurrentPopulationSize";
            comparator2.RightSideParameter.Value     = new IntValue(1);
            comparator2.ResultParameter.ActualName   = "Terminate";

            conditionalBranch3.Name = "Terminate?";
            conditionalBranch3.ConditionParameter.ActualName = "Terminate";

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

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

            conditionalBranch4.Name = "Terminate?";
            conditionalBranch4.ConditionParameter.ActualName = "Terminate";

            comparator4.Name       = "CurrentPopulationSize < MinimumPopulationSize";
            comparator4.Comparison = new Comparison(ComparisonType.Less);
            comparator4.LeftSideParameter.ActualName  = "CurrentPopulationSize";
            comparator4.RightSideParameter.ActualName = MinimumPopulationSizeParameter.Name;
            comparator4.ResultParameter.ActualName    = "Terminate";

            conditionalBranch5.Name = "Terminate?";
            conditionalBranch5.ConditionParameter.ActualName = "Terminate";

            assigner3.Name = "Reset NumberOfCreatedOffspring";
            assigner3.LeftSideParameter.ActualName = "NumberOfCreatedOffspring";
            assigner3.RightSideParameter.Value     = new IntValue(0);

            assigner4.Name = "Reset NumberOfSuccessfulOffspring";
            assigner4.LeftSideParameter.ActualName = "NumberOfSuccessfulOffspring";
            assigner4.RightSideParameter.Value     = new IntValue(0);

            assigner5.Name = "Reset OffspringList";
            assigner5.LeftSideParameter.ActualName = "OffspringList";
            assigner5.RightSideParameter.Value     = new ScopeList();

            reevaluateElitesBranch.ConditionParameter.ActualName = "ReevaluateElites";
            reevaluateElitesBranch.Name = "Reevaluate elites ?";

            uniformSubScopesProcessor2.Parallel.Value = true;

            evaluator2.Name = "Evaluator (placeholder)";
            evaluator2.OperatorParameter.ActualName = EvaluatorParameter.Name;

            subScopesCounter4.Name = "Increment EvaluatedSolutions";
            subScopesCounter4.ValueParameter.ActualName = EvaluatedSolutionsParameter.Name;
            #endregion

            #region Create operator graph
            OperatorGraph.InitialOperator = variableCreator;
            variableCreator.Successor     = assigner1;
            assigner1.Successor           = resultsCollector;
            resultsCollector.Successor    = analyzer1;
            analyzer1.Successor           = selector;
            selector.Successor            = subScopesProcessor1;
            subScopesProcessor1.Operators.Add(new EmptyOperator());
            subScopesProcessor1.Operators.Add(childrenCreator);
            subScopesProcessor1.Successor       = calculator1;
            childrenCreator.Successor           = uniformSubScopesProcessor;
            uniformSubScopesProcessor.Operator  = crossover;
            uniformSubScopesProcessor.Successor = intCounter1;
            crossover.Successor           = stochasticBranch;
            stochasticBranch.FirstBranch  = mutator;
            stochasticBranch.SecondBranch = null;
            mutator.Successor             = null;
            stochasticBranch.Successor    = evaluator;
            evaluator.Successor           = weightedParentsQualityComparator;
            weightedParentsQualityComparator.Successor = subScopesRemover;
            intCounter1.Successor                  = intCounter2;
            intCounter2.Successor                  = conditionalSelector;
            conditionalSelector.Successor          = rightReducer1;
            rightReducer1.Successor                = duplicateSelector;
            duplicateSelector.Successor            = leftReducer1;
            leftReducer1.Successor                 = progressiveOffspringSelector;
            progressiveOffspringSelector.Successor = subScopesCounter2;
            calculator1.Successor                  = conditionalBranch1;
            conditionalBranch1.FalseBranch         = comparator1;
            conditionalBranch1.TrueBranch          = subScopesProcessor2;
            comparator1.Successor                  = conditionalBranch2;
            conditionalBranch2.FalseBranch         = leftReducer2;
            conditionalBranch2.TrueBranch          = subScopesProcessor2;
            leftReducer2.Successor                 = selector;
            subScopesProcessor2.Operators.Add(bestSelector);
            subScopesProcessor2.Operators.Add(scopeCleaner);
            subScopesProcessor2.Successor        = mergingReducer;
            bestSelector.Successor               = rightReducer2;
            rightReducer2.Successor              = reevaluateElitesBranch;
            reevaluateElitesBranch.TrueBranch    = uniformSubScopesProcessor2;
            uniformSubScopesProcessor2.Operator  = evaluator2;
            uniformSubScopesProcessor2.Successor = subScopesCounter4;
            evaluator2.Successor               = null;
            subScopesCounter4.Successor        = null;
            reevaluateElitesBranch.FalseBranch = null;
            reevaluateElitesBranch.Successor   = null;
            scopeCleaner.Successor             = scopeRestorer;
            mergingReducer.Successor           = intCounter3;
            intCounter3.Successor              = subScopesCounter3;
            subScopesCounter3.Successor        = calculator2;
            calculator2.Successor              = comparator2;
            comparator2.Successor              = conditionalBranch3;
            conditionalBranch3.FalseBranch     = analyzer2;
            conditionalBranch3.TrueBranch      = null;
            analyzer2.Successor            = comparator3;
            comparator3.Successor          = conditionalBranch4;
            conditionalBranch4.FalseBranch = comparator4;
            conditionalBranch4.TrueBranch  = null;
            conditionalBranch4.Successor   = null;
            comparator4.Successor          = conditionalBranch5;
            conditionalBranch5.FalseBranch = assigner3;
            conditionalBranch5.TrueBranch  = null;
            conditionalBranch5.Successor   = null;
            assigner3.Successor            = assigner4;
            assigner4.Successor            = assigner5;
            assigner5.Successor            = selector;

            #endregion
        }
Esempio n. 5
0
        private void Initialize()
        {
            #region Create parameters
            Parameters.Add(new ValueLookupParameter <IRandom>("Random", "A pseudo random number generator."));
            Parameters.Add(new ValueLookupParameter <BoolValue>("Maximization", "True if the problem is a maximization problem, otherwise false."));
            Parameters.Add(new ScopeTreeLookupParameter <DoubleValue>("Quality", "The value which represents the quality of a solution."));
            Parameters.Add(new ValueLookupParameter <DoubleValue>("BestKnownQuality", "The best known quality value found so far."));
            Parameters.Add(new ValueLookupParameter <IntValue>("PopulationSize", "µ (mu) - the size of the population."));
            Parameters.Add(new ValueLookupParameter <IntValue>("ParentsPerChild", "ρ (rho) - how many parents should be recombined."));
            Parameters.Add(new ValueLookupParameter <IntValue>("Children", "λ (lambda) - the size of the offspring population."));
            Parameters.Add(new ValueLookupParameter <IntValue>("MaximumGenerations", "The maximum number of generations which should be processed."));
            Parameters.Add(new ValueLookupParameter <BoolValue>("PlusSelection", "True for plus selection (elitist population), false for comma selection (non-elitist population)."));
            Parameters.Add(new ValueLookupParameter <BoolValue>("ReevaluateElites", "Flag to determine if elite individuals should be reevaluated (i.e., if stochastic fitness functions are used.)"));
            Parameters.Add(new ValueLookupParameter <IOperator>("Mutator", "The operator used to mutate solutions."));
            Parameters.Add(new ValueLookupParameter <IOperator>("Recombinator", "The operator used to cross 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 <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 ScopeParameter("CurrentScope", "The current scope which represents a population of solutions on which the EvolutionStrategy should be applied."));
            Parameters.Add(new ValueLookupParameter <IOperator>("StrategyParameterManipulator", "The operator to mutate the endogeneous strategy parameters."));
            Parameters.Add(new ValueLookupParameter <IOperator>("StrategyParameterCrossover", "The operator to cross the endogeneous strategy parameters."));
            #endregion

            #region Create operators
            VariableCreator  variableCreator                       = new VariableCreator();
            ResultsCollector resultsCollector1                     = new ResultsCollector();
            Placeholder      analyzer1                             = new Placeholder();
            WithoutRepeatingBatchedRandomSelector selector         = new WithoutRepeatingBatchedRandomSelector();
            SubScopesProcessor        subScopesProcessor1          = new SubScopesProcessor();
            Comparator                useRecombinationComparator   = new Comparator();
            ConditionalBranch         useRecombinationBranch       = new ConditionalBranch();
            ChildrenCreator           childrenCreator              = new ChildrenCreator();
            UniformSubScopesProcessor uniformSubScopesProcessor1   = new UniformSubScopesProcessor();
            Placeholder               recombinator                 = new Placeholder();
            Placeholder               strategyRecombinator         = new Placeholder();
            Placeholder               strategyMutator1             = new Placeholder();
            Placeholder               mutator1                     = new Placeholder();
            SubScopesRemover          subScopesRemover             = new SubScopesRemover();
            UniformSubScopesProcessor uniformSubScopesProcessor2   = new UniformSubScopesProcessor();
            Placeholder               strategyMutator2             = new Placeholder();
            Placeholder               mutator2                     = new Placeholder();
            UniformSubScopesProcessor uniformSubScopesProcessor3   = new UniformSubScopesProcessor();
            Placeholder               evaluator                    = new Placeholder();
            SubScopesCounter          subScopesCounter             = new SubScopesCounter();
            ConditionalBranch         plusOrCommaReplacementBranch = new ConditionalBranch();
            MergingReducer            plusReplacement              = new MergingReducer();
            RightReducer              commaReplacement             = new RightReducer();
            BestSelector              bestSelector                 = new BestSelector();
            RightReducer              rightReducer                 = new RightReducer();
            IntCounter                intCounter                   = new IntCounter();
            Comparator                comparator                   = new Comparator();
            Placeholder               analyzer2                    = new Placeholder();
            ConditionalBranch         conditionalBranch            = new ConditionalBranch();
            ConditionalBranch         reevaluateElitesBranch       = new ConditionalBranch();
            SubScopesProcessor        subScopesProcessor2          = new SubScopesProcessor();
            UniformSubScopesProcessor uniformSubScopesProcessor4   = new UniformSubScopesProcessor();
            Placeholder               evaluator2                   = new Placeholder();
            SubScopesCounter          subScopesCounter2            = new SubScopesCounter();


            variableCreator.CollectedValues.Add(new ValueParameter <IntValue>("Generations", new IntValue(0))); // Class EvolutionStrategy expects this to be called Generations

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

            analyzer1.Name = "Analyzer (placeholder)";
            analyzer1.OperatorParameter.ActualName = AnalyzerParameter.Name;

            selector.Name = "ES Random Selector";
            selector.RandomParameter.ActualName          = RandomParameter.Name;
            selector.ParentsPerChildParameter.ActualName = ParentsPerChildParameter.Name;
            selector.ChildrenParameter.ActualName        = ChildrenParameter.Name;

            useRecombinationComparator.Name = "ParentsPerChild > 1";
            useRecombinationComparator.LeftSideParameter.ActualName = ParentsPerChildParameter.Name;
            useRecombinationComparator.RightSideParameter.Value     = new IntValue(1);
            useRecombinationComparator.Comparison = new Comparison(ComparisonType.Greater);
            useRecombinationComparator.ResultParameter.ActualName = "UseRecombination";

            useRecombinationBranch.Name = "Use Recombination?";
            useRecombinationBranch.ConditionParameter.ActualName = "UseRecombination";

            childrenCreator.ParentsPerChild = null;
            childrenCreator.ParentsPerChildParameter.ActualName = ParentsPerChildParameter.Name;

            recombinator.Name = "Recombinator (placeholder)";
            recombinator.OperatorParameter.ActualName = RecombinatorParameter.Name;

            strategyRecombinator.Name = "Strategy Parameter Recombinator (placeholder)";
            strategyRecombinator.OperatorParameter.ActualName = StrategyParameterCrossoverParameter.Name;

            strategyMutator1.Name = "Strategy Parameter Manipulator (placeholder)";
            strategyMutator1.OperatorParameter.ActualName = StrategyParameterManipulatorParameter.Name;

            mutator1.Name = "Mutator (placeholder)";
            mutator1.OperatorParameter.ActualName = MutatorParameter.Name;

            subScopesRemover.RemoveAllSubScopes = true;

            strategyMutator2.Name = "Strategy Parameter Manipulator (placeholder)";
            strategyMutator2.OperatorParameter.ActualName = StrategyParameterManipulatorParameter.Name;

            mutator2.Name = "Mutator (placeholder)";
            mutator2.OperatorParameter.ActualName = MutatorParameter.Name;

            uniformSubScopesProcessor3.Parallel.Value = true;

            evaluator.Name = "Evaluator (placeholder)";
            evaluator.OperatorParameter.ActualName = EvaluatorParameter.Name;

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

            plusOrCommaReplacementBranch.ConditionParameter.ActualName = PlusSelectionParameter.Name;

            bestSelector.CopySelected = new BoolValue(false);
            bestSelector.MaximizationParameter.ActualName = MaximizationParameter.Name;
            bestSelector.NumberOfSelectedSubScopesParameter.ActualName = PopulationSizeParameter.Name;
            bestSelector.QualityParameter.ActualName = QualityParameter.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 (placeholder)";
            analyzer2.OperatorParameter.ActualName = AnalyzerParameter.Name;

            conditionalBranch.ConditionParameter.ActualName = "Terminate";

            reevaluateElitesBranch.ConditionParameter.ActualName = "ReevaluateElites";
            reevaluateElitesBranch.Name = "Reevaluate elites ?";

            uniformSubScopesProcessor4.Parallel.Value = true;

            evaluator2.Name = "Evaluator (placeholder)";
            evaluator2.OperatorParameter.ActualName = EvaluatorParameter.Name;

            subScopesCounter2.Name = "Increment EvaluatedSolutions";
            subScopesCounter2.ValueParameter.ActualName = EvaluatedSolutionsParameter.Name;
            #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(useRecombinationComparator);
            subScopesProcessor1.Successor        = plusOrCommaReplacementBranch;
            useRecombinationComparator.Successor = useRecombinationBranch;
            useRecombinationBranch.TrueBranch    = childrenCreator;
            useRecombinationBranch.FalseBranch   = uniformSubScopesProcessor2;
            useRecombinationBranch.Successor     = uniformSubScopesProcessor3;
            childrenCreator.Successor            = uniformSubScopesProcessor1;
            uniformSubScopesProcessor1.Operator  = recombinator;
            uniformSubScopesProcessor1.Successor = null;
            recombinator.Successor               = strategyRecombinator;
            strategyRecombinator.Successor       = strategyMutator1;
            strategyMutator1.Successor           = mutator1;
            mutator1.Successor                   = subScopesRemover;
            subScopesRemover.Successor           = null;
            uniformSubScopesProcessor2.Operator  = strategyMutator2;
            uniformSubScopesProcessor2.Successor = null;
            strategyMutator2.Successor           = mutator2;
            mutator2.Successor                   = null;
            uniformSubScopesProcessor3.Operator  = evaluator;
            uniformSubScopesProcessor3.Successor = subScopesCounter;
            evaluator.Successor                  = null;
            subScopesCounter.Successor           = null;

            plusOrCommaReplacementBranch.TrueBranch = reevaluateElitesBranch;
            reevaluateElitesBranch.TrueBranch       = subScopesProcessor2;
            reevaluateElitesBranch.FalseBranch      = null;
            subScopesProcessor2.Operators.Add(uniformSubScopesProcessor4);
            subScopesProcessor2.Operators.Add(new EmptyOperator());
            uniformSubScopesProcessor4.Operator  = evaluator2;
            uniformSubScopesProcessor4.Successor = subScopesCounter2;
            subScopesCounter2.Successor          = null;
            reevaluateElitesBranch.Successor     = plusReplacement;

            plusOrCommaReplacementBranch.FalseBranch = commaReplacement;
            plusOrCommaReplacementBranch.Successor   = bestSelector;
            bestSelector.Successor        = rightReducer;
            rightReducer.Successor        = intCounter;
            intCounter.Successor          = comparator;
            comparator.Successor          = analyzer2;
            analyzer2.Successor           = conditionalBranch;
            conditionalBranch.FalseBranch = selector;
            conditionalBranch.TrueBranch  = null;
            conditionalBranch.Successor   = null;
            #endregion
        }
        private void Initialize()
        {
            #region Create parameters
            Parameters.Add(new ValueLookupParameter <IRandom>("Random", "A pseudo random number generator."));
            Parameters.Add(new ValueLookupParameter <BoolValue>("Maximization", "True if the problem is a maximization problem, otherwise false."));
            Parameters.Add(new ScopeTreeLookupParameter <DoubleValue>("Quality", "The value which represents the quality of a solution."));
            Parameters.Add(new ValueLookupParameter <IOperator>("Selector", "The operator used to select solutions for reproduction."));
            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 LookupParameter <IntValue>("EvaluatedSolutions", "The number of evaluated solutions."));
            Parameters.Add(new ValueLookupParameter <IntValue>("Elites", "The numer of elite solutions which are kept in each generation."));
            Parameters.Add(new ValueLookupParameter <BoolValue>("ReevaluateElites", "Flag to determine if elite individuals should be reevaluated (i.e., if stochastic fitness functions are used.)"));
            Parameters.Add(new LookupParameter <DoubleValue>("ComparisonFactor", "The comparison factor is used to determine whether the offspring should be compared to the better parent, the worse parent or a quality value linearly interpolated between them. It is in the range [0;1]."));
            Parameters.Add(new LookupParameter <DoubleValue>("CurrentSuccessRatio", "The current success ratio."));
            Parameters.Add(new ValueLookupParameter <DoubleValue>("SuccessRatio", "The ratio of successful to total children that should be achieved."));
            Parameters.Add(new LookupParameter <DoubleValue>("SelectionPressure", "The actual selection pressure."));
            Parameters.Add(new ValueLookupParameter <DoubleValue>("MaximumSelectionPressure", "The maximum selection pressure that terminates the algorithm."));
            Parameters.Add(new ValueLookupParameter <BoolValue>("OffspringSelectionBeforeMutation", "True if the offspring selection step should be applied before mutation, false if it should be applied after mutation."));
            Parameters.Add(new ValueLookupParameter <BoolValue>("FillPopulationWithParents", "True if the population should be filled with parent individual or false if worse children should be used when the maximum selection pressure is exceeded."));
            #endregion

            #region Create operators
            Placeholder                      selector                   = new Placeholder();
            SubScopesProcessor               subScopesProcessor1        = new SubScopesProcessor();
            ChildrenCreator                  childrenCreator            = new ChildrenCreator();
            ConditionalBranch                osBeforeMutationBranch     = new ConditionalBranch();
            UniformSubScopesProcessor        uniformSubScopesProcessor1 = new UniformSubScopesProcessor();
            Placeholder                      crossover1                 = new Placeholder();
            UniformSubScopesProcessor        uniformSubScopesProcessor2 = new UniformSubScopesProcessor();
            Placeholder                      evaluator1                 = new Placeholder();
            SubScopesCounter                 subScopesCounter1          = new SubScopesCounter();
            WeightedParentsQualityComparator qualityComparer1           = new WeightedParentsQualityComparator();
            SubScopesRemover                 subScopesRemover1          = new SubScopesRemover();
            UniformSubScopesProcessor        uniformSubScopesProcessor3 = new UniformSubScopesProcessor();
            StochasticBranch                 mutationBranch1            = new StochasticBranch();
            Placeholder                      mutator1                   = new Placeholder();
            VariableCreator                  variableCreator1           = new VariableCreator();
            VariableCreator                  variableCreator2           = new VariableCreator();
            ConditionalSelector              conditionalSelector        = new ConditionalSelector();
            SubScopesProcessor               subScopesProcessor2        = new SubScopesProcessor();
            UniformSubScopesProcessor        uniformSubScopesProcessor4 = new UniformSubScopesProcessor();
            Placeholder                      evaluator2                 = new Placeholder();
            SubScopesCounter                 subScopesCounter2          = new SubScopesCounter();
            MergingReducer                   mergingReducer1            = new MergingReducer();
            UniformSubScopesProcessor        uniformSubScopesProcessor5 = new UniformSubScopesProcessor();
            Placeholder                      crossover2                 = new Placeholder();
            StochasticBranch                 mutationBranch2            = new StochasticBranch();
            Placeholder                      mutator2                   = new Placeholder();
            UniformSubScopesProcessor        uniformSubScopesProcessor6 = new UniformSubScopesProcessor();
            Placeholder                      evaluator3                 = new Placeholder();
            SubScopesCounter                 subScopesCounter3          = new SubScopesCounter();
            WeightedParentsQualityComparator qualityComparer2           = new WeightedParentsQualityComparator();
            SubScopesRemover                 subScopesRemover2          = new SubScopesRemover();
            OffspringSelector                offspringSelector          = new OffspringSelector();
            SubScopesProcessor               subScopesProcessor3        = new SubScopesProcessor();
            BestSelector                     bestSelector               = new BestSelector();
            WorstSelector                    worstSelector              = new WorstSelector();
            RightReducer                     rightReducer               = new RightReducer();
            LeftReducer                      leftReducer                = new LeftReducer();
            MergingReducer                   mergingReducer2            = new MergingReducer();
            ConditionalBranch                reevaluateElitesBranch     = new ConditionalBranch();
            UniformSubScopesProcessor        uniformSubScopesProcessor7 = new UniformSubScopesProcessor();
            Placeholder                      evaluator4                 = new Placeholder();
            SubScopesCounter                 subScopesCounter4          = new SubScopesCounter();

            selector.Name = "Selector (placeholder)";
            selector.OperatorParameter.ActualName = SelectorParameter.Name;

            childrenCreator.ParentsPerChild = new IntValue(2);

            osBeforeMutationBranch.Name = "Apply OS before mutation?";
            osBeforeMutationBranch.ConditionParameter.ActualName = OffspringSelectionBeforeMutationParameter.Name;

            crossover1.Name = "Crossover (placeholder)";
            crossover1.OperatorParameter.ActualName = CrossoverParameter.Name;

            uniformSubScopesProcessor2.Parallel.Value = true;

            evaluator1.Name = "Evaluator (placeholder)";
            evaluator1.OperatorParameter.ActualName = EvaluatorParameter.Name;

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

            qualityComparer1.ComparisonFactorParameter.ActualName = ComparisonFactorParameter.Name;
            qualityComparer1.LeftSideParameter.ActualName         = QualityParameter.Name;
            qualityComparer1.MaximizationParameter.ActualName     = MaximizationParameter.Name;
            qualityComparer1.RightSideParameter.ActualName        = QualityParameter.Name;
            qualityComparer1.ResultParameter.ActualName           = "SuccessfulOffspring";

            subScopesRemover1.RemoveAllSubScopes = true;

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

            mutator1.Name = "Mutator (placeholder)";
            mutator1.OperatorParameter.ActualName = MutatorParameter.Name;

            variableCreator1.Name = "MutatedOffspring = true";
            variableCreator1.CollectedValues.Add(new ValueParameter <BoolValue>("MutatedOffspring", null, new BoolValue(true), false));

            variableCreator2.Name = "MutatedOffspring = false";
            variableCreator2.CollectedValues.Add(new ValueParameter <BoolValue>("MutatedOffspring", null, new BoolValue(false), false));

            conditionalSelector.ConditionParameter.ActualName = "MutatedOffspring";
            conditionalSelector.ConditionParameter.Depth      = 1;
            conditionalSelector.CopySelected.Value            = false;

            uniformSubScopesProcessor4.Parallel.Value = true;

            evaluator2.Name = "Evaluator (placeholder)";
            evaluator2.OperatorParameter.ActualName = EvaluatorParameter.Name;

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

            crossover2.Name = "Crossover (placeholder)";
            crossover2.OperatorParameter.ActualName = CrossoverParameter.Name;

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

            mutator2.Name = "Mutator (placeholder)";
            mutator2.OperatorParameter.ActualName = MutatorParameter.Name;

            uniformSubScopesProcessor6.Parallel.Value = true;

            evaluator3.Name = "Evaluator (placeholder)";
            evaluator3.OperatorParameter.ActualName = EvaluatorParameter.Name;

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

            qualityComparer2.ComparisonFactorParameter.ActualName = ComparisonFactorParameter.Name;
            qualityComparer2.LeftSideParameter.ActualName         = QualityParameter.Name;
            qualityComparer2.MaximizationParameter.ActualName     = MaximizationParameter.Name;
            qualityComparer2.RightSideParameter.ActualName        = QualityParameter.Name;
            qualityComparer2.ResultParameter.ActualName           = "SuccessfulOffspring";

            subScopesRemover2.RemoveAllSubScopes = true;

            offspringSelector.CurrentSuccessRatioParameter.ActualName        = CurrentSuccessRatioParameter.Name;
            offspringSelector.MaximumSelectionPressureParameter.ActualName   = MaximumSelectionPressureParameter.Name;
            offspringSelector.SelectionPressureParameter.ActualName          = SelectionPressureParameter.Name;
            offspringSelector.SuccessRatioParameter.ActualName               = SuccessRatioParameter.Name;
            offspringSelector.OffspringPopulationParameter.ActualName        = "OffspringPopulation";
            offspringSelector.OffspringPopulationWinnersParameter.ActualName = "OffspringPopulationWinners";
            offspringSelector.SuccessfulOffspringParameter.ActualName        = "SuccessfulOffspring";
            offspringSelector.FillPopulationWithParentsParameter.ActualName  = FillPopulationWithParentsParameter.Name;

            bestSelector.CopySelected = new BoolValue(false);
            bestSelector.MaximizationParameter.ActualName = MaximizationParameter.Name;
            bestSelector.NumberOfSelectedSubScopesParameter.ActualName = ElitesParameter.Name;
            bestSelector.QualityParameter.ActualName = QualityParameter.Name;

            worstSelector.CopySelected = new BoolValue(false);
            worstSelector.MaximizationParameter.ActualName = MaximizationParameter.Name;
            worstSelector.NumberOfSelectedSubScopesParameter.ActualName = ElitesParameter.Name;
            worstSelector.QualityParameter.ActualName = QualityParameter.Name;

            reevaluateElitesBranch.ConditionParameter.ActualName = "ReevaluateElites";
            reevaluateElitesBranch.Name = "Reevaluate elites ?";

            uniformSubScopesProcessor7.Parallel.Value = true;

            evaluator4.Name = "Evaluator (placeholder)";
            evaluator4.OperatorParameter.ActualName = EvaluatorParameter.Name;

            subScopesCounter4.Name = "Increment EvaluatedSolutions";
            subScopesCounter4.ValueParameter.ActualName = EvaluatedSolutionsParameter.Name;
            #endregion

            #region Create operator graph
            OperatorGraph.InitialOperator = selector;
            selector.Successor            = subScopesProcessor1;
            subScopesProcessor1.Operators.Add(new EmptyOperator());
            subScopesProcessor1.Operators.Add(childrenCreator);
            subScopesProcessor1.Successor        = offspringSelector;
            childrenCreator.Successor            = osBeforeMutationBranch;
            osBeforeMutationBranch.TrueBranch    = uniformSubScopesProcessor1;
            osBeforeMutationBranch.FalseBranch   = uniformSubScopesProcessor5;
            osBeforeMutationBranch.Successor     = null;
            uniformSubScopesProcessor1.Operator  = crossover1;
            uniformSubScopesProcessor1.Successor = uniformSubScopesProcessor2;
            crossover1.Successor = null;
            uniformSubScopesProcessor2.Operator  = evaluator1;
            uniformSubScopesProcessor2.Successor = subScopesCounter1;
            evaluator1.Successor                 = qualityComparer1;
            qualityComparer1.Successor           = subScopesRemover1;
            subScopesRemover1.Successor          = null;
            subScopesCounter1.Successor          = uniformSubScopesProcessor3;
            uniformSubScopesProcessor3.Operator  = mutationBranch1;
            uniformSubScopesProcessor3.Successor = conditionalSelector;
            mutationBranch1.FirstBranch          = mutator1;
            mutationBranch1.SecondBranch         = variableCreator2;
            mutationBranch1.Successor            = null;
            mutator1.Successor            = variableCreator1;
            variableCreator1.Successor    = null;
            variableCreator2.Successor    = null;
            conditionalSelector.Successor = subScopesProcessor2;
            subScopesProcessor2.Operators.Add(new EmptyOperator());
            subScopesProcessor2.Operators.Add(uniformSubScopesProcessor4);
            subScopesProcessor2.Successor        = mergingReducer1;
            uniformSubScopesProcessor4.Operator  = evaluator2;
            uniformSubScopesProcessor4.Successor = subScopesCounter2;
            evaluator2.Successor                 = null;
            subScopesCounter2.Successor          = null;
            mergingReducer1.Successor            = null;
            uniformSubScopesProcessor5.Operator  = crossover2;
            uniformSubScopesProcessor5.Successor = uniformSubScopesProcessor6;
            crossover2.Successor                 = mutationBranch2;
            mutationBranch2.FirstBranch          = mutator2;
            mutationBranch2.SecondBranch         = null;
            mutationBranch2.Successor            = null;
            mutator2.Successor = null;
            uniformSubScopesProcessor6.Operator  = evaluator3;
            uniformSubScopesProcessor6.Successor = subScopesCounter3;
            evaluator3.Successor               = qualityComparer2;
            qualityComparer2.Successor         = subScopesRemover2;
            subScopesRemover2.Successor        = null;
            subScopesCounter3.Successor        = null;
            offspringSelector.OffspringCreator = selector;
            offspringSelector.Successor        = subScopesProcessor3;
            subScopesProcessor3.Operators.Add(bestSelector);
            subScopesProcessor3.Operators.Add(worstSelector);
            subScopesProcessor3.Successor        = mergingReducer2;
            bestSelector.Successor               = rightReducer;
            rightReducer.Successor               = reevaluateElitesBranch;
            reevaluateElitesBranch.TrueBranch    = uniformSubScopesProcessor7;
            uniformSubScopesProcessor7.Operator  = evaluator4;
            uniformSubScopesProcessor7.Successor = subScopesCounter4;
            subScopesCounter4.Successor          = null;
            reevaluateElitesBranch.FalseBranch   = null;
            reevaluateElitesBranch.Successor     = null;
            worstSelector.Successor              = leftReducer;
            leftReducer.Successor     = null;
            mergingReducer2.Successor = null;
            #endregion
        }
Esempio n. 7
0
        private void Initialize()
        {
            #region Create parameters
            Parameters.Add(new ValueLookupParameter <IRandom>("Random", "A pseudo random number generator."));
            Parameters.Add(new ValueLookupParameter <BoolValue>("Maximization", "True if the problem is a maximization problem, otherwise false."));
            Parameters.Add(new LookupParameter <DoubleValue>("Quality", "The value which represents the quality of a solution."));
            Parameters.Add(new LookupParameter <DoubleValue>("BestLocalQuality", "The value which represents the best quality found so far."));
            Parameters.Add(new ValueLookupParameter <DoubleValue>("BestKnownQuality", "The problem's best known quality value found so far."));
            Parameters.Add(new LookupParameter <DoubleValue>("MoveQuality", "The value which represents the quality of a move."));
            Parameters.Add(new LookupParameter <IntValue>("Iterations", "The number of iterations performed."));
            Parameters.Add(new ValueLookupParameter <IntValue>("MaximumIterations", "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>("MoveGenerator", "The operator that generates the moves."));
            Parameters.Add(new ValueLookupParameter <IOperator>("MoveMaker", "The operator that performs a move and updates the quality."));
            Parameters.Add(new ValueLookupParameter <IOperator>("MoveEvaluator", "The operator that evaluates a move."));

            Parameters.Add(new ValueLookupParameter <IOperator>("Analyzer", "The operator used to analyze the solution and moves."));
            Parameters.Add(new LookupParameter <IntValue>("EvaluatedMoves", "The number of evaluated moves."));
            #endregion

            #region Create operators
            SubScopesProcessor        subScopesProcessor0    = new SubScopesProcessor();
            Assigner                  bestQualityInitializer = new Assigner();
            Placeholder               analyzer1                   = new Placeholder();
            ResultsCollector          resultsCollector1           = new ResultsCollector();
            SubScopesProcessor        mainProcessor               = new SubScopesProcessor();
            Placeholder               moveGenerator               = new Placeholder();
            UniformSubScopesProcessor moveEvaluationProcessor     = new UniformSubScopesProcessor();
            Placeholder               moveEvaluator               = new Placeholder();
            SubScopesCounter          subScopesCounter            = new SubScopesCounter();
            BestSelector              bestSelector                = new BestSelector();
            SubScopesProcessor        moveMakingProcessor         = new SubScopesProcessor();
            UniformSubScopesProcessor selectedMoveMakingProcessor = new UniformSubScopesProcessor();
            QualityComparator         qualityComparator           = new QualityComparator();
            ConditionalBranch         improvesQualityBranch       = new ConditionalBranch();
            Placeholder               moveMaker                   = new Placeholder();
            Assigner                  bestQualityUpdater          = new Assigner();
            ResultsCollector          resultsCollector2           = new ResultsCollector();
            MergingReducer            mergingReducer              = new MergingReducer();
            Placeholder               analyzer2                   = new Placeholder();
            SubScopesRemover          subScopesRemover            = new SubScopesRemover();
            IntCounter                iterationsCounter           = new IntCounter();
            Comparator                iterationsComparator        = new Comparator();
            ConditionalBranch         iterationsTermination       = new ConditionalBranch();

            bestQualityInitializer.Name = "Initialize BestQuality";
            bestQualityInitializer.LeftSideParameter.ActualName  = BestLocalQualityParameter.Name;
            bestQualityInitializer.RightSideParameter.ActualName = QualityParameter.Name;

            analyzer1.Name = "Analyzer (placeholder)";
            analyzer1.OperatorParameter.ActualName = AnalyzerParameter.Name;

            resultsCollector1.CopyValue = new BoolValue(false);
            resultsCollector1.CollectedValues.Add(new LookupParameter <IntValue>(IterationsParameter.Name));
            resultsCollector1.CollectedValues.Add(new LookupParameter <DoubleValue>(BestLocalQualityParameter.Name, null, BestLocalQualityParameter.Name));
            resultsCollector1.ResultsParameter.ActualName = ResultsParameter.Name;

            moveGenerator.Name = "MoveGenerator (placeholder)";
            moveGenerator.OperatorParameter.ActualName = MoveGeneratorParameter.Name;

            moveEvaluationProcessor.Parallel = new BoolValue(true);

            moveEvaluator.Name = "MoveEvaluator (placeholder)";
            moveEvaluator.OperatorParameter.ActualName = MoveEvaluatorParameter.Name;

            subScopesCounter.Name = "Increment EvaluatedMoves";
            subScopesCounter.ValueParameter.ActualName = EvaluatedMovesParameter.Name;

            bestSelector.CopySelected = new BoolValue(false);
            bestSelector.MaximizationParameter.ActualName         = MaximizationParameter.Name;
            bestSelector.NumberOfSelectedSubScopesParameter.Value = new IntValue(1);
            bestSelector.QualityParameter.ActualName = MoveQualityParameter.Name;

            qualityComparator.LeftSideParameter.ActualName  = MoveQualityParameter.Name;
            qualityComparator.RightSideParameter.ActualName = QualityParameter.Name;
            qualityComparator.ResultParameter.ActualName    = "IsBetter";

            improvesQualityBranch.ConditionParameter.ActualName = "IsBetter";

            moveMaker.Name = "MoveMaker (placeholder)";
            moveMaker.OperatorParameter.ActualName = MoveMakerParameter.Name;

            bestQualityUpdater.Name = "Update BestQuality";
            bestQualityUpdater.LeftSideParameter.ActualName  = BestLocalQualityParameter.Name;
            bestQualityUpdater.RightSideParameter.ActualName = QualityParameter.Name;

            resultsCollector2.CopyValue = new BoolValue(false);
            resultsCollector2.CollectedValues.Add(new LookupParameter <DoubleValue>(BestLocalQualityParameter.Name, null, BestLocalQualityParameter.Name));
            resultsCollector2.ResultsParameter.ActualName = ResultsParameter.Name;

            analyzer2.Name = "Analyzer (placeholder)";
            analyzer2.OperatorParameter.ActualName = AnalyzerParameter.Name;

            subScopesRemover.RemoveAllSubScopes = true;

            iterationsCounter.Name      = "Iterations Counter";
            iterationsCounter.Increment = new IntValue(1);
            iterationsCounter.ValueParameter.ActualName = IterationsParameter.Name;

            iterationsComparator.Name       = "Iterations >= MaximumIterations";
            iterationsComparator.Comparison = new Comparison(ComparisonType.GreaterOrEqual);
            iterationsComparator.LeftSideParameter.ActualName  = IterationsParameter.Name;
            iterationsComparator.RightSideParameter.ActualName = MaximumIterationsParameter.Name;
            iterationsComparator.ResultParameter.ActualName    = "Terminate";

            iterationsTermination.Name = "Iterations Termination Condition";
            iterationsTermination.ConditionParameter.ActualName = "Terminate";
            #endregion

            #region Create operator graph
            OperatorGraph.InitialOperator = subScopesProcessor0; // don't change this without adapting the constructor of LocalSearchImprovementOperator
            subScopesProcessor0.Operators.Add(bestQualityInitializer);
            subScopesProcessor0.Successor    = resultsCollector1;
            bestQualityInitializer.Successor = analyzer1;
            analyzer1.Successor         = null;
            resultsCollector1.Successor = mainProcessor;
            mainProcessor.Operators.Add(moveGenerator);
            mainProcessor.Successor           = iterationsCounter;
            moveGenerator.Successor           = moveEvaluationProcessor;
            moveEvaluationProcessor.Operator  = moveEvaluator;
            moveEvaluationProcessor.Successor = subScopesCounter;
            moveEvaluator.Successor           = null;
            subScopesCounter.Successor        = bestSelector;
            bestSelector.Successor            = moveMakingProcessor;
            moveMakingProcessor.Operators.Add(new EmptyOperator());
            moveMakingProcessor.Operators.Add(selectedMoveMakingProcessor);
            moveMakingProcessor.Successor        = mergingReducer;
            selectedMoveMakingProcessor.Operator = qualityComparator;
            qualityComparator.Successor          = improvesQualityBranch;
            improvesQualityBranch.TrueBranch     = moveMaker;
            improvesQualityBranch.FalseBranch    = null;
            improvesQualityBranch.Successor      = null;
            moveMaker.Successor               = bestQualityUpdater;
            bestQualityUpdater.Successor      = null;
            mergingReducer.Successor          = analyzer2;
            analyzer2.Successor               = subScopesRemover;
            subScopesRemover.Successor        = null;
            iterationsCounter.Successor       = iterationsComparator;
            iterationsComparator.Successor    = iterationsTermination;
            iterationsTermination.TrueBranch  = null;
            iterationsTermination.FalseBranch = mainProcessor;
            #endregion
        }
        private void Initialize()
        {
            #region Create parameters
            Parameters.Add(new ValueLookupParameter <IRandom>("Random", "A pseudo random number generator."));
            Parameters.Add(new ValueLookupParameter <BoolValue>("Maximization", "True if the problem is a maximization problem, otherwise false."));
            Parameters.Add(new ScopeTreeLookupParameter <DoubleValue>("Quality", "The value which represents the quality of a solution."));
            Parameters.Add(new ValueLookupParameter <DoubleValue>("BestKnownQuality", "The best known quality value found so far."));
            Parameters.Add(new ValueLookupParameter <IntValue>("PopulationSize", "µ (mu) - the size of the population."));
            Parameters.Add(new ValueLookupParameter <IntValue>("ParentsPerChild", "ρ (rho) - how many parents should be recombined."));
            Parameters.Add(new ValueLookupParameter <IntValue>("MaximumGenerations", "The maximum number of generations which should be processed."));
            Parameters.Add(new ValueLookupParameter <BoolValue>("PlusSelection", "True for plus selection (elitist population), false for comma selection (non-elitist population)."));
            Parameters.Add(new ValueLookupParameter <BoolValue>("ReevaluateElites", "Flag to determine if elite individuals should be reevaluated (i.e., if stochastic fitness functions are used.)"));
            Parameters.Add(new ValueLookupParameter <IOperator>("Mutator", "The operator used to mutate solutions."));
            Parameters.Add(new ValueLookupParameter <IOperator>("Recombinator", "The operator used to cross 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 <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 ScopeParameter("CurrentScope", "The current scope which represents a population of solutions on which the OffspringSelectionEvolutionStrategy should be applied."));
            Parameters.Add(new ValueLookupParameter <IOperator>("StrategyParameterManipulator", "The operator to mutate the endogeneous strategy parameters."));
            Parameters.Add(new ValueLookupParameter <IOperator>("StrategyParameterCrossover", "The operator to cross the endogeneous strategy parameters."));

            Parameters.Add(new LookupParameter <DoubleValue>("CurrentSuccessRatio", "The current success ratio."));
            Parameters.Add(new ValueLookupParameter <DoubleValue>("SuccessRatio", "The ratio of successful to total children that should be achieved."));
            Parameters.Add(new LookupParameter <DoubleValue>("SelectionPressure", "The actual selection pressure."));
            Parameters.Add(new ValueLookupParameter <DoubleValue>("MaximumSelectionPressure", "The maximum selection pressure that terminates the algorithm."));
            Parameters.Add(new ValueLookupParameter <IntValue>("MaximumEvaluatedSolutions", "The maximum number of evaluated solutions."));
            Parameters.Add(new ValueLookupParameter <IntValue>("SelectedParents", "How much parents should be selected each time the offspring selection step is performed until the population is filled. This parameter should be about the same or twice the size of PopulationSize for smaller problems, and less for large problems."));
            Parameters.Add(new LookupParameter <DoubleValue>("ComparisonFactor", "The comparison factor is used to determine whether the offspring should be compared to the better parent, the worse parent or a quality value linearly interpolated between them. It is in the range [0;1]."));

            #endregion

            #region Create operators
            VariableCreator  variableCreator                                           = new VariableCreator();
            ResultsCollector resultsCollector1                                         = new ResultsCollector();
            Placeholder      analyzer1                                                 = new Placeholder();
            WithoutRepeatingBatchedRandomSelector selector                             = new WithoutRepeatingBatchedRandomSelector();
            SubScopesProcessor                 subScopesProcessor1                     = new SubScopesProcessor();
            Comparator                         useRecombinationComparator              = new Comparator();
            ConditionalBranch                  useRecombinationBranch                  = new ConditionalBranch();
            ChildrenCreator                    childrenCreator                         = new ChildrenCreator();
            UniformSubScopesProcessor          uniformSubScopesProcessor1              = new UniformSubScopesProcessor();
            Placeholder                        recombinator                            = new Placeholder();
            Placeholder                        strategyRecombinator                    = new Placeholder();
            Placeholder                        strategyMutator1                        = new Placeholder();
            Placeholder                        mutator1                                = new Placeholder();
            SubScopesRemover                   subScopesRemover                        = new SubScopesRemover();
            UniformSubScopesProcessor          uniformSubScopesProcessor2              = new UniformSubScopesProcessor();
            Placeholder                        strategyMutator2                        = new Placeholder();
            Placeholder                        mutator2                                = new Placeholder();
            UniformSubScopesProcessor          uniformSubScopesProcessor3              = new UniformSubScopesProcessor();
            Placeholder                        evaluator                               = new Placeholder();
            SubScopesCounter                   subScopesCounter                        = new SubScopesCounter();
            ConditionalBranch                  plusOrCommaReplacementBranch            = new ConditionalBranch();
            MergingReducer                     plusReplacement                         = new MergingReducer();
            RightReducer                       commaReplacement                        = new RightReducer();
            BestSelector                       bestSelector                            = new BestSelector();
            RightReducer                       rightReducer                            = new RightReducer();
            IntCounter                         intCounter                              = new IntCounter();
            Comparator                         maxGenerationsComparator                = new Comparator();
            Placeholder                        analyzer2                               = new Placeholder();
            ConditionalBranch                  conditionalBranchTerminate              = new ConditionalBranch();
            ConditionalBranch                  reevaluateElitesBranch                  = new ConditionalBranch();
            SubScopesProcessor                 subScopesProcessor2                     = new SubScopesProcessor();
            UniformSubScopesProcessor          uniformSubScopesProcessor4              = new UniformSubScopesProcessor();
            Placeholder                        evaluator2                              = new Placeholder();
            SubScopesCounter                   subScopesCounter2                       = new SubScopesCounter();
            WeightedParentsQualityComparator   parentsComparator                       = new WeightedParentsQualityComparator();
            SubScopesRemover                   subScopesRemover_afterCompare           = new SubScopesRemover();
            EvolutionStrategyOffspringSelector offspringSelector                       = new EvolutionStrategyOffspringSelector();
            ChildrenCopyCreator                childrenCopyCreator                     = new ChildrenCopyCreator();
            Comparator                         maxSelectionPressureComparator          = new Comparator();
            ConditionalBranch                  conditionalBranchTerminateSelPressure   = new ConditionalBranch();
            Comparator                         maxEvaluatedSolutionsComparator         = new Comparator();
            ConditionalBranch                  conditionalBranchTerminateEvalSolutions = new ConditionalBranch();

            variableCreator.CollectedValues.Add(new ValueParameter <IntValue>("Generations", new IntValue(0))); // Class OffspringSelectionEvolutionStrategy expects this to be called Generations
            variableCreator.CollectedValues.Add(new ValueParameter <DoubleValue>("SelectionPressure", new DoubleValue(0)));
            variableCreator.CollectedValues.Add(new ValueParameter <DoubleValue>("CurrentSuccessRatio", new DoubleValue(0)));

            resultsCollector1.CollectedValues.Add(new LookupParameter <IntValue>("Generations"));
            resultsCollector1.CollectedValues.Add(new LookupParameter <DoubleValue>("Current Selection Pressure", "Displays the rising selection pressure during a generation.", "SelectionPressure"));
            resultsCollector1.CollectedValues.Add(new LookupParameter <DoubleValue>("Current Success Ratio", "Indicates how many successful children were already found during a generation (relative to the population size).", "CurrentSuccessRatio"));
            resultsCollector1.CopyValue = new BoolValue(false);
            resultsCollector1.ResultsParameter.ActualName = ResultsParameter.Name;

            analyzer1.Name = "Analyzer (placeholder)";
            analyzer1.OperatorParameter.ActualName = AnalyzerParameter.Name;

            selector.Name = "ES Random Selector";
            selector.RandomParameter.ActualName          = RandomParameter.Name;
            selector.ParentsPerChildParameter.ActualName = ParentsPerChildParameter.Name;
            selector.ChildrenParameter.ActualName        = SelectedParentsParameter.Name;

            useRecombinationComparator.Name = "ParentsPerChild > 1";
            useRecombinationComparator.LeftSideParameter.ActualName = ParentsPerChildParameter.Name;
            useRecombinationComparator.RightSideParameter.Value     = new IntValue(1);
            useRecombinationComparator.Comparison = new Comparison(ComparisonType.Greater);
            useRecombinationComparator.ResultParameter.ActualName = "UseRecombination";

            useRecombinationBranch.Name = "Use Recombination?";
            useRecombinationBranch.ConditionParameter.ActualName = "UseRecombination";

            childrenCreator.ParentsPerChild = null;
            childrenCreator.ParentsPerChildParameter.ActualName = ParentsPerChildParameter.Name;

            recombinator.Name = "Recombinator (placeholder)";
            recombinator.OperatorParameter.ActualName = RecombinatorParameter.Name;

            strategyRecombinator.Name = "Strategy Parameter Recombinator (placeholder)";
            strategyRecombinator.OperatorParameter.ActualName = StrategyParameterCrossoverParameter.Name;

            strategyMutator1.Name = "Strategy Parameter Manipulator (placeholder)";
            strategyMutator1.OperatorParameter.ActualName = StrategyParameterManipulatorParameter.Name;

            mutator1.Name = "Mutator (placeholder)";
            mutator1.OperatorParameter.ActualName = MutatorParameter.Name;

            subScopesRemover.RemoveAllSubScopes = true;

            strategyMutator2.Name = "Strategy Parameter Manipulator (placeholder)";
            strategyMutator2.OperatorParameter.ActualName = StrategyParameterManipulatorParameter.Name;

            mutator2.Name = "Mutator (placeholder)";
            mutator2.OperatorParameter.ActualName = MutatorParameter.Name;

            uniformSubScopesProcessor3.Parallel.Value = true;

            evaluator.Name = "Evaluator (placeholder)";
            evaluator.OperatorParameter.ActualName = EvaluatorParameter.Name;

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

            plusOrCommaReplacementBranch.ConditionParameter.ActualName = PlusSelectionParameter.Name;

            bestSelector.CopySelected = new BoolValue(false);
            bestSelector.MaximizationParameter.ActualName = MaximizationParameter.Name;
            bestSelector.NumberOfSelectedSubScopesParameter.ActualName = PopulationSizeParameter.Name;
            bestSelector.QualityParameter.ActualName = QualityParameter.Name;

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

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

            analyzer2.Name = "Analyzer (placeholder)";
            analyzer2.OperatorParameter.ActualName = AnalyzerParameter.Name;

            conditionalBranchTerminate.ConditionParameter.ActualName = "Terminate";

            reevaluateElitesBranch.ConditionParameter.ActualName = "ReevaluateElites";
            reevaluateElitesBranch.Name = "Reevaluate elites ?";

            uniformSubScopesProcessor4.Parallel.Value = true;

            evaluator2.Name = "Evaluator (placeholder)";
            evaluator2.OperatorParameter.ActualName = EvaluatorParameter.Name;

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

            parentsComparator.ComparisonFactorParameter.ActualName = ComparisonFactorParameter.Name;
            parentsComparator.LeftSideParameter.ActualName         = QualityParameter.Name;
            parentsComparator.RightSideParameter.ActualName        = QualityParameter.Name;
            parentsComparator.MaximizationParameter.ActualName     = MaximizationParameter.Name;
            parentsComparator.ResultParameter.ActualName           = "SuccessfulOffspring";

            subScopesRemover_afterCompare.RemoveAllSubScopes = true;

            offspringSelector.CurrentSuccessRatioParameter.ActualName        = CurrentSuccessRatioParameter.Name;
            offspringSelector.MaximumSelectionPressureParameter.ActualName   = MaximumSelectionPressureParameter.Name;
            offspringSelector.SelectionPressureParameter.ActualName          = SelectionPressureParameter.Name;
            offspringSelector.SuccessRatioParameter.ActualName               = SuccessRatioParameter.Name;
            offspringSelector.OffspringPopulationParameter.ActualName        = "OffspringPopulation";
            offspringSelector.OffspringPopulationWinnersParameter.ActualName = "OffspringPopulationWinners";
            offspringSelector.SuccessfulOffspringParameter.ActualName        = "SuccessfulOffspring";
            offspringSelector.QualityParameter.ActualName = QualityParameter.Name;

            maxSelectionPressureComparator.Comparison = new Comparison(ComparisonType.GreaterOrEqual);
            maxSelectionPressureComparator.LeftSideParameter.ActualName  = "SelectionPressure";
            maxSelectionPressureComparator.ResultParameter.ActualName    = "TerminateSelectionPressure";
            maxSelectionPressureComparator.RightSideParameter.ActualName = MaximumSelectionPressureParameter.Name;

            conditionalBranchTerminateSelPressure.ConditionParameter.ActualName = "TerminateSelectionPressure";

            maxEvaluatedSolutionsComparator.Comparison = new Comparison(ComparisonType.GreaterOrEqual);
            maxEvaluatedSolutionsComparator.LeftSideParameter.ActualName  = "EvaluatedSolutions";
            maxEvaluatedSolutionsComparator.ResultParameter.ActualName    = "TerminateEvaluatedSolutions";
            maxEvaluatedSolutionsComparator.RightSideParameter.ActualName = MaximumEvaluatedSolutionsParameter.Name;

            conditionalBranchTerminateEvalSolutions.ConditionParameter.ActualName = "TerminateEvaluatedSolutions";

            #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(useRecombinationComparator);

            subScopesProcessor1.Successor      = offspringSelector;
            offspringSelector.OffspringCreator = selector;
            offspringSelector.Successor        = plusOrCommaReplacementBranch;

            useRecombinationComparator.Successor = useRecombinationBranch;
            useRecombinationBranch.TrueBranch    = childrenCreator;

            useRecombinationBranch.FalseBranch = childrenCopyCreator;
            childrenCopyCreator.Successor      = uniformSubScopesProcessor2;

            useRecombinationBranch.Successor     = uniformSubScopesProcessor3;
            childrenCreator.Successor            = uniformSubScopesProcessor1;
            uniformSubScopesProcessor1.Operator  = recombinator;
            uniformSubScopesProcessor1.Successor = null;
            recombinator.Successor         = strategyRecombinator;
            strategyRecombinator.Successor = strategyMutator1;
            strategyMutator1.Successor     = mutator1;

            mutator1.Successor = null;

            uniformSubScopesProcessor2.Operator  = strategyMutator2;
            uniformSubScopesProcessor2.Successor = null;
            strategyMutator2.Successor           = mutator2;
            mutator2.Successor = null;
            uniformSubScopesProcessor3.Operator  = evaluator;
            uniformSubScopesProcessor3.Successor = subScopesCounter;

            evaluator.Successor                     = parentsComparator;
            parentsComparator.Successor             = subScopesRemover_afterCompare;
            subScopesRemover_afterCompare.Successor = null;
            subScopesCounter.Successor              = null;

            plusOrCommaReplacementBranch.TrueBranch = reevaluateElitesBranch;
            reevaluateElitesBranch.TrueBranch       = subScopesProcessor2;
            reevaluateElitesBranch.FalseBranch      = null;
            subScopesProcessor2.Operators.Add(uniformSubScopesProcessor4);
            subScopesProcessor2.Operators.Add(new EmptyOperator());
            uniformSubScopesProcessor4.Operator  = evaluator2;
            uniformSubScopesProcessor4.Successor = subScopesCounter2;
            subScopesCounter2.Successor          = null;
            reevaluateElitesBranch.Successor     = plusReplacement;

            plusReplacement.Successor = bestSelector;
            bestSelector.Successor    = rightReducer;

            plusOrCommaReplacementBranch.FalseBranch = commaReplacement;
            plusOrCommaReplacementBranch.Successor   = intCounter;


            intCounter.Successor = maxGenerationsComparator;
            maxGenerationsComparator.Successor        = maxSelectionPressureComparator;
            maxSelectionPressureComparator.Successor  = maxEvaluatedSolutionsComparator;
            maxEvaluatedSolutionsComparator.Successor = analyzer2;
            analyzer2.Successor = conditionalBranchTerminate;
            conditionalBranchTerminate.FalseBranch              = conditionalBranchTerminateSelPressure;
            conditionalBranchTerminate.TrueBranch               = null;
            conditionalBranchTerminate.Successor                = null;
            conditionalBranchTerminateSelPressure.FalseBranch   = conditionalBranchTerminateEvalSolutions;
            conditionalBranchTerminateSelPressure.TrueBranch    = null;
            conditionalBranchTerminateSelPressure.Successor     = null;
            conditionalBranchTerminateEvalSolutions.FalseBranch = selector;
            conditionalBranchTerminateEvalSolutions.TrueBranch  = null;
            conditionalBranchTerminateEvalSolutions.Successor   = null;

            #endregion
        }
        private void Initialize()
        {
            #region Create parameters
            Parameters.Add(new ValueLookupParameter <IMultiAnalyzer>("Analyzer", "The analyzer used to analyze each iteration."));
            Parameters.Add(new ValueLookupParameter <DoubleValue>("BestKnownQuality", "The best known quality value found so far."));
            Parameters.Add(new ValueLookupParameter <ICrossover>("Crossover", "The operator used to cross solutions."));
            Parameters.Add(new ValueLookupParameter <IntValue>("EvaluatedSolutions", "The number of times solutions have been evaluated."));
            Parameters.Add(new ValueLookupParameter <IEvaluator>("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 <BoolValue>("ExecutePathRelinking", "True if path relinking should be executed instead of crossover, otherwise false."));
            Parameters.Add(new ValueLookupParameter <IImprovementOperator>("Improver", "The operator used to improve solutions."));
            Parameters.Add(new ValueLookupParameter <IntValue>("Iterations", "The number of iterations performed."));
            Parameters.Add(new ValueLookupParameter <BoolValue>("Maximization", "True if the problem is a maximization problem, otherwise false."));
            Parameters.Add(new ValueLookupParameter <IntValue>("MaximumIterations", "The maximum number of iterations which should be processed."));
            Parameters.Add(new ValueLookupParameter <IntValue>("NumberOfHighQualitySolutions", "The number of high quality solutions in the reference set."));
            Parameters.Add(new ValueLookupParameter <IPathRelinker>("PathRelinker", "The operator used to execute path relinking."));
            Parameters.Add(new ValueLookupParameter <IntValue>("PopulationSize", "The size of the population of solutions."));
            Parameters.Add(new ValueLookupParameter <IntValue>("ReferenceSetSize", "The size of the reference set."));
            Parameters.Add(new ValueLookupParameter <DoubleValue>("Quality", "This parameter is used for name translation only."));
            Parameters.Add(new ValueLookupParameter <IRandom>("Random", "A pseudo random number generator."));
            Parameters.Add(new ValueLookupParameter <VariableCollection>("Results", "The variable collection where results should be stored."));
            Parameters.Add(new ValueLookupParameter <ISolutionSimilarityCalculator>("SimilarityCalculator", "The operator used to calculate the similarity between two solutions."));
            #endregion

            #region Create operators
            Placeholder               analyzer                   = new Placeholder();
            Assigner                  assigner1                  = new Assigner();
            Assigner                  assigner2                  = new Assigner();
            ChildrenCreator           childrenCreator            = new ChildrenCreator();
            Placeholder               crossover                  = new Placeholder();
            Comparator                iterationsChecker          = new Comparator();
            IntCounter                iterationsCounter          = new IntCounter();
            MergingReducer            mergingReducer             = new MergingReducer();
            ConditionalBranch         executePathRelinkingBranch = new ConditionalBranch();
            ConditionalBranch         newSolutionsBranch         = new ConditionalBranch();
            OffspringProcessor        offspringProcessor         = new OffspringProcessor();
            Placeholder               pathRelinker               = new Placeholder();
            PopulationRebuildMethod   populationRebuildMethod    = new PopulationRebuildMethod();
            ReferenceSetUpdateMethod  referenceSetUpdateMethod   = new ReferenceSetUpdateMethod();
            ResultsCollector          resultsCollector           = new ResultsCollector();
            RightSelector             rightSelector              = new RightSelector();
            Placeholder               solutionEvaluator1         = new Placeholder();
            Placeholder               solutionEvaluator2         = new Placeholder();
            Placeholder               solutionImprover1          = new Placeholder();
            Placeholder               solutionImprover2          = new Placeholder();
            SolutionPoolUpdateMethod  solutionPoolUpdateMethod   = new SolutionPoolUpdateMethod();
            SolutionsCreator          solutionsCreator           = new SolutionsCreator();
            DataReducer               dataReducer1               = new DataReducer();
            DataReducer               dataReducer2               = new DataReducer();
            SubScopesProcessor        subScopesProcessor1        = new SubScopesProcessor();
            SubScopesProcessor        subScopesProcessor2        = new SubScopesProcessor();
            SubScopesProcessor        subScopesProcessor3        = new SubScopesProcessor();
            SubScopesProcessor        subScopesProcessor4        = new SubScopesProcessor();
            ConditionalBranch         terminateBranch            = new ConditionalBranch();
            UniformSubScopesProcessor uniformSubScopesProcessor1 = new UniformSubScopesProcessor();
            UniformSubScopesProcessor uniformSubScopesProcessor2 = new UniformSubScopesProcessor();
            UniformSubScopesProcessor uniformSubScopesProcessor3 = new UniformSubScopesProcessor();
            VariableCreator           variableCreator            = new VariableCreator();
            #endregion

            #region Create operator graph
            OperatorGraph.InitialOperator = variableCreator;
            variableCreator.CollectedValues.Add(new ValueParameter <IntValue>(IterationsParameter.Name, new IntValue(0)));
            variableCreator.CollectedValues.Add(new ValueParameter <BoolValue>("NewSolutions", new BoolValue(false)));
            variableCreator.Successor = resultsCollector;

            resultsCollector.CopyValue = new BoolValue(false);
            resultsCollector.CollectedValues.Add(new LookupParameter <IntValue>(IterationsParameter.Name));
            resultsCollector.ResultsParameter.ActualName = ResultsParameter.Name;
            resultsCollector.Successor = iterationsChecker;

            iterationsChecker.Name                          = "IterationsChecker";
            iterationsChecker.Comparison.Value              = ComparisonType.GreaterOrEqual;
            iterationsChecker.LeftSideParameter.ActualName  = IterationsParameter.Name;
            iterationsChecker.RightSideParameter.ActualName = MaximumIterationsParameter.Name;
            iterationsChecker.ResultParameter.ActualName    = "Terminate";
            iterationsChecker.Successor                     = terminateBranch;

            terminateBranch.Name = "TerminateChecker";
            terminateBranch.ConditionParameter.ActualName = "Terminate";
            terminateBranch.FalseBranch = referenceSetUpdateMethod;

            referenceSetUpdateMethod.Successor = assigner1;

            assigner1.Name = "NewSolutions = true";
            assigner1.LeftSideParameter.ActualName = "NewSolutions";
            assigner1.RightSideParameter.Value     = new BoolValue(true);
            assigner1.Successor = subScopesProcessor1;

            subScopesProcessor1.DepthParameter.Value = new IntValue(1);
            subScopesProcessor1.Operators.Add(new EmptyOperator());
            subScopesProcessor1.Operators.Add(childrenCreator);
            subScopesProcessor1.Successor = newSolutionsBranch;

            childrenCreator.Name = "SubsetGenerator";
            childrenCreator.ParentsPerChildParameter.Value = new IntValue(2);
            childrenCreator.Successor = assigner2;

            assigner2.Name = "NewSolutions = false";
            assigner2.LeftSideParameter.ActualName = "NewSolutions";
            assigner2.RightSideParameter.Value     = new BoolValue(false);
            assigner2.Successor = uniformSubScopesProcessor1;

            uniformSubScopesProcessor1.DepthParameter.Value = new IntValue(1);
            uniformSubScopesProcessor1.Operator             = executePathRelinkingBranch;
            uniformSubScopesProcessor1.Successor            = solutionPoolUpdateMethod;

            executePathRelinkingBranch.Name = "ExecutePathRelinkingChecker";
            executePathRelinkingBranch.ConditionParameter.ActualName = ExecutePathRelinkingParameter.ActualName;
            executePathRelinkingBranch.TrueBranch  = pathRelinker;
            executePathRelinkingBranch.FalseBranch = crossover;

            pathRelinker.Name = "PathRelinker";
            pathRelinker.OperatorParameter.ActualName = PathRelinkerParameter.Name;
            pathRelinker.Successor = rightSelector;

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

            offspringProcessor.Successor = rightSelector;

            rightSelector.NumberOfSelectedSubScopesParameter.Value = new IntValue(1);
            rightSelector.CopySelected = new BoolValue(false);
            rightSelector.Successor    = subScopesProcessor2;

            subScopesProcessor2.DepthParameter.Value = new IntValue(1);
            subScopesProcessor2.Operators.Add(new EmptyOperator());
            subScopesProcessor2.Operators.Add(uniformSubScopesProcessor2);
            subScopesProcessor2.Successor = mergingReducer;

            uniformSubScopesProcessor2.DepthParameter.Value    = new IntValue(2);
            uniformSubScopesProcessor2.Operator                = solutionImprover1;
            uniformSubScopesProcessor2.ParallelParameter.Value = new BoolValue(true);
            uniformSubScopesProcessor2.Successor               = subScopesProcessor4;

            solutionImprover1.Name = "SolutionImprover";
            solutionImprover1.OperatorParameter.ActualName = ImproverParameter.Name;
            solutionImprover1.Successor = solutionEvaluator1;

            solutionEvaluator1.Name = "SolutionEvaluator";
            solutionEvaluator1.OperatorParameter.ActualName = EvaluatorParameter.Name;

            subScopesProcessor4.Operators.Add(dataReducer1);

            dataReducer1.Name = "Increment EvaluatedSolutions";
            dataReducer1.ParameterToReduce.ActualName = "LocalEvaluatedSolutions";
            dataReducer1.TargetParameter.ActualName   = EvaluatedSolutionsParameter.Name;
            dataReducer1.ReductionOperation.Value     = new ReductionOperation(ReductionOperations.Sum);
            dataReducer1.TargetOperation.Value        = new ReductionOperation(ReductionOperations.Sum);

            solutionPoolUpdateMethod.QualityParameter.ActualName = QualityParameter.ActualName;
            solutionPoolUpdateMethod.Successor = analyzer;

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

            newSolutionsBranch.Name = "NewSolutionsChecker";
            newSolutionsBranch.ConditionParameter.ActualName = "NewSolutions";
            newSolutionsBranch.TrueBranch  = subScopesProcessor1;
            newSolutionsBranch.FalseBranch = populationRebuildMethod;

            populationRebuildMethod.QualityParameter.ActualName = QualityParameter.ActualName;
            populationRebuildMethod.Successor = subScopesProcessor3;

            subScopesProcessor3.DepthParameter.Value = new IntValue(1);
            subScopesProcessor3.Operators.Add(solutionsCreator);
            subScopesProcessor3.Operators.Add(new EmptyOperator());
            subScopesProcessor3.Successor = iterationsCounter;

            solutionsCreator.Name = "DiversificationGenerationMethod";
            solutionsCreator.NumberOfSolutionsParameter.ActualName = PopulationSizeParameter.Name;
            solutionsCreator.Successor = uniformSubScopesProcessor3;

            uniformSubScopesProcessor3.DepthParameter.Value    = new IntValue(1);
            uniformSubScopesProcessor3.Operator                = solutionImprover2;
            uniformSubScopesProcessor3.ParallelParameter.Value = new BoolValue(true);
            uniformSubScopesProcessor3.Successor               = dataReducer2;

            solutionImprover2.Name = "SolutionImprover";
            solutionImprover2.OperatorParameter.ActualName = ImproverParameter.Name;
            solutionImprover2.Successor = solutionEvaluator2;

            solutionEvaluator2.Name = "SolutionEvaluator";
            solutionEvaluator2.OperatorParameter.ActualName = EvaluatorParameter.Name;

            dataReducer2.Name = "Increment EvaluatedSolutions";
            dataReducer2.ParameterToReduce.ActualName = "LocalEvaluatedSolutions";
            dataReducer2.TargetParameter.ActualName   = EvaluatedSolutionsParameter.Name;
            dataReducer2.ReductionOperation.Value     = new ReductionOperation(ReductionOperations.Sum);
            dataReducer2.TargetOperation.Value        = new ReductionOperation(ReductionOperations.Sum);

            iterationsCounter.Name = "IterationCounter";
            iterationsCounter.IncrementParameter.Value  = new IntValue(1);
            iterationsCounter.ValueParameter.ActualName = IterationsParameter.Name;
            iterationsCounter.Successor = resultsCollector;
            #endregion
        }
Esempio n. 10
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
        }
        public AlpsGeneticAlgorithmMainOperator()
            : base()
        {
            Parameters.Add(new ValueLookupParameter <IRandom>("Random", "A pseudo random number generator."));

            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>("EvaluatedSolutions", "The number of times solutions have been evaluated."));
            Parameters.Add(new ScopeTreeLookupParameter <DoubleValue>("Quality", "The value which represents the quality of a solution."));
            Parameters.Add(new ValueLookupParameter <BoolValue>("Maximization", "True if the problem is a maximization problem, otherwise false."));

            Parameters.Add(new ValueLookupParameter <IntValue>("PopulationSize", "The size of the population of solutions in each layer."));
            Parameters.Add(new ValueLookupParameter <IOperator>("Selector", "The operator used to select solutions for reproduction."));
            Parameters.Add(new ValueLookupParameter <IOperator>("Crossover", "The operator used to cross solutions."));
            Parameters.Add(new ValueLookupParameter <IOperator>("Mutator", "The operator used to mutate solutions."));
            Parameters.Add(new ValueLookupParameter <PercentValue>("MutationProbability", "The probability that the mutation operator is applied on a solution."));
            Parameters.Add(new ValueLookupParameter <IntValue>("Elites", "The numer of elite solutions which are kept in each generation."));
            Parameters.Add(new ValueLookupParameter <BoolValue>("ReevaluateElites", "Flag to determine if elite individuals should be reevaluated (i.e., if stochastic fitness functions are used.)"));
            Parameters.Add(new ValueLookupParameter <BoolValue>("PlusSelection", "Include the parents in the selection of the invividuals for the next generation."));

            Parameters.Add(new ScopeTreeLookupParameter <DoubleValue>("Age", "The age of individuals."));
            Parameters.Add(new ValueLookupParameter <DoubleValue>("AgeInheritance", "A weight that determines the age of a child after crossover based on the older (1.0) and younger (0.0) parent."));
            Parameters.Add(new ValueLookupParameter <DoubleValue>("AgeIncrement", "The value the age the individuals is incremented if they survives a generation."));


            var numberOfSelectedParentsCalculator = new ExpressionCalculator()
            {
                Name = "NumberOfSelectedParents = 2 * (PopulationSize - (PlusSelection ? 0 : Elites))"
            };
            var selector = new Placeholder()
            {
                Name = "Selector (Placeholder)"
            };
            var subScopesProcessor1        = new SubScopesProcessor();
            var childrenCreator            = new ChildrenCreator();
            var uniformSubScopesProcessor1 = new UniformSubScopesProcessor();
            var crossover = new Placeholder()
            {
                Name = "Crossover (Placeholder)"
            };
            var stochasticBranch = new StochasticBranch()
            {
                Name = "MutationProbability"
            };
            var mutator = new Placeholder()
            {
                Name = "Mutator (Placeholder)"
            };
            var ageCalculator = new WeightingReducer()
            {
                Name = "Calculate Age"
            };
            var subScopesRemover           = new SubScopesRemover();
            var uniformSubScopesProcessor2 = new UniformSubScopesProcessor();
            var evaluator = new Placeholder()
            {
                Name = "Evaluator (Placeholder)"
            };
            var subScopesCounter = new SubScopesCounter()
            {
                Name = "Increment EvaluatedSolutions"
            };
            var replacementBranch = new ConditionalBranch()
            {
                Name = "PlusSelection?"
            };
            var replacementMergingReducer = new MergingReducer();
            var replacementBestSelector   = new BestSelector();
            var replacementRightReducer   = new RightReducer();
            var subScopesProcessor2       = new SubScopesProcessor();
            var bestSelector           = new BestSelector();
            var rightReducer           = new RightReducer();
            var mergingReducer         = new MergingReducer();
            var reevaluateElitesBranch = new ConditionalBranch()
            {
                Name = "Reevaluate elites ?"
            };
            var incrementAgeProcessor = new UniformSubScopesProcessor();
            var ageIncrementor        = new DoubleCounter()
            {
                Name = "Increment Age"
            };

            OperatorGraph.InitialOperator = numberOfSelectedParentsCalculator;

            numberOfSelectedParentsCalculator.CollectedValues.Add(new LookupParameter <IntValue>(PopulationSizeParameter.Name));
            numberOfSelectedParentsCalculator.CollectedValues.Add(new LookupParameter <IntValue>(ElitesParameter.Name));
            numberOfSelectedParentsCalculator.CollectedValues.Add(new LookupParameter <BoolValue>(PlusSelectionParameter.Name));
            numberOfSelectedParentsCalculator.ExpressionResultParameter.ActualName = "NumberOfSelectedSubScopes";
            numberOfSelectedParentsCalculator.ExpressionParameter.Value            = new StringValue("PopulationSize 0 Elites PlusSelection if - 2 * toint");
            numberOfSelectedParentsCalculator.Successor = selector;

            selector.OperatorParameter.ActualName = SelectorParameter.Name;
            selector.Successor = subScopesProcessor1;

            subScopesProcessor1.Operators.Add(new EmptyOperator());
            subScopesProcessor1.Operators.Add(childrenCreator);
            subScopesProcessor1.Successor = replacementBranch;

            childrenCreator.ParentsPerChild = new IntValue(2);
            childrenCreator.Successor       = uniformSubScopesProcessor1;

            uniformSubScopesProcessor1.Operator  = crossover;
            uniformSubScopesProcessor1.Successor = uniformSubScopesProcessor2;

            crossover.OperatorParameter.ActualName = CrossoverParameter.Name;
            crossover.Successor = stochasticBranch;

            stochasticBranch.ProbabilityParameter.ActualName = MutationProbabilityParameter.Name;
            stochasticBranch.RandomParameter.ActualName      = RandomParameter.Name;
            stochasticBranch.FirstBranch  = mutator;
            stochasticBranch.SecondBranch = null;
            stochasticBranch.Successor    = ageCalculator;

            mutator.OperatorParameter.ActualName = MutatorParameter.Name;
            mutator.Successor = null;

            ageCalculator.ParameterToReduce.ActualName = AgeParameter.Name;
            ageCalculator.TargetParameter.ActualName   = AgeParameter.Name;
            ageCalculator.WeightParameter.ActualName   = AgeInheritanceParameter.Name;
            ageCalculator.Successor = subScopesRemover;

            subScopesRemover.RemoveAllSubScopes = true;
            subScopesRemover.Successor          = null;

            uniformSubScopesProcessor2.Parallel.Value = true;
            uniformSubScopesProcessor2.Operator       = evaluator;
            uniformSubScopesProcessor2.Successor      = subScopesCounter;

            evaluator.OperatorParameter.ActualName = EvaluatorParameter.Name;
            evaluator.Successor = null;

            subScopesCounter.ValueParameter.ActualName = EvaluatedSolutionsParameter.Name;
            subScopesCounter.AccumulateParameter.Value = new BoolValue(true);
            subScopesCounter.Successor = null;

            replacementBranch.ConditionParameter.ActualName = PlusSelectionParameter.Name;
            replacementBranch.TrueBranch  = replacementMergingReducer;
            replacementBranch.FalseBranch = subScopesProcessor2;
            replacementBranch.Successor   = incrementAgeProcessor;

            replacementMergingReducer.Successor = replacementBestSelector;

            replacementBestSelector.NumberOfSelectedSubScopesParameter.ActualName = PopulationSizeParameter.Name;
            replacementBestSelector.CopySelected = new BoolValue(false);
            replacementBestSelector.Successor    = replacementRightReducer;

            replacementRightReducer.Successor = reevaluateElitesBranch;

            subScopesProcessor2.Operators.Add(bestSelector);
            subScopesProcessor2.Operators.Add(new EmptyOperator());
            subScopesProcessor2.Successor = mergingReducer;

            bestSelector.CopySelected = new BoolValue(false);
            bestSelector.MaximizationParameter.ActualName = MaximizationParameter.Name;
            bestSelector.NumberOfSelectedSubScopesParameter.ActualName = ElitesParameter.Name;
            bestSelector.QualityParameter.ActualName = QualityParameter.Name;
            bestSelector.Successor = rightReducer;

            rightReducer.Successor = reevaluateElitesBranch;

            mergingReducer.Successor = null;

            reevaluateElitesBranch.ConditionParameter.ActualName = ReevaluateElitesParameter.Name;
            reevaluateElitesBranch.TrueBranch  = uniformSubScopesProcessor2;
            reevaluateElitesBranch.FalseBranch = null;
            reevaluateElitesBranch.Successor   = null;


            incrementAgeProcessor.Operator  = ageIncrementor;
            incrementAgeProcessor.Successor = null;

            ageIncrementor.ValueParameter.ActualName     = AgeParameter.Name;
            ageIncrementor.IncrementParameter.Value      = null;
            ageIncrementor.IncrementParameter.ActualName = AgeIncrementParameter.Name;
            ageIncrementor.Successor = null;
        }
        private CombinedOperator CreateEldersEmigrator()
        {
            var eldersEmigrator = new CombinedOperator()
            {
                Name = "Emigrate Elders"
            };
            var selectorProsessor    = new UniformSubScopesProcessor();
            var eldersSelector       = new EldersSelector();
            var shiftToRightMigrator = new UnidirectionalRingMigrator()
            {
                Name = "Shift elders to next layer"
            };
            var mergingProsessor             = new UniformSubScopesProcessor();
            var mergingReducer               = new MergingReducer();
            var subScopesCounter             = new SubScopesCounter();
            var reduceToPopulationSizeBranch = new ConditionalBranch()
            {
                Name = "ReduceToPopulationSize?"
            };
            var countCalculator = new ExpressionCalculator()
            {
                Name = "CurrentPopulationSize = Min(CurrentPopulationSize, PopulationSize)"
            };
            var bestSelector = new BestSelector();
            var rightReducer = new RightReducer();

            eldersEmigrator.OperatorGraph.InitialOperator = selectorProsessor;

            selectorProsessor.Operator  = eldersSelector;
            selectorProsessor.Successor = shiftToRightMigrator;

            eldersSelector.AgeParameter.ActualName            = AgeParameter.Name;
            eldersSelector.AgeLimitsParameter.ActualName      = AgeLimitsParameter.Name;
            eldersSelector.NumberOfLayersParameter.ActualName = NumberOfLayersParameter.Name;
            eldersSelector.LayerParameter.ActualName          = "Layer";
            eldersSelector.Successor = null;

            shiftToRightMigrator.ClockwiseMigrationParameter.Value = new BoolValue(true);
            shiftToRightMigrator.Successor = mergingProsessor;

            mergingProsessor.Operator = mergingReducer;

            mergingReducer.Successor = subScopesCounter;

            subScopesCounter.ValueParameter.ActualName = CurrentPopulationSizeParameter.Name;
            subScopesCounter.AccumulateParameter.Value = new BoolValue(false);
            subScopesCounter.Successor = reduceToPopulationSizeBranch;

            reduceToPopulationSizeBranch.ConditionParameter.ActualName = ReduceToPopulationSizeParameter.Name;
            reduceToPopulationSizeBranch.TrueBranch = countCalculator;

            countCalculator.CollectedValues.Add(new LookupParameter <IntValue>(PopulationSizeParameter.Name));
            countCalculator.CollectedValues.Add(new LookupParameter <IntValue>(CurrentPopulationSizeParameter.Name));
            countCalculator.ExpressionParameter.Value            = new StringValue("CurrentPopulationSize PopulationSize CurrentPopulationSize PopulationSize < if toint");
            countCalculator.ExpressionResultParameter.ActualName = CurrentPopulationSizeParameter.Name;
            countCalculator.Successor = bestSelector;

            bestSelector.NumberOfSelectedSubScopesParameter.ActualName = CurrentPopulationSizeParameter.Name;
            bestSelector.CopySelected = new BoolValue(false);
            bestSelector.Successor    = rightReducer;

            return(eldersEmigrator);
        }
Esempio n. 13
0
        private CombinedOperator CreateEldersEmigrator()
        {
            var eldersEmigrator = new CombinedOperator {
                Name = "Emigrate Elders"
            };
            var selectorProcessor    = new UniformSubScopesProcessor();
            var eldersSelector       = new EldersSelector();
            var shiftToRightMigrator = new UnidirectionalRingMigrator {
                Name = "Shift elders to next layer"
            };
            var mergingProcessor  = new UniformSubScopesProcessor();
            var mergingReducer    = new MergingReducer();
            var subScopesCounter1 = new SubScopesCounter();
            var currentPopulationSizeComparator = new Comparator {
                Name = "Is CurrentPopulationSize greater than 1?"
            };
            var currentPopulationSizeIsGreaterThanOne = new ConditionalBranch {
                Name = "CurrentPopulationSize > 1"
            };
            var reduceToPopulationSizeBranch = new ConditionalBranch {
                Name = "ReduceToPopulationSize?"
            };
            var countCalculator = new ExpressionCalculator {
                Name = "CurrentPopulationSize = Min(CurrentPopulationSize, PopulationSize)"
            };
            var leftSelector          = new LeftSelector();
            var rankAndCrowdingSorter = new RankAndCrowdingSorter();
            var subScopesCounter2     = new SubScopesCounter();
            var rightReducer          = new RightReducer();

            eldersEmigrator.OperatorGraph.InitialOperator = selectorProcessor;

            selectorProcessor.Operator  = eldersSelector;
            selectorProcessor.Successor = shiftToRightMigrator;

            eldersSelector.AgeParameter.ActualName            = AgeParameter.Name;
            eldersSelector.AgeLimitsParameter.ActualName      = AgeLimitsParameter.Name;
            eldersSelector.NumberOfLayersParameter.ActualName = NumberOfLayersParameter.Name;
            eldersSelector.LayerParameter.ActualName          = "Layer";
            eldersSelector.Successor = null;

            shiftToRightMigrator.ClockwiseMigrationParameter.Value = new BoolValue(true);
            shiftToRightMigrator.Successor = mergingProcessor;

            mergingProcessor.Operator = mergingReducer;

            mergingReducer.Successor = subScopesCounter1;

            subScopesCounter1.ValueParameter.ActualName = CurrentPopulationSizeParameter.Name;
            subScopesCounter1.AccumulateParameter.Value = new BoolValue(false);
            subScopesCounter1.Successor = currentPopulationSizeComparator;

            currentPopulationSizeComparator.LeftSideParameter.ActualName  = CurrentPopulationSizeParameter.Name;
            currentPopulationSizeComparator.RightSideParameter.ActualName = OneParameter.Name;
            currentPopulationSizeComparator.ResultParameter.ActualName    = "CurrentPopulationSizeIsGreaterThanOne";
            currentPopulationSizeComparator.Comparison = new Comparison(ComparisonType.Greater);
            currentPopulationSizeComparator.Successor  = currentPopulationSizeIsGreaterThanOne;

            currentPopulationSizeIsGreaterThanOne.ConditionParameter.ActualName = "CurrentPopulationSizeIsGreaterThanOne";
            currentPopulationSizeIsGreaterThanOne.TrueBranch = rankAndCrowdingSorter;

            // We have to sort individuals before reducing, because if we shifted some of them to another layer, it can happen that they are not correctly sorted
            rankAndCrowdingSorter.DominateOnEqualQualitiesParameter.ActualName = DominateOnEqualQualitiesParameter.Name;
            rankAndCrowdingSorter.CrowdingDistanceParameter.ActualName         = "CrowdingDistance";
            rankAndCrowdingSorter.RankParameter.ActualName = "Rank";
            rankAndCrowdingSorter.Successor = reduceToPopulationSizeBranch;

            reduceToPopulationSizeBranch.ConditionParameter.ActualName = ReduceToPopulationSizeParameter.Name;
            reduceToPopulationSizeBranch.TrueBranch = countCalculator;

            countCalculator.CollectedValues.Add(new LookupParameter <IntValue>(PopulationSizeParameter.Name));
            countCalculator.CollectedValues.Add(new LookupParameter <IntValue>(CurrentPopulationSizeParameter.Name));
            countCalculator.ExpressionParameter.Value            = new StringValue("CurrentPopulationSize PopulationSize CurrentPopulationSize PopulationSize < if toint");
            countCalculator.ExpressionResultParameter.ActualName = CurrentPopulationSizeParameter.Name;
            countCalculator.Successor = leftSelector;

            leftSelector.CopySelected = new BoolValue(false);
            leftSelector.NumberOfSelectedSubScopesParameter.ActualName = CurrentPopulationSizeParameter.Name;
            leftSelector.Successor = rightReducer;

            rightReducer.Successor = subScopesCounter2;
            subScopesCounter2.ValueParameter.ActualName = CurrentPopulationSizeParameter.Name;
            subScopesCounter2.AccumulateParameter.Value = new BoolValue(false);

            return(eldersEmigrator);
        }
Esempio n. 14
0
        private void Initialize()
        {
            #region Create parameters

            Parameters.Add(new ValueLookupParameter <IRandom>("GlobalRandom", "A pseudo random number generator."));
            Parameters.Add(new ValueLookupParameter <IRandom>("LocalRandom", "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>("NumberOfLayers", "The number of layers."));
            Parameters.Add(new ValueLookupParameter <IntValue>("PopulationSize", "The population size."));
            Parameters.Add(new LookupParameter <IntValue>("CurrentPopulationSize", "The current size of the population."));

            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 ScopeTreeLookupParameter <DoubleValue>("Age", "The age of individuals."));
            Parameters.Add(new ValueLookupParameter <IntValue>("AgeGap", "The frequency of reseeding the lowest layer and scaling factor for the age-limits for the layers."));
            Parameters.Add(new ValueLookupParameter <DoubleValue>("AgeInheritance", "A weight that determines the age of a child after crossover based on the older (1.0) and younger (0.0) parent."));
            Parameters.Add(new ValueLookupParameter <IntArray>("AgeLimits", "The maximum age an individual is allowed to reach in a certain layer."));

            Parameters.Add(new ValueLookupParameter <IntValue>("MatingPoolRange", "The range of sub - populations used for creating a mating pool. (1 = current + previous sub-population)"));
            Parameters.Add(new ValueLookupParameter <BoolValue>("ReduceToPopulationSize", "Reduce the CurrentPopulationSize after elder migration to PopulationSize"));

            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 <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 ValueLookupParameter <IOperator>("LayerAnalyzer", "The operator used to analyze each layer."));
            Parameters.Add(new ValueLookupParameter <IOperator>("FinalAnalyzer", "The operator used to finally analyze the solution (after termination of the algorithm)."));

            Parameters.Add(new LookupParameter <IntValue>("EvaluatedSolutions", "The number of times solutions have been evaluated."));
            Parameters.Add(new ValueLookupParameter <BoolValue>("DominateOnEqualQualities", "Flag which determines whether solutions with equal quality values should be treated as dominated."));

            Parameters.Add(new ValueLookupParameter <IOperator>("Terminator", "The termination criteria that defines if the algorithm should continue or stop"));

            Parameters.Add(new FixedValueParameter <IntValue>("Zero", "Zero Value.", new IntValue(0)));
            Parameters.Add(new FixedValueParameter <IntValue>("One", "1 as a Value.", new IntValue(1)));

            #endregion

            #region Create operators and operator graph

            var variableCreator = new VariableCreator {
                Name = "Initialize"
            };
            var resultsCollector1          = new ResultsCollector();
            var initLayerAnalyzerProcessor = new SubScopesProcessor();
            var layerVariableCreator       = new VariableCreator {
                Name = "Initialize Layer"
            };
            var initLayerAnalyzerPlaceholder = new Placeholder {
                Name = "LayerAnalyzer (Placeholder)"
            };
            var initAnalyzerPlaceholder = new Placeholder {
                Name = "Analyzer (Placeholder)"
            };
            var initFinalAnalyzerPlaceholder = new Placeholder {
                Name = "FinalAnalyzer (Placeholder)"
            };
            var matingPoolCreator = new MatingPoolCreator {
                Name = "Create Mating Pools"
            };
            var matingPoolProcessor = new UniformSubScopesProcessor {
                Name = "Process Mating Pools"
            };
            var initializeLayer = new Assigner {
                Name = "Reset LayerEvaluatedSolutions"
            };
            var mainOperator           = new AlpsNsga2MainOperator();
            var generationsIncrementer = new IntCounter {
                Name = "Increment Generations"
            };
            var evaluatedSolutionsReducer = new DataReducer {
                Name = "Increment EvaluatedSolutions"
            };
            var eldersEmigrator = CreateEldersEmigrator();
            var layerOpener     = CreateLayerOpener();
            var layerReseeder   = CreateReseeder();
            var currentPopulationSizeComparator = new Comparator {
                Name = "Isn't CurrentPopulationSize 0?"
            };
            var currentPopulationSizeIsNotZeroBranch = new ConditionalBranch {
                Name = "CurrentPopulationSize != Zero"
            };
            var layerAnalyzerProcessor   = new UniformSubScopesProcessor();
            var layerAnalyzerPlaceholder = new Placeholder {
                Name = "LayerAnalyzer (Placeholder)"
            };
            var analyzerPlaceholder = new Placeholder {
                Name = "Analyzer (Placeholder)"
            };
            var termination           = new TerminationOperator();
            var rankAndCrowdingSorter = new RankAndCrowdingSorter();
            var mergingReducer        = new MergingReducer();
            var leftSelector          = new LeftSelector();
            var rightReducer          = new RightReducer();

            OperatorGraph.InitialOperator = variableCreator;

            variableCreator.CollectedValues.Add(new ValueParameter <IntValue>("Generations", new IntValue(0)));
            variableCreator.CollectedValues.Add(new ValueParameter <IntValue>("OpenLayers", new IntValue(1)));
            variableCreator.Successor = initLayerAnalyzerProcessor;

            initLayerAnalyzerProcessor.Operators.Add(layerVariableCreator);
            initLayerAnalyzerProcessor.Successor = initAnalyzerPlaceholder;

            layerVariableCreator.CollectedValues.Add(new ValueParameter <IntValue>("Layer", new IntValue(0)));
            layerVariableCreator.CollectedValues.Add(new ValueParameter <ResultCollection>("LayerResults"));
            layerVariableCreator.Successor = initLayerAnalyzerPlaceholder;

            initLayerAnalyzerPlaceholder.OperatorParameter.ActualName = LayerAnalyzerParameter.Name;
            initLayerAnalyzerPlaceholder.Successor = null;

            initAnalyzerPlaceholder.OperatorParameter.ActualName = AnalyzerParameter.Name;
            initAnalyzerPlaceholder.Successor = resultsCollector1;

            resultsCollector1.CollectedValues.Add(new LookupParameter <IntValue>("Generations"));
            resultsCollector1.CollectedValues.Add(new ScopeTreeLookupParameter <ResultCollection>("LayerResults", "Result set for each Layer", "LayerResults"));
            resultsCollector1.CollectedValues.Add(new LookupParameter <IntValue>("OpenLayers"));
            resultsCollector1.CopyValue = new BoolValue(false);
            resultsCollector1.ResultsParameter.ActualName = ResultsParameter.Name;
            resultsCollector1.Successor = matingPoolCreator;

            matingPoolCreator.MatingPoolRangeParameter.Value      = null;
            matingPoolCreator.MatingPoolRangeParameter.ActualName = MatingPoolRangeParameter.Name;
            matingPoolCreator.Successor = matingPoolProcessor;

            matingPoolProcessor.Parallel.Value = true;
            matingPoolProcessor.Operator       = initializeLayer;
            matingPoolProcessor.Successor      = generationsIncrementer;

            initializeLayer.LeftSideParameter.ActualName = "LayerEvaluatedSolutions";
            initializeLayer.RightSideParameter.Value     = new IntValue(0);
            initializeLayer.Successor = mainOperator;

            mainOperator.RandomParameter.ActualName               = LocalRandomParameter.Name;
            mainOperator.EvaluatorParameter.ActualName            = EvaluatorParameter.Name;
            mainOperator.EvaluatedSolutionsParameter.ActualName   = "LayerEvaluatedSolutions";
            mainOperator.QualityParameter.ActualName              = QualitiesParameter.Name;
            mainOperator.MaximizationParameter.ActualName         = MaximizationParameter.Name;
            mainOperator.PopulationSizeParameter.ActualName       = PopulationSizeParameter.Name;
            mainOperator.SelectorParameter.ActualName             = SelectorParameter.Name;
            mainOperator.CrossoverParameter.ActualName            = CrossoverParameter.Name;
            mainOperator.CrossoverProbabilityParameter.ActualName = CrossoverProbabilityParameter.Name;
            mainOperator.MutatorParameter.ActualName              = MutatorParameter.ActualName;
            mainOperator.MutationProbabilityParameter.ActualName  = MutationProbabilityParameter.Name;
            mainOperator.AgeParameter.ActualName            = AgeParameter.Name;
            mainOperator.AgeInheritanceParameter.ActualName = AgeInheritanceParameter.Name;
            mainOperator.AgeIncrementParameter.Value        = new DoubleValue(1.0);
            mainOperator.Successor = null;

            generationsIncrementer.ValueParameter.ActualName = "Generations";
            generationsIncrementer.Increment = new IntValue(1);
            generationsIncrementer.Successor = evaluatedSolutionsReducer;

            evaluatedSolutionsReducer.ParameterToReduce.ActualName = "LayerEvaluatedSolutions";
            evaluatedSolutionsReducer.TargetParameter.ActualName   = EvaluatedSolutionsParameter.Name;
            evaluatedSolutionsReducer.ReductionOperation.Value     = new ReductionOperation(ReductionOperations.Sum);
            evaluatedSolutionsReducer.TargetOperation.Value        = new ReductionOperation(ReductionOperations.Sum);
            evaluatedSolutionsReducer.Successor = eldersEmigrator;

            eldersEmigrator.Successor = layerOpener;

            layerOpener.Successor = layerReseeder;

            layerReseeder.Successor = layerAnalyzerProcessor;

            // Layer analyzer is only performed if individuals count is not 0
            layerAnalyzerProcessor.Operator  = currentPopulationSizeComparator;
            layerAnalyzerProcessor.Successor = analyzerPlaceholder;

            currentPopulationSizeComparator.LeftSideParameter.ActualName  = CurrentPopulationSizeParameter.Name;
            currentPopulationSizeComparator.RightSideParameter.ActualName = ZeroParameter.Name;
            currentPopulationSizeComparator.ResultParameter.ActualName    = "CurrentPopulationSizeIsNotZero";
            currentPopulationSizeComparator.Comparison = new Comparison(ComparisonType.NotEqual);
            currentPopulationSizeComparator.Successor  = currentPopulationSizeIsNotZeroBranch;

            currentPopulationSizeIsNotZeroBranch.ConditionParameter.ActualName = "CurrentPopulationSizeIsNotZero";
            currentPopulationSizeIsNotZeroBranch.TrueBranch = layerAnalyzerPlaceholder;

            layerAnalyzerPlaceholder.OperatorParameter.ActualName = LayerAnalyzerParameter.Name;

            analyzerPlaceholder.OperatorParameter.ActualName = AnalyzerParameter.Name;
            analyzerPlaceholder.Successor = termination;

            termination.TerminatorParameter.ActualName = TerminatorParameter.Name;
            termination.ContinueBranch = matingPoolCreator;

            termination.TerminateBranch = mergingReducer;
            mergingReducer.Successor    = rankAndCrowdingSorter;

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

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

            rightReducer.Successor = initFinalAnalyzerPlaceholder;

            initFinalAnalyzerPlaceholder.OperatorParameter.ActualName = FinalAnalyzerParameter.Name;

            #endregion
        }
Esempio n. 15
0
        private void Initialize()
        {
            #region Create parameters
            Parameters.Add(new ValueLookupParameter <IRandom>("Random", "A pseudo random number generator."));
            Parameters.Add(new ValueLookupParameter <BoolValue>("Maximization", "True if the problem is a maximization problem, otherwise false."));
            Parameters.Add(new ScopeTreeLookupParameter <DoubleValue>("Quality", "The value which represents the quality of a solution."));
            Parameters.Add(new ValueLookupParameter <IOperator>("Selector", "The operator used to select solutions for reproduction."));
            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>("Elites", "The numer of elite solutions which are kept in each generation."));
            Parameters.Add(new ValueLookupParameter <BoolValue>("ReevaluateElites", "Flag to determine if elite individuals should be reevaluated (i.e., if stochastic fitness functions are used.)"));
            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 ValueLookupParameter <IntValue>("EvaluatedSolutions", "The number of times solutions have been evaluated."));
            Parameters.Add(new ValueLookupParameter <IntValue>("PopulationSize", "The size of the population."));
            Parameters.Add(new ScopeParameter("CurrentScope", "The current scope which represents a population of solutions on which the genetic algorithm should be applied."));
            #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();
            Placeholder               crossover                  = new Placeholder();
            StochasticBranch          stochasticBranch           = new StochasticBranch();
            Placeholder               mutator                    = new Placeholder();
            SubScopesRemover          subScopesRemover           = new SubScopesRemover();
            UniformSubScopesProcessor uniformSubScopesProcessor2 = new UniformSubScopesProcessor();
            Placeholder               evaluator                  = new Placeholder();
            SubScopesCounter          subScopesCounter           = new SubScopesCounter();
            SubScopesProcessor        subScopesProcessor2        = new SubScopesProcessor();
            BestSelector              bestSelector               = new BestSelector();
            RightReducer              rightReducer               = new RightReducer();
            MergingReducer            mergingReducer             = new MergingReducer();
            IntCounter        intCounter             = new IntCounter();
            Comparator        comparator             = new Comparator();
            Placeholder       analyzer2              = new Placeholder();
            ConditionalBranch conditionalBranch      = new ConditionalBranch();
            ConditionalBranch reevaluateElitesBranch = new ConditionalBranch();

            variableCreator.CollectedValues.Add(new ValueParameter <IntValue>("Generations", new IntValue(0))); // Class GeneticAlgorithm expects this to be called Generations

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

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

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

            childrenCreator.ParentsPerChild = new IntValue(2);

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

            stochasticBranch.ProbabilityParameter.ActualName = "MutationProbability";
            stochasticBranch.RandomParameter.ActualName      = "Random";

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

            subScopesRemover.RemoveAllSubScopes = true;

            uniformSubScopesProcessor2.Parallel.Value = true;

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

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

            bestSelector.CopySelected = new BoolValue(false);
            bestSelector.MaximizationParameter.ActualName = "Maximization";
            bestSelector.NumberOfSelectedSubScopesParameter.ActualName = "Elites";
            bestSelector.QualityParameter.ActualName = "Quality";

            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 = "MaximumGenerations";

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

            conditionalBranch.ConditionParameter.ActualName = "Terminate";

            reevaluateElitesBranch.ConditionParameter.ActualName = "ReevaluateElites";
            reevaluateElitesBranch.Name = "Reevaluate elites ?";
            #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        = subScopesProcessor2;
            childrenCreator.Successor            = uniformSubScopesProcessor1;
            uniformSubScopesProcessor1.Operator  = crossover;
            uniformSubScopesProcessor1.Successor = uniformSubScopesProcessor2;
            crossover.Successor                  = stochasticBranch;
            stochasticBranch.FirstBranch         = mutator;
            stochasticBranch.SecondBranch        = null;
            stochasticBranch.Successor           = subScopesRemover;
            mutator.Successor                    = null;
            subScopesRemover.Successor           = null;
            uniformSubScopesProcessor2.Operator  = evaluator;
            uniformSubScopesProcessor2.Successor = subScopesCounter;
            evaluator.Successor                  = null;
            subScopesCounter.Successor           = null;
            subScopesProcessor2.Operators.Add(bestSelector);
            subScopesProcessor2.Operators.Add(new EmptyOperator());
            subScopesProcessor2.Successor      = mergingReducer;
            bestSelector.Successor             = rightReducer;
            rightReducer.Successor             = reevaluateElitesBranch;
            reevaluateElitesBranch.TrueBranch  = uniformSubScopesProcessor2;
            reevaluateElitesBranch.FalseBranch = null;
            reevaluateElitesBranch.Successor   = null;
            mergingReducer.Successor           = intCounter;
            intCounter.Successor          = comparator;
            comparator.Successor          = analyzer2;
            analyzer2.Successor           = conditionalBranch;
            conditionalBranch.FalseBranch = selector;
            conditionalBranch.TrueBranch  = null;
            conditionalBranch.Successor   = null;
            #endregion
        }
        public AlpsNsga2MainOperator() : base()
        {
            Parameters.Add(new ValueLookupParameter <IRandom>("Random", "A pseudo random number generator."));

            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>("EvaluatedSolutions", "The number of times solutions have been evaluated."));
            Parameters.Add(new ScopeTreeLookupParameter <DoubleValue>("Quality", "The value which represents the quality of a solution."));
            Parameters.Add(new ValueLookupParameter <BoolValue>("Maximization", "True if the problem is a maximization problem, otherwise false."));

            Parameters.Add(new ValueLookupParameter <IntValue>("PopulationSize", "The size of the population of solutions in each layer."));
            Parameters.Add(new ValueLookupParameter <IOperator>("Selector", "The operator used to select solutions for reproduction."));

            Parameters.Add(new ValueLookupParameter <IOperator>("Crossover", "The operator used to cross solutions."));
            Parameters.Add(new ValueLookupParameter <PercentValue>("CrossoverProbability", "The probability that the crossover operator is applied on a solution."));
            Parameters.Add(new ValueLookupParameter <IOperator>("Mutator", "The operator used to mutate solutions."));
            Parameters.Add(new ValueLookupParameter <PercentValue>("MutationProbability", "The probability that the mutation operator is applied on a solution."));

            Parameters.Add(new ScopeTreeLookupParameter <DoubleValue>("Age", "The age of individuals."));
            Parameters.Add(new ValueLookupParameter <DoubleValue>("AgeInheritance", "A weight that determines the age of a child after crossover based on the older (1.0) and younger (0.0) parent."));
            Parameters.Add(new ValueLookupParameter <DoubleValue>("AgeIncrement", "The value the age the individuals is incremented if they survives a generation."));

            Parameters.Add(new ValueLookupParameter <BoolValue>("DominateOnEqualQualities", "Flag which determines whether solutions with equal quality values should be treated as dominated."));

            var selector = new Placeholder {
                Name = "Selector (Placeholder)"
            };
            var subScopesProcessor1        = new SubScopesProcessor();
            var childrenCreator            = new ChildrenCreator();
            var uniformSubScopesProcessor1 = new UniformSubScopesProcessor();
            var crossoverStochasticBranch  = new StochasticBranch {
                Name = "CrossoverProbability"
            };
            var crossover = new Placeholder {
                Name = "Crossover (Placeholder)"
            };
            var noCrossover = new ParentCopyCrossover();
            var mutationStochasticBranch = new StochasticBranch {
                Name = "MutationProbability"
            };
            var mutator = new Placeholder {
                Name = "Mutator (Placeholder)"
            };
            var ageCalculator = new WeightingReducer {
                Name = "Calculate Age"
            };
            var subScopesRemover           = new SubScopesRemover();
            var uniformSubScopesProcessor2 = new UniformSubScopesProcessor();
            var evaluator = new Placeholder {
                Name = "Evaluator (Placeholder)"
            };
            var subScopesCounter = new SubScopesCounter {
                Name = "Increment EvaluatedSolutions"
            };
            var mergingReducer         = new MergingReducer();
            var rankAndCrowdingSorter1 = new RankAndCrowdingSorter();
            var rankAndCrowdingSorter2 = new RankAndCrowdingSorter();
            var leftSelector           = new LeftSelector();
            var rightReducer           = new RightReducer();
            var incrementAgeProcessor  = new UniformSubScopesProcessor();
            var ageIncrementer         = new DoubleCounter {
                Name = "Increment Age"
            };

            OperatorGraph.InitialOperator = rankAndCrowdingSorter1;

            rankAndCrowdingSorter1.DominateOnEqualQualitiesParameter.ActualName = DominateOnEqualQualitiesParameter.Name;
            rankAndCrowdingSorter1.CrowdingDistanceParameter.ActualName         = "CrowdingDistance";
            rankAndCrowdingSorter1.RankParameter.ActualName = "Rank";
            rankAndCrowdingSorter1.Successor = selector;

            selector.OperatorParameter.ActualName = SelectorParameter.Name;
            selector.Successor = subScopesProcessor1;

            subScopesProcessor1.Operators.Add(new EmptyOperator());
            subScopesProcessor1.Operators.Add(childrenCreator);
            subScopesProcessor1.Successor = mergingReducer;

            childrenCreator.ParentsPerChild = new IntValue(2);
            childrenCreator.Successor       = uniformSubScopesProcessor1;

            uniformSubScopesProcessor1.Operator  = crossoverStochasticBranch;
            uniformSubScopesProcessor1.Successor = uniformSubScopesProcessor2;

            crossoverStochasticBranch.ProbabilityParameter.ActualName = CrossoverProbabilityParameter.Name;
            crossoverStochasticBranch.RandomParameter.ActualName      = RandomParameter.Name;
            crossoverStochasticBranch.FirstBranch  = crossover;
            crossoverStochasticBranch.SecondBranch = noCrossover;
            crossoverStochasticBranch.Successor    = mutationStochasticBranch;

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

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

            mutationStochasticBranch.ProbabilityParameter.ActualName = MutationProbabilityParameter.Name;
            mutationStochasticBranch.RandomParameter.ActualName      = RandomParameter.Name;
            mutationStochasticBranch.FirstBranch  = mutator;
            mutationStochasticBranch.SecondBranch = null;
            mutationStochasticBranch.Successor    = ageCalculator;

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

            ageCalculator.ParameterToReduce.ActualName = AgeParameter.Name;
            ageCalculator.TargetParameter.ActualName   = AgeParameter.Name;
            ageCalculator.WeightParameter.ActualName   = AgeInheritanceParameter.Name;
            ageCalculator.Successor = subScopesRemover;

            subScopesRemover.RemoveAllSubScopes = true;
            subScopesRemover.Successor          = null;

            uniformSubScopesProcessor2.Parallel.Value = true;
            uniformSubScopesProcessor2.Operator       = evaluator;
            uniformSubScopesProcessor2.Successor      = subScopesCounter;

            evaluator.OperatorParameter.ActualName = EvaluatorParameter.Name;
            evaluator.Successor = null;

            subScopesCounter.ValueParameter.ActualName = EvaluatedSolutionsParameter.Name;
            subScopesCounter.AccumulateParameter.Value = new BoolValue(true);
            subScopesCounter.Successor = null;

            mergingReducer.Successor = rankAndCrowdingSorter2;

            rankAndCrowdingSorter2.DominateOnEqualQualitiesParameter.ActualName = DominateOnEqualQualitiesParameter.Name;
            rankAndCrowdingSorter2.CrowdingDistanceParameter.ActualName         = "CrowdingDistance";
            rankAndCrowdingSorter2.RankParameter.ActualName = "Rank";
            rankAndCrowdingSorter2.Successor = leftSelector;

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

            rightReducer.Successor = incrementAgeProcessor;

            incrementAgeProcessor.Operator  = ageIncrementer;
            incrementAgeProcessor.Successor = null;

            ageIncrementer.ValueParameter.ActualName     = AgeParameter.Name;
            ageIncrementer.IncrementParameter.Value      = null;
            ageIncrementer.IncrementParameter.ActualName = AgeIncrementParameter.Name;
            ageIncrementer.Successor = null;
        }