public AlpsOffspringSelectionGeneticAlgorithmMainLoop()
      : base() {
      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<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<IOperator>("Analyzer", "The operator used to analyze all individuals from all layers combined."));
      Parameters.Add(new ValueLookupParameter<IOperator>("LayerAnalyzer", "The operator used to analyze each layer."));

      Parameters.Add(new ValueLookupParameter<IntValue>("NumberOfLayers", "The number of layers."));
      Parameters.Add(new ValueLookupParameter<IntValue>("PopulationSize", "The size of the population of solutions in each layer."));
      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<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<DoubleValue>("SuccessRatio", "The ratio of successful to total children that should be achieved."));
      Parameters.Add(new ValueLookupParameter<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 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."));

      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>("Terminator", "The termination criteria that defines if the algorithm should continue or stop"));


      var variableCreator = new VariableCreator() { Name = "Initialize" };
      var initLayerAnalyzerProcessor = new SubScopesProcessor();
      var layerVariableCreator = new VariableCreator() { Name = "Initialize Layer" };
      var initLayerAnalyzerPlaceholder = new Placeholder() { Name = "LayerAnalyzer (Placeholder)" };
      var layerResultCollector = new ResultsCollector() { Name = "Collect layer results" };
      var initAnalyzerPlaceholder = new Placeholder() { Name = "Analyzer (Placeholder)" };
      var resultsCollector = new ResultsCollector();
      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 AlpsOffspringSelectionGeneticAlgorithmMainOperator();
      var generationsIcrementor = new IntCounter() { Name = "Increment Generations" };
      var evaluatedSolutionsReducer = new DataReducer() { Name = "Increment EvaluatedSolutions" };
      var eldersEmigrator = CreateEldersEmigrator();
      var layerOpener = CreateLayerOpener();
      var layerReseeder = CreateReseeder();
      var layerAnalyzerProcessor = new UniformSubScopesProcessor();
      var layerAnalyzerPlaceholder = new Placeholder() { Name = "LayerAnalyzer (Placeholder)" };
      var analyzerPlaceholder = new Placeholder() { Name = "Analyzer (Placeholder)" };
      var termination = new TerminationOperator();

      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.CollectedValues.Add(new ValueParameter<DoubleValue>("SelectionPressure", new DoubleValue(0)));
      layerVariableCreator.CollectedValues.Add(new ValueParameter<DoubleValue>("CurrentSuccessRatio", new DoubleValue(0)));
      layerVariableCreator.Successor = initLayerAnalyzerPlaceholder;

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

      layerResultCollector.ResultsParameter.ActualName = "LayerResults";
      layerResultCollector.CollectedValues.Add(new LookupParameter<DoubleValue>("Current Selection Pressure", "Displays the rising selection pressure during a generation.", "SelectionPressure"));
      layerResultCollector.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"));
      layerResultCollector.Successor = null;

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

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

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

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

      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 = QualityParameter.Name;
      mainOperator.MaximizationParameter.ActualName = MaximizationParameter.Name;
      mainOperator.PopulationSizeParameter.ActualName = PopulationSizeParameter.Name;
      mainOperator.SelectorParameter.ActualName = SelectorParameter.Name;
      mainOperator.CrossoverParameter.ActualName = CrossoverParameter.Name;
      mainOperator.MutatorParameter.ActualName = MutatorParameter.ActualName;
      mainOperator.MutationProbabilityParameter.ActualName = MutationProbabilityParameter.Name;
      mainOperator.ElitesParameter.ActualName = ElitesParameter.Name;
      mainOperator.ReevaluateElitesParameter.ActualName = ReevaluateElitesParameter.Name;
      mainOperator.ComparisonFactorParameter.ActualName = ComparisonFactorParameter.Name;
      mainOperator.SuccessRatioParameter.ActualName = SuccessRatioParameter.Name;
      mainOperator.CurrentSuccessRatioParameter.ActualName = "CurrentSuccessRatio";
      mainOperator.SelectionPressureParameter.ActualName = "SelectionPressure";
      mainOperator.MaximumSelectionPressureParameter.ActualName = MaximumSelectionPressureParameter.Name;
      mainOperator.OffspringSelectionBeforeMutationParameter.ActualName = OffspringSelectionBeforeMutationParameter.Name;
      mainOperator.FillPopulationWithParentsParameter.ActualName = FillPopulationWithParentsParameter.Name;
      mainOperator.AgeParameter.ActualName = AgeParameter.Name;
      mainOperator.AgeInheritanceParameter.ActualName = AgeInheritanceParameter.Name;
      mainOperator.AgeIncrementParameter.Value = new DoubleValue(1.0);
      mainOperator.Successor = null;

      generationsIcrementor.ValueParameter.ActualName = "Generations";
      generationsIcrementor.Increment = new IntValue(1);
      generationsIcrementor.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;

      layerAnalyzerProcessor.Operator = layerAnalyzerPlaceholder;
      layerAnalyzerProcessor.Successor = analyzerPlaceholder;

      layerAnalyzerPlaceholder.OperatorParameter.ActualName = LayerAnalyzerParameter.Name;

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

      termination.TerminatorParameter.ActualName = TerminatorParameter.Name;
      termination.ContinueBranch = matingPoolCreator;
    }
