private IslandGeneticAlgorithmMainLoop(IslandGeneticAlgorithmMainLoop original, Cloner cloner)
     : base(original, cloner)
 {
 }
 private IslandGeneticAlgorithmMainLoop(IslandGeneticAlgorithmMainLoop original, Cloner cloner)
   : base(original, cloner) {
 }
Beispiel #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();
        }
    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();
    }