Free cookie consent management tool by TermsFeed Policy Generator

Changeset 13604


Ignore:
Timestamp:
02/08/16 15:55:31 (9 years ago)
Author:
pkuelzer
Message:

#2558 Include LayerNumber in GroupResults
Added Migration

Location:
branches/IslandALPS/IslandALPS/3.3
Files:
1 added
3 edited

Legend:

Unmodified
Added
Removed
  • branches/IslandALPS/IslandALPS/3.3/HeuristicLab.Algorithms.IslandALPS-3.3.csproj

    r13595 r13604  
    105105  </ItemGroup>
    106106  <ItemGroup>
     107    <Compile Include="LayerMigrator.cs" />
    107108    <Compile Include="ResultsExtractor.cs" />
    108109    <Compile Include="IslandALPSAlgorithm.cs" />
  • branches/IslandALPS/IslandALPS/3.3/IslandALPSAlgorithm.cs

    r13595 r13604  
    8383      get { return (IValueParameter<IntValue>)Parameters["MigrationInterval"]; }
    8484    }
    85 
     85    public IConstrainedValueParameter<IMigrator> MigratorParameter {
     86      get { return (IConstrainedValueParameter<IMigrator>)Parameters["Migrator"]; }
     87    }
     88    public IConstrainedValueParameter<ISelector> EmigrantsSelectorParameter {
     89      get { return (IConstrainedValueParameter<ISelector>)Parameters["EmigrantsSelector"]; }
     90    }
     91    public IConstrainedValueParameter<IReplacer> ImmigrationReplacerParameter {
     92      get { return (IConstrainedValueParameter<IReplacer>)Parameters["ImmigrationReplacer"]; }
     93    }
    8694    #endregion
    8795
     
    284292      Parameters.Add(new ValueParameter<IntValue>("MigrationInterval", "The number Generations before a migration occurs.", new IntValue(20)));
    285293      Parameters.Add(new ValueParameter<MultiAnalyzer>("IslandAnalyzer", "The operator used to analyze each island.", new MultiAnalyzer()));
     294      Parameters.Add(new ConstrainedValueParameter<IMigrator>("Migrator", "The migration strategy."));
     295      Parameters.Add(new ConstrainedValueParameter<ISelector>("EmigrantsSelector", "Selects the individuals that will be migrated."));
     296      Parameters.Add(new ConstrainedValueParameter<IReplacer>("ImmigrationReplacer", "Selects the population from the unification of the original population and the immigrants."));
    286297
    287298      #endregion
     
    429440      UpdateTerminators();
    430441      ParameterizeAgeLimits();
     442      ParametrizeMigration();
    431443      #endregion
    432444
     
    585597      ElitesParameter.ValueChanged += ElitesParameter_ValueChanged;
    586598      Elites.ValueChanged += Elites_ValueChanged;
     599      MigrationRateParameter.Value.ValueChanged += MigrationRate_ValueChanged;
     600      MigrationRateParameter.ValueChanged += MigrationRate_ValueChanged;
    587601
    588602      Analyzer.Operators.ItemsAdded += AnalyzerOperators_ItemsAdded;
     
    603617      NumberOfLayers.ValueChanged += NumberOfLayers_ValueChanged;
    604618
     619    }
     620
     621    private void MigrationRate_ValueChanged(object sender, EventArgs e) {
     622      var migrationSize = (int)Math.Ceiling(MigrationRateParameter.Value.Value * PopulationSize.Value);
     623      foreach (var selector in EmigrantsSelectorParameter.ValidValues) {
     624        selector.NumberOfSelectedSubScopesParameter.Value = new IntValue(migrationSize);
     625      }
    605626    }
    606627
     
    719740      MainLoop.NumberOfLayersParameter.ActualName = NumberOfLayersParameter.Name;
    720741      MainLoop.MigrationIntervalParameter.ActualName = MigrationIntervalParameter.Name;
     742      MainLoop.MigratorParameter.ActualName = MigratorParameter.Name;
     743      MainLoop.EmigrantsSelectorParameter.ActualName = EmigrantsSelectorParameter.Name;
     744      MainLoop.ImmigrationReplacerParameter.ActualName = ImmigrationReplacerParameter.Name;
     745
     746
     747
    721748      MainLoop.PopulationSizeParameter.ActualName = PopulationSizeParameter.Name;
    722749      MainLoop.CurrentPopulationSizeParameter.ActualName = "CurrentPopulationSize";
     
    738765    }
    739766
     767    private void ParametrizeMigration() {
     768      var migrationSize = (int) Math.Ceiling(MigrationRateParameter.Value.Value *PopulationSize.Value);
     769      foreach (ISelector selector in ApplicationManager.Manager.GetInstances<ISelector>().Where(x => !(x is IMultiObjectiveSelector)).OrderBy(x => x.Name)) {
     770        selector.NumberOfSelectedSubScopesParameter.Value = new IntValue(migrationSize);
     771        selector.NumberOfSelectedSubScopesParameter.Hidden = true;
     772
     773        ParameterizeStochasticOperatorForLayer(selector);
     774
     775        EmigrantsSelectorParameter.ValidValues.Add(selector);
     776      }
     777
     778      foreach (IReplacer replacer in ApplicationManager.Manager.GetInstances<IReplacer>().OrderBy(x => x.Name)) {
     779        ParameterizeStochasticOperatorForLayer(replacer);
     780        ImmigrationReplacerParameter.ValidValues.Add(replacer);
     781      }
     782
     783      MigratorParameter.ValidValues.Add(new LayerMigrator());
     784    }
     785
    740786    private void ParameterizeSolutionsCreator() {
    741787      SolutionsCreator.EvaluatorParameter.ActualName = Problem.EvaluatorParameter.Name;
     
    750796        ParameterizeStochasticOperatorForLayer(selector);
    751797      }
     798
    752799      if (Problem != null) {
    753800        foreach (var selector in SelectorParameter.ValidValues.OfType<ISingleObjectiveSelector>()) {
    754           selector.MaximizationParameter.ActualName = Problem.MaximizationParameter.Name;
    755           selector.MaximizationParameter.Hidden = true;
    756           selector.QualityParameter.ActualName = Problem.Evaluator.QualityParameter.ActualName;
    757           selector.QualityParameter.Hidden = true;
    758         }
    759       }
     801          ParametrizeSingleObjectiveSelector(selector);
     802        }
     803        foreach (var replacer in EmigrantsSelectorParameter.ValidValues.OfType<ISingleObjectiveSelector>()) {
     804          ParametrizeSingleObjectiveSelector(replacer);
     805        }
     806        foreach (var selector in ImmigrationReplacerParameter.ValidValues.OfType<ISingleObjectiveSelector>()) {
     807          ParametrizeSingleObjectiveSelector(selector);
     808        }
     809
     810      }
     811    }
     812
     813    private void ParametrizeSingleObjectiveSelector(ISingleObjectiveSelector selector) {
     814      selector.MaximizationParameter.ActualName = Problem.MaximizationParameter.Name;
     815      selector.MaximizationParameter.Hidden = true;
     816      selector.QualityParameter.ActualName = Problem.Evaluator.QualityParameter.ActualName;
     817      selector.QualityParameter.Hidden = true;
    760818    }
    761819
  • branches/IslandALPS/IslandALPS/3.3/IslandALPSAlgorthmsMainLoop.cs

    r13595 r13604  
    225225      var resultsCollector = new ResultsCollector();
    226226
    227       var processIslandsUssp = new UniformSubScopesProcessor() {Name = "Process Islands"};
     227      var processIslandsUssp = new UniformSubScopesProcessor() {Name = "Process Islands", Parallel = new BoolValue(true)};
    228228      var initIslandGenerationsAss = new Assigner() {Name = "Init Island Generations"};
    229229      var initIslandEvaluationsAss = new Assigner() {Name = "Init Island Evaluations"};
     
    231231      var incrementGenerationDr = new DataReducer() { Name = "Increment Generations" };
    232232      var incrementEvaluatedSolutionDr = new DataReducer() { Name = "Increment Evaluated Solutions" };
    233       //TODO: increase migration count + migrate
    234233
    235234      var elderMigrator = CreateEldersEmigrator();
     
    250249      var groupResultsExtractor = new ResultsExtractor() {Name = "Collect group results into variable"};
    251250      var groupResultsCollector = new ResultsCollector() {Name = "Collect group results into into global results"};
    252 
     251      var groupLayerNumberResultsCollector = new ResultsCollector() {Name = "Add Layernumber to Results"};
    253252
    254253      var matingPoolCreator = new MatingPoolCreator();
    255254      var matingPoolUssp = new UniformSubScopesProcessor() {Name = "Process Mating Pools"};
    256       var alpsMainOperator =new AlpsGeneticAlgorithmMainOperator();
     255      var alpsMainOperator = new AlpsGeneticAlgorithmMainOperator();
    257256
    258257      var incrementIslandGeneration = new IntCounter() {Name = "incrementIslandGeneration" };
    259258      var setIslandEvaluatedSolutions = new DataReducer() {Name = "Set IslandEvaluatedSolutions" };
     259       
     260      var migrationCounter = new IntCounter() {Name = "Increment  Migrations"};
     261      var selectforMigrationUssp = new UniformSubScopesProcessor();
     262      var emigrantSelector = new Placeholder() {Name = "Emigrant Selector (Placeholder)"};
     263      var migrator = new LayerMigrator();
     264      var replaceforMigrationUssp = new UniformSubScopesProcessor();
     265      var immigrantSelector = new Placeholder() { Name = "Immigrant Replacer (Placeholder)" };
    260266
    261267      var migrateComparator = new Comparator();
     
    283289      resultsCollector.CollectedValues.Add(new ScopeTreeLookupParameter<ResultCollection>("IslandResults","","IslandResults"));
    284290      resultsCollector.CollectedValues.Add(new ScopeTreeLookupParameter<ResultCollection>("GroupResults","","GroupResults"));
     291      resultsCollector.CollectedValues.Add(new ValueLookupParameter<IntValue>("Migrations"));
    285292      resultsCollector.CopyValue = new BoolValue(false);
    286293
     
    314321      migrateCondBranch.ConditionParameter.ActualName = "Migrate";
    315322
     323      migrationCounter.ValueParameter.ActualName = "Migrations";
     324      selectforMigrationUssp.Depth = new IntValue(2);
     325      emigrantSelector.OperatorParameter.ActualName = EmigrantsSelectorParameter.Name;
     326
     327      replaceforMigrationUssp.Depth = new IntValue(2);
     328      immigrantSelector.OperatorParameter.ActualName = ImmigrationReplacerParameter.Name;
     329
    316330      groupAnalyzer.OperatorParameter.ActualName = GroupAnalyzerParameter.Name;
     331      groupLayerNumberResultsCollector.CollectedValues.Add(new LookupParameter<IntValue>("LayerNumber"));
     332      groupLayerNumberResultsCollector.ResultsParameter.ActualName = "GroupResults";
     333
    317334      layerAnalyzerPlaceholder.OperatorParameter.ActualName = LayerAnalyzerParameter.Name;
    318335      layerResultsCollector.ResultsParameter.ActualName = "LayerResults";
     
    384401      processIslandsUssp.Successor = incrementGenerationDr;
    385402      incrementGenerationDr.Successor = incrementEvaluatedSolutionDr;
    386       incrementEvaluatedSolutionDr.Successor = globalAnalyzerPlacerholder;
     403      incrementEvaluatedSolutionDr.Successor = migrationCounter;
     404     
     405      migrationCounter.Successor = selectforMigrationUssp;
     406      selectforMigrationUssp.Operator = emigrantSelector;
     407      emigrantSelector.Successor = null;
     408      selectforMigrationUssp.Successor = migrator;
     409
     410      migrator.Successor = replaceforMigrationUssp;
     411      replaceforMigrationUssp.Operator = immigrantSelector;
     412      immigrantSelector.Successor = null;
     413      replaceforMigrationUssp.Successor = globalAnalyzerPlacerholder;
     414
    387415      globalAnalyzerPlacerholder.Successor = groupingOperator;
    388416      groupingOperator.Operator = groupAnalyzer;
    389       groupAnalyzer.Successor = null;
     417      groupAnalyzer.Successor = groupLayerNumberResultsCollector;
     418      groupLayerNumberResultsCollector.Successor = null;
    390419      groupingOperator.Successor = groupResultsExtractor;
    391420      groupResultsExtractor.Successor = groupResultsCollector;
Note: See TracChangeset for help on using the changeset viewer.