示例#1
0
        public CMAEvolutionStrategy()
            : base()
        {
            Parameters.Add(new FixedValueParameter <IntValue>(SeedName, "The random seed used to initialize the new pseudo random number generator.", new IntValue(0)));
            Parameters.Add(new FixedValueParameter <BoolValue>(SetSeedRandomlyName, "True if the random seed should be set to a random value, otherwise false.", new BoolValue(true)));
            Parameters.Add(new FixedValueParameter <IntValue>(PopulationSizeName, "λ (lambda) - the size of the offspring population.", new IntValue(20)));
            Parameters.Add(new FixedValueParameter <IntValue>(InitialIterationsName, "The number of iterations that should be performed with only axis parallel mutation.", new IntValue(0)));
            Parameters.Add(new FixedValueParameter <DoubleArray>(InitialSigmaName, "The initial sigma can be a single value or a value for each dimension. All values need to be > 0.", new DoubleArray(new[] { 0.5 })));
            Parameters.Add(new OptionalValueParameter <IntValue>(MuName, "Optional, the mu best offspring that should be considered for update of the new mean and strategy parameters. If not given it will be automatically calculated."));
            Parameters.Add(new ConstrainedValueParameter <ICMARecombinator>(CMARecombinatorName, "The operator used to calculate the new mean."));
            Parameters.Add(new ConstrainedValueParameter <ICMAManipulator>(CMAMutatorName, "The operator used to manipulate a point."));
            Parameters.Add(new ConstrainedValueParameter <ICMAInitializer>(CMAInitializerName, "The operator that initializes the covariance matrix and strategy parameters."));
            Parameters.Add(new ConstrainedValueParameter <ICMAUpdater>(CMAUpdaterName, "The operator that updates the covariance matrix and strategy parameters."));
            Parameters.Add(new ValueParameter <MultiAnalyzer>(AnalyzerName, "The operator used to analyze each generation.", new MultiAnalyzer()));
            Parameters.Add(new FixedValueParameter <IntValue>(MaximumGenerationsName, "The maximum number of generations which should be processed.", new IntValue(1000)));
            Parameters.Add(new FixedValueParameter <IntValue>(MaximumEvaluatedSolutionsName, "The maximum number of evaluated solutions that should be computed.", new IntValue(int.MaxValue)));
            Parameters.Add(new FixedValueParameter <DoubleValue>(TargetQualityName, "(stopFitness) Surpassing this quality value terminates the algorithm.", new DoubleValue(double.NaN)));
            Parameters.Add(new FixedValueParameter <DoubleValue>(MinimumQualityChangeName, "(stopTolFun) If the range of fitness values is less than a certain value the algorithm terminates (set to 0 or positive value to enable).", new DoubleValue(double.NaN)));
            Parameters.Add(new FixedValueParameter <DoubleValue>(MinimumQualityHistoryChangeName, "(stopTolFunHist) If the range of fitness values is less than a certain value for a certain time the algorithm terminates (set to 0 or positive to enable).", new DoubleValue(double.NaN)));
            Parameters.Add(new FixedValueParameter <DoubleValue>(MinimumStandardDeviationName, "(stopTolXFactor) If the standard deviation falls below a certain value the algorithm terminates (set to 0 or positive to enable).", new DoubleValue(double.NaN)));
            Parameters.Add(new FixedValueParameter <DoubleValue>(MaximumStandardDeviationChangeName, "(stopTolUpXFactor) If the standard deviation changes by a value larger than this parameter the algorithm stops (set to a value > 0 to enable).", new DoubleValue(double.NaN)));

            var randomCreator    = new RandomCreator();
            var variableCreator  = new VariableCreator();
            var resultsCollector = new ResultsCollector();
            var cmaInitializer   = new Placeholder();

            solutionCreator = new Placeholder();
            var subScopesCreator = new SubScopesCreator();
            var ussp1            = new UniformSubScopesProcessor();

            populationSolutionCreator = new Placeholder();
            var cmaMutator = new Placeholder();
            var ussp2      = new UniformSubScopesProcessor();

            evaluator = new Placeholder();
            var subScopesCounter = new SubScopesCounter();

            sorter = new SubScopesSorter();
            var analyzer           = new Placeholder();
            var cmaRecombinator    = new Placeholder();
            var generationsCounter = new IntCounter();
            var cmaUpdater         = new Placeholder();

            terminator = new Terminator();

            OperatorGraph.InitialOperator = randomCreator;

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

            variableCreator.Name = "Initialize Variables";
            variableCreator.CollectedValues.Add(new ValueParameter <IntValue>("EvaluatedSolutions", new IntValue(0)));
            variableCreator.CollectedValues.Add(new ValueParameter <IntValue>("Generations", new IntValue(0)));
            variableCreator.Successor = resultsCollector;

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

            cmaInitializer.Name = "Initialize Strategy Parameters";
            cmaInitializer.OperatorParameter.ActualName = CMAInitializerParameter.Name;
            cmaInitializer.Successor = subScopesCreator;

            subScopesCreator.NumberOfSubScopesParameter.ActualName = PopulationSizeParameter.Name;
            subScopesCreator.Successor = ussp1;

            ussp1.Name      = "Create population";
            ussp1.Parallel  = new BoolValue(false);
            ussp1.Operator  = populationSolutionCreator;
            ussp1.Successor = solutionCreator;

            populationSolutionCreator.Name = "Initialize arx";
            // populationSolutionCreator.OperatorParameter will be wired
            populationSolutionCreator.Successor = null;

            solutionCreator.Name = "Initialize xmean";
            // solutionCreator.OperatorParameter will be wired
            solutionCreator.Successor = cmaMutator;

            cmaMutator.Name = "Sample population";
            cmaMutator.OperatorParameter.ActualName = CMAMutatorParameter.Name;
            cmaMutator.Successor = ussp2;

            ussp2.Name      = "Evaluate offspring";
            ussp2.Parallel  = new BoolValue(true);
            ussp2.Operator  = evaluator;
            ussp2.Successor = subScopesCounter;

            evaluator.Name = "Evaluator";
            // evaluator.OperatorParameter will be wired
            evaluator.Successor = null;

            subScopesCounter.Name = "Count EvaluatedSolutions";
            subScopesCounter.AccumulateParameter.Value = new BoolValue(true);
            subScopesCounter.ValueParameter.ActualName = "EvaluatedSolutions";
            subScopesCounter.Successor = sorter;

            // sorter.ValueParameter will be wired
            // sorter.DescendingParameter will be wired
            sorter.Successor = analyzer;

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

            cmaRecombinator.Name = "Create new xmean";
            cmaRecombinator.OperatorParameter.ActualName = CMARecombinatorParameter.Name;
            cmaRecombinator.Successor = generationsCounter;

            generationsCounter.Name = "Generations++";
            generationsCounter.IncrementParameter.Value  = new IntValue(1);
            generationsCounter.ValueParameter.ActualName = "Generations";
            generationsCounter.Successor = cmaUpdater;

            cmaUpdater.Name = "Update distributions";
            cmaUpdater.OperatorParameter.ActualName = CMAUpdaterParameter.Name;
            cmaUpdater.Successor = terminator;

            terminator.Continue  = cmaMutator;
            terminator.Terminate = null;

            qualityAnalyzer = new BestAverageWorstQualityAnalyzer();
            cmaAnalyzer     = new CMAAnalyzer();

            InitializeOperators();
            RegisterEventHandlers();
            Parameterize();
        }