예제 #2
0
 private MatingPoolCreator(MatingPoolCreator original, Cloner cloner)
   : base(original, cloner) { }
예제 #3
0
 private MatingPoolCreator(MatingPoolCreator original, Cloner cloner)
     : base(original, cloner)
 {
 }
        public AlpsGeneticAlgorithmMainLoop()
            : base()
        {
            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 <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 <IOperator>("Analyzer", "The operator used to analyze all individuals from all layers combined."));
            Parameters.Add(new ValueLookupParameter <IOperator>("LayerAnalyzer", "The operator used to analyze each layer."));

            Parameters.Add(new ValueLookupParameter <IntValue>("NumberOfLayers", "The number of layers."));
            Parameters.Add(new ValueLookupParameter <IntValue>("PopulationSize", "The size of the population of solutions in each layer."));
            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 <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 <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>("Terminator", "The termination criteria that defines if the algorithm should continue or stop"));


            var variableCreator = new VariableCreator()
            {
                Name = "Initialize"
            };
            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 resultsCollector  = new ResultsCollector();
            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 AlpsGeneticAlgorithmMainOperator();
            var generationsIcrementor = new IntCounter()
            {
                Name = "Increment Generations"
            };
            var evaluatedSolutionsReducer = new DataReducer()
            {
                Name = "Increment EvaluatedSolutions"
            };
            var eldersEmigrator          = CreateEldersEmigrator();
            var layerOpener              = CreateLayerOpener();
            var layerReseeder            = CreateReseeder();
            var layerAnalyzerProcessor   = new UniformSubScopesProcessor();
            var layerAnalyzerPlaceholder = new Placeholder()
            {
                Name = "LayerAnalyzer (Placeholder)"
            };
            var analyzerPlaceholder = new Placeholder()
            {
                Name = "Analyzer (Placeholder)"
            };
            var termination = new TerminationOperator();

            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 = resultsCollector;

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

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

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

            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             = QualityParameter.Name;
            mainOperator.MaximizationParameter.ActualName        = MaximizationParameter.Name;
            mainOperator.PopulationSizeParameter.ActualName      = PopulationSizeParameter.Name;
            mainOperator.SelectorParameter.ActualName            = SelectorParameter.Name;
            mainOperator.CrossoverParameter.ActualName           = CrossoverParameter.Name;
            mainOperator.MutatorParameter.ActualName             = MutatorParameter.ActualName;
            mainOperator.MutationProbabilityParameter.ActualName = MutationProbabilityParameter.Name;
            mainOperator.ElitesParameter.ActualName              = ElitesParameter.Name;
            mainOperator.ReevaluateElitesParameter.ActualName    = ReevaluateElitesParameter.Name;
            mainOperator.PlusSelectionParameter.ActualName       = PlusSelectionParameter.Name;
            mainOperator.AgeParameter.ActualName            = AgeParameter.Name;
            mainOperator.AgeInheritanceParameter.ActualName = AgeInheritanceParameter.Name;
            mainOperator.AgeIncrementParameter.Value        = new DoubleValue(1.0);
            mainOperator.Successor = null;

            generationsIcrementor.ValueParameter.ActualName = "Generations";
            generationsIcrementor.Increment = new IntValue(1);
            generationsIcrementor.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;

            layerAnalyzerProcessor.Operator  = layerAnalyzerPlaceholder;
            layerAnalyzerProcessor.Successor = analyzerPlaceholder;

            layerAnalyzerPlaceholder.OperatorParameter.ActualName = LayerAnalyzerParameter.Name;

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

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