示例#2
0
        public SASEGASA()
            : base()
        {
            Parameters.Add(new ValueParameter <IntValue>("Seed", "The random seed used to initialize the new pseudo random number generator.", new IntValue(0)));
            Parameters.Add(new ValueParameter <BoolValue>("SetSeedRandomly", "True if the random seed should be set to a random value, otherwise false.", new BoolValue(true)));
            Parameters.Add(new ValueParameter <IntValue>("NumberOfVillages", "The initial number of villages.", new IntValue(10)));
            Parameters.Add(new ValueParameter <IntValue>("PopulationSize", "The size of the population of solutions.", new IntValue(100)));
            Parameters.Add(new ValueParameter <IntValue>("MaximumGenerations", "The maximum number of generations that should be processed.", new IntValue(1000)));
            Parameters.Add(new ConstrainedValueParameter <ISelector>("Selector", "The operator used to select solutions for reproduction."));
            Parameters.Add(new ConstrainedValueParameter <ICrossover>("Crossover", "The operator used to cross solutions."));
            Parameters.Add(new ValueParameter <PercentValue>("MutationProbability", "The probability that the mutation operator is applied on a solution.", new PercentValue(0.05)));
            Parameters.Add(new OptionalConstrainedValueParameter <IManipulator>("Mutator", "The operator used to mutate solutions."));
            Parameters.Add(new ValueParameter <IntValue>("Elites", "The numer of elite solutions which are kept in each generation.", new IntValue(1)));
            Parameters.Add(new FixedValueParameter <BoolValue>("ReevaluateElites", "Flag to determine if elite individuals should be reevaluated (i.e., if stochastic fitness functions are used.)", new BoolValue(false))
            {
                Hidden = true
            });
            Parameters.Add(new ValueLookupParameter <DoubleValue>("SuccessRatio", "The ratio of successful to total children that should be achieved.", new DoubleValue(1)));
            Parameters.Add(new ValueLookupParameter <DoubleValue>("ComparisonFactorLowerBound", "The lower bound of the comparison factor (start).", new DoubleValue(0.3)));
            Parameters.Add(new ValueLookupParameter <DoubleValue>("ComparisonFactorUpperBound", "The upper bound of the comparison factor (end).", new DoubleValue(0.7)));
            Parameters.Add(new OptionalConstrainedValueParameter <IDiscreteDoubleValueModifier>("ComparisonFactorModifier", "The operator used to modify the comparison factor.", new ItemSet <IDiscreteDoubleValueModifier>(new IDiscreteDoubleValueModifier[] { new LinearDiscreteDoubleValueModifier() }), new LinearDiscreteDoubleValueModifier()));
            Parameters.Add(new ValueLookupParameter <DoubleValue>("MaximumSelectionPressure", "The maximum selection pressure that terminates the algorithm.", new DoubleValue(100)));
            Parameters.Add(new ValueLookupParameter <DoubleValue>("FinalMaximumSelectionPressure", "The maximum selection pressure used when there is only one village left.", new DoubleValue(100)));
            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.", new BoolValue(false)));
            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.", new IntValue(200)));
            Parameters.Add(new ValueParameter <MultiAnalyzer>("Analyzer", "The operator used to analyze the villages.", new MultiAnalyzer()));
            Parameters.Add(new ValueParameter <MultiAnalyzer>("VillageAnalyzer", "The operator used to analyze each village.", new MultiAnalyzer()));
            Parameters.Add(new ValueParameter <IntValue>("MaximumEvaluatedSolutions", "The maximum number of evaluated solutions (approximately).", new IntValue(int.MaxValue)));
            Parameters.Add(new FixedValueParameter <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.", new BoolValue(true))
            {
                Hidden = true
            });

            RandomCreator             randomCreator     = new RandomCreator();
            SubScopesCreator          populationCreator = new SubScopesCreator();
            UniformSubScopesProcessor ussp1             = new UniformSubScopesProcessor();
            SolutionsCreator          solutionsCreator  = new SolutionsCreator();
            VariableCreator           variableCreator   = new VariableCreator();
            UniformSubScopesProcessor ussp2             = new UniformSubScopesProcessor();
            SubScopesCounter          subScopesCounter  = new SubScopesCounter();
            ResultsCollector          resultsCollector  = new ResultsCollector();
            SASEGASAMainLoop          mainLoop          = new SASEGASAMainLoop();

            OperatorGraph.InitialOperator = randomCreator;

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

            populationCreator.NumberOfSubScopesParameter.ActualName = NumberOfVillagesParameter.Name;
            populationCreator.Successor = ussp1;

            ussp1.Operator  = solutionsCreator;
            ussp1.Successor = variableCreator;

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

            variableCreator.Name = "Initialize EvaluatedSolutions";
            variableCreator.CollectedValues.Add(new ValueParameter <IntValue>("EvaluatedSolutions", new IntValue()));
            variableCreator.Successor = ussp2;

            ussp2.Operator  = subScopesCounter;
            ussp2.Successor = resultsCollector;

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

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

            mainLoop.NumberOfVillagesParameter.ActualName                 = NumberOfVillagesParameter.Name;
            mainLoop.SelectorParameter.ActualName                         = SelectorParameter.Name;
            mainLoop.CrossoverParameter.ActualName                        = CrossoverParameter.Name;
            mainLoop.ElitesParameter.ActualName                           = ElitesParameter.Name;
            mainLoop.ReevaluateElitesParameter.ActualName                 = ReevaluateElitesParameter.Name;
            mainLoop.MutatorParameter.ActualName                          = MutatorParameter.Name;
            mainLoop.MutationProbabilityParameter.ActualName              = MutationProbabilityParameter.Name;
            mainLoop.RandomParameter.ActualName                           = randomCreator.RandomParameter.ActualName;
            mainLoop.ResultsParameter.ActualName                          = "Results";
            mainLoop.SuccessRatioParameter.ActualName                     = SuccessRatioParameter.Name;
            mainLoop.ComparisonFactorStartParameter.ActualName            = ComparisonFactorLowerBoundParameter.Name;
            mainLoop.ComparisonFactorModifierParameter.ActualName         = ComparisonFactorModifierParameter.Name;
            mainLoop.MaximumSelectionPressureParameter.ActualName         = MaximumSelectionPressureParameter.Name;
            mainLoop.FinalMaximumSelectionPressureParameter.ActualName    = FinalMaximumSelectionPressureParameter.Name;
            mainLoop.MaximumGenerationsParameter.ActualName               = MaximumGenerationsParameter.Name;
            mainLoop.OffspringSelectionBeforeMutationParameter.ActualName = OffspringSelectionBeforeMutationParameter.Name;
            mainLoop.EvaluatedSolutionsParameter.ActualName               = "EvaluatedSolutions";
            mainLoop.FillPopulationWithParentsParameter.ActualName        = FillPopulationWithParentsParameter.Name;
            mainLoop.Successor = null;

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

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

            ParameterizeSelectors();

            foreach (IDiscreteDoubleValueModifier modifier in ApplicationManager.Manager.GetInstances <IDiscreteDoubleValueModifier>().OrderBy(x => x.Name))
            {
                ComparisonFactorModifierParameter.ValidValues.Add(modifier);
            }
            IDiscreteDoubleValueModifier linearModifier = ComparisonFactorModifierParameter.ValidValues.FirstOrDefault(x => x.GetType().Name.Equals("LinearDiscreteDoubleValueModifier"));

            if (linearModifier != null)
            {
                ComparisonFactorModifierParameter.Value = linearModifier;
            }
            ParameterizeComparisonFactorModifiers();

            qualityAnalyzer                  = new BestAverageWorstQualityAnalyzer();
            villageQualityAnalyzer           = new BestAverageWorstQualityAnalyzer();
            selectionPressureAnalyzer        = new ValueAnalyzer();
            villageSelectionPressureAnalyzer = new ValueAnalyzer();
            successfulOffspringAnalyzer      = new SuccessfulOffspringAnalyzer();
            ParameterizeAnalyzers();
            UpdateAnalyzers();

            Initialize();
        }
示例#3
0
        public IslandGeneticAlgorithm()
            : base()
        {
            Parameters.Add(new ValueParameter <IntValue>("Seed", "The random seed used to initialize the new pseudo random number generator.", new IntValue(0)));
            Parameters.Add(new ValueParameter <BoolValue>("SetSeedRandomly", "True if the random seed should be set to a random value, otherwise false.", new BoolValue(true)));
            Parameters.Add(new ValueParameter <IntValue>("NumberOfIslands", "The number of islands.", new IntValue(5)));
            Parameters.Add(new ValueParameter <IntValue>("MigrationInterval", "The number of generations that should pass between migration phases.", new IntValue(20)));
            Parameters.Add(new ValueParameter <PercentValue>("MigrationRate", "The proportion of individuals that should migrate between the islands.", new PercentValue(0.15)));
            Parameters.Add(new ConstrainedValueParameter <IMigrator>("Migrator", "The migration strategy."));
            Parameters.Add(new ConstrainedValueParameter <ISelector>("EmigrantsSelector", "Selects the individuals that will be migrated."));
            Parameters.Add(new ConstrainedValueParameter <IReplacer>("ImmigrationReplacer", "Selects the population from the unification of the original population and the immigrants."));
            Parameters.Add(new ValueParameter <IntValue>("PopulationSize", "The size of the population of solutions.", new IntValue(100)));
            Parameters.Add(new ValueParameter <IntValue>("MaximumGenerations", "The maximum number of generations that should be processed.", new IntValue(1000)));
            Parameters.Add(new ConstrainedValueParameter <ISelector>("Selector", "The operator used to select solutions for reproduction."));
            Parameters.Add(new ConstrainedValueParameter <ICrossover>("Crossover", "The operator used to cross solutions."));
            Parameters.Add(new ValueParameter <PercentValue>("MutationProbability", "The probability that the mutation operator is applied on a solution.", new PercentValue(0.05)));
            Parameters.Add(new OptionalConstrainedValueParameter <IManipulator>("Mutator", "The operator used to mutate solutions."));
            Parameters.Add(new ValueParameter <IntValue>("Elites", "The numer of elite solutions which are kept in each generation.", new IntValue(1)));
            Parameters.Add(new FixedValueParameter <BoolValue>("ReevaluateElites", "Flag to determine if elite individuals should be reevaluated (i.e., if stochastic fitness functions are used.)", new BoolValue(false))
            {
                Hidden = true
            });
            Parameters.Add(new ValueParameter <MultiAnalyzer>("Analyzer", "The operator used to analyze the islands.", new MultiAnalyzer()));
            Parameters.Add(new ValueParameter <MultiAnalyzer>("IslandAnalyzer", "The operator used to analyze each island.", new MultiAnalyzer()));

            RandomCreator                  randomCreator        = new RandomCreator();
            UniformSubScopesProcessor      ussp0                = new UniformSubScopesProcessor();
            LocalRandomCreator             localRandomCreator   = new LocalRandomCreator();
            RandomCreator                  globalRandomResetter = new RandomCreator();
            SubScopesCreator               populationCreator    = new SubScopesCreator();
            UniformSubScopesProcessor      ussp1                = new UniformSubScopesProcessor();
            SolutionsCreator               solutionsCreator     = new SolutionsCreator();
            VariableCreator                variableCreator      = new VariableCreator();
            UniformSubScopesProcessor      ussp2                = new UniformSubScopesProcessor();
            SubScopesCounter               subScopesCounter     = new SubScopesCounter();
            ResultsCollector               resultsCollector     = new ResultsCollector();
            IslandGeneticAlgorithmMainLoop mainLoop             = new IslandGeneticAlgorithmMainLoop();

            OperatorGraph.InitialOperator = randomCreator;

            randomCreator.RandomParameter.ActualName          = "GlobalRandom";
            randomCreator.SeedParameter.ActualName            = SeedParameter.Name;
            randomCreator.SeedParameter.Value                 = null;
            randomCreator.SetSeedRandomlyParameter.ActualName = SetSeedRandomlyParameter.Name;
            randomCreator.SetSeedRandomlyParameter.Value      = null;
            randomCreator.Successor = populationCreator;

            populationCreator.NumberOfSubScopesParameter.ActualName = NumberOfIslandsParameter.Name;
            populationCreator.Successor = ussp0;

            ussp0.Operator  = localRandomCreator;
            ussp0.Successor = globalRandomResetter;

            // BackwardsCompatibility3.3
            // the global random is resetted to ensure the same algorithm results
            #region Backwards compatible code, remove global random resetter with 3.4 and rewire the operator graph
            globalRandomResetter.RandomParameter.ActualName     = "GlobalRandom";
            globalRandomResetter.SeedParameter.ActualName       = SeedParameter.Name;
            globalRandomResetter.SeedParameter.Value            = null;
            globalRandomResetter.SetSeedRandomlyParameter.Value = new BoolValue(false);
            globalRandomResetter.Successor = ussp1;
            #endregion

            ussp1.Operator  = solutionsCreator;
            ussp1.Successor = variableCreator;

            solutionsCreator.NumberOfSolutionsParameter.ActualName = PopulationSizeParameter.Name;
            //don't create solutions in parallel because the hive engine would distribute these tasks
            solutionsCreator.ParallelParameter.Value = new BoolValue(false);
            solutionsCreator.Successor = null;

            variableCreator.Name = "Initialize EvaluatedSolutions";
            variableCreator.CollectedValues.Add(new ValueParameter <IntValue>("EvaluatedSolutions", new IntValue()));
            variableCreator.Successor = ussp2;

            ussp2.Operator  = subScopesCounter;
            ussp2.Successor = resultsCollector;

            subScopesCounter.Name = "Count EvaluatedSolutions";
            subScopesCounter.ValueParameter.ActualName = "EvaluatedSolutions";
            subScopesCounter.Successor = null;

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

            mainLoop.EmigrantsSelectorParameter.ActualName   = EmigrantsSelectorParameter.Name;
            mainLoop.ImmigrationReplacerParameter.ActualName = ImmigrationReplacerParameter.Name;
            mainLoop.MaximumGenerationsParameter.ActualName  = MaximumGenerationsParameter.Name;
            mainLoop.MigrationIntervalParameter.ActualName   = MigrationIntervalParameter.Name;
            mainLoop.MigrationRateParameter.ActualName       = MigrationRateParameter.Name;
            mainLoop.MigratorParameter.ActualName            = MigratorParameter.Name;
            mainLoop.NumberOfIslandsParameter.ActualName     = NumberOfIslandsParameter.Name;
            mainLoop.SelectorParameter.ActualName            = SelectorParameter.Name;
            mainLoop.CrossoverParameter.ActualName           = CrossoverParameter.Name;
            mainLoop.ElitesParameter.ActualName              = ElitesParameter.Name;
            mainLoop.ReevaluateElitesParameter.ActualName    = ReevaluateElitesParameter.Name;
            mainLoop.MutatorParameter.ActualName             = MutatorParameter.Name;
            mainLoop.MutationProbabilityParameter.ActualName = MutationProbabilityParameter.Name;
            mainLoop.RandomParameter.ActualName              = randomCreator.RandomParameter.ActualName;
            mainLoop.ResultsParameter.ActualName             = "Results";
            mainLoop.AnalyzerParameter.ActualName            = AnalyzerParameter.Name;
            mainLoop.IslandAnalyzerParameter.ActualName      = IslandAnalyzerParameter.Name;
            mainLoop.EvaluatedSolutionsParameter.ActualName  = "EvaluatedSolutions";
            mainLoop.Successor = null;

            foreach (ISelector selector in ApplicationManager.Manager.GetInstances <ISelector>().Where(x => !(x is IMultiObjectiveSelector)).OrderBy(x => x.Name))
            {
                SelectorParameter.ValidValues.Add(selector);
            }
            ISelector proportionalSelector = SelectorParameter.ValidValues.FirstOrDefault(x => x.GetType().Name.Equals("ProportionalSelector"));
            if (proportionalSelector != null)
            {
                SelectorParameter.Value = proportionalSelector;
            }

            foreach (ISelector selector in ApplicationManager.Manager.GetInstances <ISelector>().Where(x => !(x is IMultiObjectiveSelector)).OrderBy(x => x.Name))
            {
                EmigrantsSelectorParameter.ValidValues.Add(selector);
            }

            foreach (IReplacer replacer in ApplicationManager.Manager.GetInstances <IReplacer>().OrderBy(x => x.Name))
            {
                ImmigrationReplacerParameter.ValidValues.Add(replacer);
            }

            ParameterizeSelectors();

            foreach (IMigrator migrator in ApplicationManager.Manager.GetInstances <IMigrator>().OrderBy(x => x.Name))
            {
                // BackwardsCompatibility3.3
                // Set the migration direction to counterclockwise
                var unidirectionalRing = migrator as UnidirectionalRingMigrator;
                if (unidirectionalRing != null)
                {
                    unidirectionalRing.ClockwiseMigrationParameter.Value = new BoolValue(false);
                }
                MigratorParameter.ValidValues.Add(migrator);
            }

            qualityAnalyzer       = new BestAverageWorstQualityAnalyzer();
            islandQualityAnalyzer = new BestAverageWorstQualityAnalyzer();
            ParameterizeAnalyzers();
            UpdateAnalyzers();

            Initialize();
        }
示例#4
0
        public AlpsOffspringSelectionGeneticAlgorithm()
            : base()
        {
            #region Add parameters
            Parameters.Add(new FixedValueParameter <IntValue>("Seed", "The random seed used to initialize the new pseudo random number generator.", new IntValue(0)));
            Parameters.Add(new FixedValueParameter <BoolValue>("SetSeedRandomly", "True if the random seed should be set to a random value, otherwise false.", new BoolValue(true)));

            Parameters.Add(new FixedValueParameter <MultiAnalyzer>("Analyzer", "The operator used to analyze all individuals from all layers combined.", new MultiAnalyzer()));
            Parameters.Add(new FixedValueParameter <MultiAnalyzer>("LayerAnalyzer", "The operator used to analyze each layer.", new MultiAnalyzer()));

            Parameters.Add(new FixedValueParameter <IntValue>("NumberOfLayers", "The number of layers.", new IntValue(10)));
            Parameters.Add(new FixedValueParameter <IntValue>("PopulationSize", "The size of the population of solutions in each layer.", new IntValue(100)));

            Parameters.Add(new ConstrainedValueParameter <ISelector>("Selector", "The operator used to select solutions for reproduction."));
            Parameters.Add(new ConstrainedValueParameter <ICrossover>("Crossover", "The operator used to cross solutions."));
            Parameters.Add(new ConstrainedValueParameter <IManipulator>("Mutator", "The operator used to mutate solutions."));
            Parameters.Add(new FixedValueParameter <PercentValue>("MutationProbability", "The probability that the mutation operator is applied on a solution.", new PercentValue(0.05)));
            Parameters.Add(new FixedValueParameter <IntValue>("Elites", "The numer of elite solutions which are kept in each generation.", new IntValue(1)));
            Parameters.Add(new FixedValueParameter <BoolValue>("ReevaluateElites", "Flag to determine if elite individuals should be reevaluated (i.e., if stochastic fitness functions are used.)", new BoolValue(false))
            {
                Hidden = true
            });

            Parameters.Add(new FixedValueParameter <DoubleValue>("SuccessRatio", "The ratio of successful to total children that should be achieved.", new DoubleValue(1)));
            Parameters.Add(new FixedValueParameter <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].", new DoubleValue(1)));
            Parameters.Add(new FixedValueParameter <DoubleValue>("MaximumSelectionPressure", "The maximum selection pressure that terminates the algorithm.", new DoubleValue(100)));
            Parameters.Add(new FixedValueParameter <BoolValue>("OffspringSelectionBeforeMutation", "True if the offspring selection step should be applied before mutation, false if it should be applied after mutation.", new BoolValue(false)));
            Parameters.Add(new FixedValueParameter <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.", new IntValue(200)));
            Parameters.Add(new FixedValueParameter <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.", new BoolValue(false))
            {
                Hidden = true
            });

            Parameters.Add(new FixedValueParameter <EnumValue <AgingScheme> >("AgingScheme", "The aging scheme for setting the age-limits for the layers.", new EnumValue <AgingScheme>(ALPS.AgingScheme.Polynomial)));
            Parameters.Add(new FixedValueParameter <IntValue>("AgeGap", "The frequency of reseeding the lowest layer and scaling factor for the age-limits for the layers.", new IntValue(20)));
            Parameters.Add(new FixedValueParameter <DoubleValue>("AgeInheritance", "A weight that determines the age of a child after crossover based on the older (1.0) and younger (0.0) parent.", new DoubleValue(1.0))
            {
                Hidden = true
            });
            Parameters.Add(new FixedValueParameter <IntArray>("AgeLimits", "The maximum age an individual is allowed to reach in a certain layer.", new IntArray(new int[0]))
            {
                Hidden = true
            });

            Parameters.Add(new FixedValueParameter <IntValue>("MatingPoolRange", "The range of layers used for creating a mating pool. (1 = current + previous layer)", new IntValue(1))
            {
                Hidden = true
            });
            Parameters.Add(new FixedValueParameter <BoolValue>("ReduceToPopulationSize", "Reduce the CurrentPopulationSize after elder migration to PopulationSize", new BoolValue(true))
            {
                Hidden = true
            });

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

            #region Create operators
            var globalRandomCreator = new RandomCreator();
            var layer0Creator       = new SubScopesCreator()
            {
                Name = "Create Layer Zero"
            };
            var layer0Processor        = new SubScopesProcessor();
            var localRandomCreator     = new LocalRandomCreator();
            var layerSolutionsCreator  = new SolutionsCreator();
            var initializeAgeProcessor = new UniformSubScopesProcessor();
            var initializeAge          = new VariableCreator()
            {
                Name = "Initialize Age"
            };
            var initializeCurrentPopulationSize = new SubScopesCounter()
            {
                Name = "Initialize CurrentPopulationCounter"
            };
            var initializeLocalEvaluatedSolutions = new Assigner()
            {
                Name = "Initialize LayerEvaluatedSolutions"
            };
            var initializeGlobalEvaluatedSolutions = new DataReducer()
            {
                Name = "Initialize EvaluatedSolutions"
            };
            var resultsCollector = new ResultsCollector();
            var mainLoop         = new AlpsOffspringSelectionGeneticAlgorithmMainLoop();
            #endregion

            #region Create and parameterize operator graph
            OperatorGraph.InitialOperator = globalRandomCreator;

            globalRandomCreator.RandomParameter.ActualName          = "GlobalRandom";
            globalRandomCreator.SeedParameter.Value                 = null;
            globalRandomCreator.SeedParameter.ActualName            = SeedParameter.Name;
            globalRandomCreator.SetSeedRandomlyParameter.Value      = null;
            globalRandomCreator.SetSeedRandomlyParameter.ActualName = SetSeedRandomlyParameter.Name;
            globalRandomCreator.Successor = layer0Creator;

            layer0Creator.NumberOfSubScopesParameter.Value = new IntValue(1);
            layer0Creator.Successor = layer0Processor;

            layer0Processor.Operators.Add(localRandomCreator);
            layer0Processor.Successor = initializeGlobalEvaluatedSolutions;

            localRandomCreator.Successor = layerSolutionsCreator;

            layerSolutionsCreator.NumberOfSolutionsParameter.ActualName = PopulationSizeParameter.Name;
            layerSolutionsCreator.Successor = initializeAgeProcessor;

            initializeAgeProcessor.Operator  = initializeAge;
            initializeAgeProcessor.Successor = initializeCurrentPopulationSize;

            initializeCurrentPopulationSize.ValueParameter.ActualName = "CurrentPopulationSize";
            initializeCurrentPopulationSize.Successor = initializeLocalEvaluatedSolutions;

            initializeAge.CollectedValues.Add(new ValueParameter <DoubleValue>("Age", new DoubleValue(0)));
            initializeAge.Successor = null;

            initializeLocalEvaluatedSolutions.LeftSideParameter.ActualName  = "LayerEvaluatedSolutions";
            initializeLocalEvaluatedSolutions.RightSideParameter.ActualName = "CurrentPopulationSize";
            initializeLocalEvaluatedSolutions.Successor = null;

            initializeGlobalEvaluatedSolutions.ReductionOperation.Value.Value = ReductionOperations.Sum;
            initializeGlobalEvaluatedSolutions.TargetOperation.Value.Value    = ReductionOperations.Assign;
            initializeGlobalEvaluatedSolutions.ParameterToReduce.ActualName   = "LayerEvaluatedSolutions";
            initializeGlobalEvaluatedSolutions.TargetParameter.ActualName     = "EvaluatedSolutions";
            initializeGlobalEvaluatedSolutions.Successor = resultsCollector;

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

            mainLoop.GlobalRandomParameter.ActualName          = "GlobalRandom";
            mainLoop.LocalRandomParameter.ActualName           = localRandomCreator.LocalRandomParameter.Name;
            mainLoop.EvaluatedSolutionsParameter.ActualName    = "EvaluatedSolutions";
            mainLoop.AnalyzerParameter.ActualName              = AnalyzerParameter.Name;
            mainLoop.LayerAnalyzerParameter.ActualName         = LayerAnalyzerParameter.Name;
            mainLoop.NumberOfLayersParameter.ActualName        = NumberOfLayersParameter.Name;
            mainLoop.PopulationSizeParameter.ActualName        = PopulationSizeParameter.Name;
            mainLoop.CurrentPopulationSizeParameter.ActualName = "CurrentPopulationSize";
            mainLoop.SelectorParameter.ActualName              = SelectorParameter.Name;
            mainLoop.CrossoverParameter.ActualName             = CrossoverParameter.Name;
            mainLoop.MutatorParameter.ActualName             = MutatorParameter.Name;
            mainLoop.MutationProbabilityParameter.ActualName = MutationProbabilityParameter.Name;
            mainLoop.ElitesParameter.ActualName                           = ElitesParameter.Name;
            mainLoop.ReevaluateElitesParameter.ActualName                 = ReevaluateElitesParameter.Name;
            mainLoop.SuccessRatioParameter.ActualName                     = SuccessRatioParameter.Name;
            mainLoop.ComparisonFactorParameter.ActualName                 = ComparisonFactorParameter.Name;
            mainLoop.MaximumSelectionPressureParameter.ActualName         = MaximumSelectionPressureParameter.Name;
            mainLoop.OffspringSelectionBeforeMutationParameter.ActualName = OffspringSelectionBeforeMutationParameter.Name;
            mainLoop.FillPopulationWithParentsParameter.ActualName        = FillPopulationWithParentsParameter.Name;
            mainLoop.AgeParameter.ActualName                    = "Age";
            mainLoop.AgeGapParameter.ActualName                 = AgeGapParameter.Name;
            mainLoop.AgeInheritanceParameter.ActualName         = AgeInheritanceParameter.Name;
            mainLoop.AgeLimitsParameter.ActualName              = AgeLimitsParameter.Name;
            mainLoop.MatingPoolRangeParameter.ActualName        = MatingPoolRangeParameter.Name;
            mainLoop.ReduceToPopulationSizeParameter.ActualName = ReduceToPopulationSizeParameter.Name;
            mainLoop.TerminatorParameter.ActualName             = TerminatorParameter.Name;
            #endregion

            #region Set operators
            foreach (var selector in ApplicationManager.Manager.GetInstances <ISelector>().Where(s => !(s is IMultiObjectiveSelector)).OrderBy(s => Name))
            {
                SelectorParameter.ValidValues.Add(selector);
            }
            var defaultSelector = SelectorParameter.ValidValues.OfType <GeneralizedRankSelector>().FirstOrDefault();
            if (defaultSelector != null)
            {
                defaultSelector.PressureParameter.Value = new DoubleValue(4.0);
                SelectorParameter.Value = defaultSelector;
            }
            #endregion

            #region Create analyzers
            qualityAnalyzer                = new BestAverageWorstQualityAnalyzer();
            layerQualityAnalyzer           = new BestAverageWorstQualityAnalyzer();
            ageAnalyzer                    = new OldestAverageYoungestAgeAnalyzer();
            layerAgeAnalyzer               = new OldestAverageYoungestAgeAnalyzer();
            ageDistributionAnalyzer        = new AgeDistributionAnalyzer();
            layerAgeDistributionAnalyzer   = new AgeDistributionAnalyzer();
            selectionPressureAnalyzer      = new ValueAnalyzer();
            layerSelectionPressureAnalyzer = new ValueAnalyzer();
            currentSuccessRatioAnalyzer    = new ValueAnalyzer();
            #endregion

            #region Create terminators
            generationsTerminator = new ComparisonTerminator <IntValue>("Generations", ComparisonType.Less, new IntValue(1000))
            {
                Name = "Generations"
            };
            evaluationsTerminator = new ComparisonTerminator <IntValue>("EvaluatedSolutions", ComparisonType.Less, new IntValue(int.MaxValue))
            {
                Name = "Evaluations"
            };
            qualityTerminator = new SingleObjectiveQualityTerminator()
            {
                Name = "Quality"
            };
            executionTimeTerminator = new ExecutionTimeTerminator(this, new TimeSpanValue(TimeSpan.FromMinutes(5)));
            #endregion

            #region Parameterize
            UpdateAnalyzers();
            ParameterizeAnalyzers();

            ParameterizeSelectors();

            UpdateTerminators();

            ParameterizeAgeLimits();
            #endregion

            Initialize();
        }