Free cookie consent management tool by TermsFeed Policy Generator

Changeset 13595 for branches


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

#2558 Added GroupedLayerAnalyzer
Fixed an evaluated solutions bug

Location:
branches/IslandALPS/IslandALPS
Files:
4 added
6 edited

Legend:

Unmodified
Added
Removed
  • branches/IslandALPS/IslandALPS

    • Property svn:global-ignores set to
      .vs
  • branches/IslandALPS/IslandALPS/3.3

    • Property svn:global-ignores set to
      .vs
      obj
  • branches/IslandALPS/IslandALPS/3.3/HeuristicLab.Algorithms.IslandALPS-3.3.csproj

    r13493 r13595  
    105105  </ItemGroup>
    106106  <ItemGroup>
     107    <Compile Include="ResultsExtractor.cs" />
    107108    <Compile Include="IslandALPSAlgorithm.cs" />
    108109    <Compile Include="IslandALPSAlgorthmsMainLoop.cs" />
    109110    <Compile Include="Plugin.cs" />
    110111    <Compile Include="Properties\AssemblyInfo.cs" />
     112    <Compile Include="GroupedLayerOperator.cs" />
    111113  </ItemGroup>
    112114  <ItemGroup>
  • branches/IslandALPS/IslandALPS/3.3/IslandALPS

    • Property svn:global-ignores set to
      bin
      obj
  • branches/IslandALPS/IslandALPS/3.3/IslandALPSAlgorithm.cs

    r13493 r13595  
    6262      get { return (IValueParameter<MultiAnalyzer>)Parameters["LayerAnalyzer"]; }
    6363    }
     64    private IValueParameter<MultiAnalyzer> GroupAnalyzerParameter {
     65      get { return (IValueParameter<MultiAnalyzer>)Parameters["GroupAnalyzer"]; }
     66    }
    6467    private IValueParameter<BoolValue> PlusSelectionParameter {
    6568      get { return (IValueParameter<BoolValue>)Parameters["PlusSelection"]; }
     
    149152      set { LayerAnalyzerParameter.Value = value; }
    150153    }
     154    public MultiAnalyzer GroupAnalyzer {
     155      get { return GroupAnalyzerParameter.Value; }
     156      set { GroupAnalyzerParameter.Value = value; }
     157    }
    151158    public ISelector Selector {
    152159      get { return SelectorParameter.Value; }
     
    224231    [Storable] private readonly BestAverageWorstQualityAnalyzer islandQualityAnalyzer;
    225232    [Storable] private readonly BestAverageWorstQualityAnalyzer layerQualityAnalyzer;
     233    [Storable] private readonly BestAverageWorstQualityAnalyzer groupQualityAnalyzer;
    226234
    227235    #endregion
     
    246254      islandQualityAnalyzer = cloner.Clone(original.islandQualityAnalyzer);
    247255      layerQualityAnalyzer = cloner.Clone(original.layerQualityAnalyzer);
     256      groupQualityAnalyzer = cloner.Clone(original.groupQualityAnalyzer);
    248257      //terminator
    249258      generationsTerminator = cloner.Clone(original.generationsTerminator);
     
    266275      Parameters.Add(new ValueParameter<IntValue>("NumberOfLayers", "", new IntValue(10)));
    267276      Parameters.Add(new ValueParameter<MultiAnalyzer>("LayerAnalyzer", "The operator used to analyze each layer.", new MultiAnalyzer()));
     277      Parameters.Add(new ValueParameter<MultiAnalyzer>("GroupAnalyzer", "The operator used to analyze each layergroup.", new MultiAnalyzer()));
    268278      Parameters.Add(new ValueParameter<BoolValue>("PlusSelection", "Include the parents in the selection of the invividuals for the next generation.", new BoolValue(false)));
    269279
     
    334344      islandQualityAnalyzer = new BestAverageWorstQualityAnalyzer();
    335345      layerQualityAnalyzer = new BestAverageWorstQualityAnalyzer();
     346      groupQualityAnalyzer = new BestAverageWorstQualityAnalyzer();
    336347      #endregion
    337348
     
    519530      LayerAnalyzer.Operators.Clear();
    520531      IslandAnalyzer.Operators.Clear();
     532      GroupAnalyzer.Operators.Clear();
    521533      Analyzer.Operators.Clear();
    522534
    523535      //add analyzer
     536      GroupAnalyzer.Operators.Add(groupQualityAnalyzer, groupQualityAnalyzer.EnabledByDefault);
    524537      LayerAnalyzer.Operators.Add(layerQualityAnalyzer, layerQualityAnalyzer.EnabledByDefault);
    525538      IslandAnalyzer.Operators.Add(islandQualityAnalyzer, islandQualityAnalyzer.EnabledByDefault);
    526539      Analyzer.Operators.Add(qualityAnalyzer, qualityAnalyzer.EnabledByDefault);
    527 
    528540      //depth for each analyzer gets set when added
    529541      if (Problem != null) {
     
    532544          IslandAnalyzer.Operators.Add((IAnalyzer)analyzer.Clone(),false);
    533545          LayerAnalyzer.Operators.Add((IAnalyzer)analyzer.Clone(), false);
     546          GroupAnalyzer.Operators.Add((IAnalyzer) analyzer.Clone(),false);
    534547        }
    535548      }
     
    576589      IslandAnalyzer.Operators.ItemsAdded += IslandAnalyzerOperators_ItemsAdded;
    577590      LayerAnalyzer.Operators.ItemsAdded += LayerAnalyzerOperators_ItemsAdded;
     591      GroupAnalyzer.Operators.ItemsAdded += GroupAnalyzerOperators_ItemsAdded;
    578592
    579593      if (Problem != null) {
     
    589603      NumberOfLayers.ValueChanged += NumberOfLayers_ValueChanged;
    590604
     605    }
     606
     607    private void GroupAnalyzerOperators_ItemsAdded(object sender, CollectionItemsChangedEventArgs<IndexedItem<IAnalyzer>> e) {
     608      foreach (var analyzer in e.Items) {
     609        IParameter resultParameter;
     610        if (analyzer.Value.Parameters.TryGetValue("Results", out resultParameter)) {
     611          var lookupParameter = resultParameter as ILookupParameter;
     612          if (lookupParameter != null)
     613            lookupParameter.ActualName = "GroupResults";
     614        }
     615        foreach (var parameter in analyzer.Value.Parameters.OfType<IScopeTreeLookupParameter>()) {
     616          parameter.Depth = 1;
     617        }
     618      }
    591619    }
    592620
     
    685713
    686714      MainLoop.EvaluatorParameter.ActualName = Problem.EvaluatorParameter.Name;
    687       MainLoop.LayerEvaluatedSolutionsParameter.ActualName = "EvaluatedSolutions";
     715      MainLoop.LayerEvaluatedSolutionsParameter.ActualName = "LayerEvaluatedSolutions";
    688716
    689717      MainLoop.PlusSelectionParameter.ActualName = PlusSelectionParameter.Name;
     
    700728      MainLoop.TerminatorParameter.ActualName = TerminatorParameter.Name;
    701729
     730      MainLoop.AnalyzerParameter.ActualName = AnalyzerParameter.Name;
     731      MainLoop.LayerAnalyzerParameter.ActualName = LayerAnalyzerParameter.Name;
     732      MainLoop.IslandAnalyzerParameter.ActualName = IslandAnalyzerParameter.Name;
     733      MainLoop.GroupAnalyzerParameter.ActualName = GroupAnalyzerParameter.Name;
     734
     735
    702736      MainLoop.QualityParameter.ActualName = Problem.Evaluator.QualityParameter.ActualName;
    703737      MainLoop.MaximizationParameter.ActualName = Problem.MaximizationParameter.Name;
     
    735769      qualityAnalyzer.ResultsParameter.ActualName = "Results";
    736770      qualityAnalyzer.ResultsParameter.Hidden = true;
    737      
     771
     772      groupQualityAnalyzer.ResultsParameter.ActualName = "GroupResults";
     773      groupQualityAnalyzer.ResultsParameter.Hidden = true;
    738774
    739775      if (Problem != null) {
    740 
    741         layerQualityAnalyzer.MaximizationParameter.ActualName = Problem.MaximizationParameter.Name;
    742         layerQualityAnalyzer.MaximizationParameter.Hidden = true;
    743         layerQualityAnalyzer.QualityParameter.ActualName = Problem.Evaluator.QualityParameter.ActualName;
    744         layerQualityAnalyzer.QualityParameter.Hidden = true;
    745         layerQualityAnalyzer.BestKnownQualityParameter.ActualName = Problem.BestKnownQualityParameter.Name;
    746         layerQualityAnalyzer.BestKnownQualityParameter.Hidden = true;
    747         islandQualityAnalyzer.MaximizationParameter.ActualName = Problem.MaximizationParameter.Name;
    748         islandQualityAnalyzer.MaximizationParameter.Hidden = true;
    749         islandQualityAnalyzer.QualityParameter.ActualName = Problem.Evaluator.QualityParameter.ActualName;
    750         islandQualityAnalyzer.QualityParameter.Hidden = true;
    751         islandQualityAnalyzer.BestKnownQualityParameter.ActualName = Problem.BestKnownQualityParameter.Name;
    752         islandQualityAnalyzer.BestKnownQualityParameter.Hidden = true;
    753         qualityAnalyzer.MaximizationParameter.ActualName = Problem.MaximizationParameter.Name;
    754         qualityAnalyzer.MaximizationParameter.Hidden = true;
    755         qualityAnalyzer.QualityParameter.ActualName = Problem.Evaluator.QualityParameter.ActualName;
    756         qualityAnalyzer.QualityParameter.Hidden = true;
    757         qualityAnalyzer.BestKnownQualityParameter.ActualName = Problem.BestKnownQualityParameter.Name;
    758         qualityAnalyzer.BestKnownQualityParameter.Hidden = true;
    759       }
     776        SetAnalyzerParameter(layerQualityAnalyzer);
     777        SetAnalyzerParameter(islandQualityAnalyzer);
     778        SetAnalyzerParameter(qualityAnalyzer);
     779        SetAnalyzerParameter(groupQualityAnalyzer);
     780      }
     781    }
     782
     783    private void SetAnalyzerParameter(BestAverageWorstQualityAnalyzer analyzer) {
     784      analyzer.MaximizationParameter.ActualName = Problem.MaximizationParameter.Name;
     785      analyzer.MaximizationParameter.Hidden = true;
     786      analyzer.QualityParameter.ActualName = Problem.Evaluator.QualityParameter.ActualName;
     787      analyzer.QualityParameter.Hidden = true;
     788      analyzer.BestKnownQualityParameter.ActualName = Problem.BestKnownQualityParameter.Name;
     789      analyzer.BestKnownQualityParameter.Hidden = true;
    760790    }
    761791
  • branches/IslandALPS/IslandALPS/3.3/IslandALPSAlgorthmsMainLoop.cs

    r13493 r13595  
    8080      get { return (ValueLookupParameter<IOperator>)Parameters["LayerAnalyzer"]; }
    8181    }
     82
     83    public ValueLookupParameter<IOperator> GroupAnalyzerParameter {
     84      get { return (ValueLookupParameter<IOperator>)Parameters["GroupAnalyzer"]; }
     85    }
     86
    8287    public LookupParameter<IntValue> LayerEvaluatedSolutionsParameter {
    8388      get { return (LookupParameter<IntValue>)Parameters["LayerEvaluatedSolutions"]; }
     
    196201      Parameters.Add(new ValueLookupParameter<IOperator>("IslandAnalyzer", "The operator used to analyze each island."));
    197202      Parameters.Add(new ValueLookupParameter<IOperator>("LayerAnalyzer", "The operator used to analyze each Layer."));
     203      Parameters.Add(new ValueLookupParameter<IOperator>("GroupAnalyzer", "The operator used to analyze each Layergroup."));
     204
    198205      Parameters.Add(new LookupParameter<IntValue>("LayerEvaluatedSolutions", "The number of times a solution has been evaluated."));
    199206      Parameters.Add(new LookupParameter<IntValue>("IslandGenerations", "The number of generations calculated on one island."));
     
    208215      var islandVarCreatorUssp = new UniformSubScopesProcessor();
    209216      var islandVariableCreator = new VariableCreator() {Name = "Initialize Results"};
     217      var groupVariableCreator = new VariableCreator() {Name = "Initialize Group Results"};
    210218
    211219      var layerUssp = new UniformSubScopesProcessor();
     
    221229      var initIslandEvaluationsAss = new Assigner() {Name = "Init Island Evaluations"};
    222230
    223       var incrementGenerationDr = new IntCounter(){ Name = "Increment Generations" };
     231      var incrementGenerationDr = new DataReducer() { Name = "Increment Generations" };
    224232      var incrementEvaluatedSolutionDr = new DataReducer() { Name = "Increment Evaluated Solutions" };
    225233      //TODO: increase migration count + migrate
     
    234242      var layerResultsCollector = new ResultsCollector() {Name = "Collect Additional Infos"};
    235243      var islandAnalyzerPlaceholder = new Placeholder() { Name = "Island Analyzer (Placeholder)" };
     244      var islandResultsCollector = new ResultsCollector() { Name = "Collect layer results into IslandResults" };
     245
    236246      var globalAnalyzerPlacerholder = new Placeholder() { Name = "Global Analyzer (Placeholder)" };
     247
     248      var groupingOperator = new GroupedLayerOperator() {Name = "Grouped Analyzer"};
     249      var groupAnalyzer = new Placeholder() {Name = "Group Analyzer (Placeholder)"};
     250      var groupResultsExtractor = new ResultsExtractor() {Name = "Collect group results into variable"};
     251      var groupResultsCollector = new ResultsCollector() {Name = "Collect group results into into global results"};
     252
    237253
    238254      var matingPoolCreator = new MatingPoolCreator();
    239255      var matingPoolUssp = new UniformSubScopesProcessor() {Name = "Process Mating Pools"};
    240256      var alpsMainOperator =new AlpsGeneticAlgorithmMainOperator();
     257
     258      var incrementIslandGeneration = new IntCounter() {Name = "incrementIslandGeneration" };
     259      var setIslandEvaluatedSolutions = new DataReducer() {Name = "Set IslandEvaluatedSolutions" };
     260
     261      var migrateComparator = new Comparator();
     262      var migrateCondBranch = new ConditionalBranch() {Name = "Migrate?"};
    241263
    242264      var terminator = new TerminationOperator();
     
    245267      globalVariableCreator.CollectedValues.Add(new ValueParameter<IntValue>("Migrations",new IntValue(0)));
    246268
    247       islandVariableCreator.CollectedValues.Add(new ValueParameter<IntValue>("IslandGenerations", new IntValue(0)));
     269      islandVariableCreator.CollectedValues.Add(new ValueParameter<IntValue>(IslandGenerations.Name, new IntValue(0)));
    248270      islandVariableCreator.CollectedValues.Add(new ValueParameter<IntValue>("OpenLayers", new IntValue(1)));
    249271      islandVariableCreator.CollectedValues.Add(new ValueParameter<ResultCollection>("IslandResults"));
     
    252274      layerVariableCreator.CollectedValues.Add(new ValueParameter<ResultCollection>("LayerResults"));
    253275
     276      groupVariableCreator.CollectedValues.Add((new ValueParameter<ResultCollection>("GroupResults")));
     277      //TODO: groupAnalyze
    254278      initLayerAnalyzerPlaceholder.OperatorParameter.ActualName = LayerAnalyzerParameter.Name;
    255 
    256279      initIslandAnalyzerPlaceholder.OperatorParameter.ActualName = IslandAnalyzerParameter.Name;
    257 
    258280      initGlobalAnalyzerPlacerholder.OperatorParameter.ActualName = AnalyzerParameter.Name;
    259281
    260282      resultsCollector.CollectedValues.Add(new LookupParameter<IntValue>("Generations"));
    261283      resultsCollector.CollectedValues.Add(new ScopeTreeLookupParameter<ResultCollection>("IslandResults","","IslandResults"));
    262       resultsCollector.CollectedValues.Add(new ScopeTreeLookupParameter<ResultCollection>("LayerResults","","LayerResults",2));
     284      resultsCollector.CollectedValues.Add(new ScopeTreeLookupParameter<ResultCollection>("GroupResults","","GroupResults"));
    263285      resultsCollector.CopyValue = new BoolValue(false);
    264286
     
    269291      initIslandEvaluationsAss.RightSideParameter.Value = new IntValue(0);
    270292
    271       incrementGenerationDr.ValueParameter.ActualName = "Generations";
    272       incrementGenerationDr.Increment = new IntValue(1);
    273 
    274       incrementEvaluatedSolutionDr.ParameterToReduce.ActualName = LayerEvaluatedSolutionsParameter.Name;
     293      incrementGenerationDr.TargetParameter.ActualName = "Generations";
     294      incrementGenerationDr.ParameterToReduce.ActualName = IslandGenerations.Name;
     295      incrementGenerationDr.TargetOperation.Value = new ReductionOperation(ReductionOperations.Sum);
     296      incrementGenerationDr.ReductionOperation.Value = new ReductionOperation(ReductionOperations.Min);
     297
     298      incrementEvaluatedSolutionDr.ParameterToReduce.ActualName = IslandEvaluatedSolutions.Name;
    275299      incrementEvaluatedSolutionDr.TargetParameter.ActualName = EvaluatedSolutions.Name;
    276300      incrementEvaluatedSolutionDr.ReductionOperation.Value = new ReductionOperation(ReductionOperations.Sum);
    277301      incrementEvaluatedSolutionDr.TargetOperation.Value = new ReductionOperation(ReductionOperations.Sum);
    278302
     303      incrementIslandGeneration.ValueParameter.ActualName = IslandGenerations.Name;
     304      setIslandEvaluatedSolutions.ParameterToReduce.ActualName = LayerEvaluatedSolutionsParameter.Name;
     305      setIslandEvaluatedSolutions.ReductionOperation.Value = new ReductionOperation(ReductionOperations.Sum);
     306      setIslandEvaluatedSolutions.TargetOperation.Value = new ReductionOperation(ReductionOperations.Assign);
     307      setIslandEvaluatedSolutions.TargetParameter.ActualName = IslandEvaluatedSolutions.Name;
     308
     309      migrateComparator.Comparison.Value = ComparisonType.GreaterOrEqual;
     310      migrateComparator.LeftSideParameter.ActualName = IslandGenerations.Name;
     311      migrateComparator.RightSideParameter.ActualName = MigrationIntervalParameter.Name;
     312      migrateComparator.ResultParameter.ActualName = "Migrate";
     313
     314      migrateCondBranch.ConditionParameter.ActualName = "Migrate";
     315
     316      groupAnalyzer.OperatorParameter.ActualName = GroupAnalyzerParameter.Name;
    279317      layerAnalyzerPlaceholder.OperatorParameter.ActualName = LayerAnalyzerParameter.Name;
    280318      layerResultsCollector.ResultsParameter.ActualName = "LayerResults";
    281319      layerResultsCollector.CollectedValues.Add(new LookupParameter<IntValue>("Layer"));
    282320      islandAnalyzerPlaceholder.OperatorParameter.ActualName = IslandAnalyzerParameter.Name;
     321      islandResultsCollector.ResultsParameter.ActualName = "IslandResults";
     322      islandResultsCollector.CollectedValues.Add(new ScopeTreeLookupParameter<ResultCollection>("LayerResults"));
    283323      globalAnalyzerPlacerholder.OperatorParameter.ActualName = AnalyzerParameter.Name;
    284324
     325      //TODO: implement check for grouped layer analyzer
     326      groupResultsExtractor.SourceNameParameter.Value = new StringValue("GroupScope");
     327      groupResultsExtractor.TargetNameParameter.Value = new StringValue("GroupResults");
     328      groupResultsCollector.CollectedValues.Add(new LookupParameter<ItemArray<ResultCollection>>("GroupResults"));
    285329      matingPoolCreator.MatingPoolRangeParameter.ActualName = MatingPoolRangeParameter.Name;
    286330
     
    328372      layerAnalyzerPlaceholder.Successor = layerResultsCollector;
    329373      layerResultsCollector.Successor = null;
     374
    330375      analyzeLayerUssp.Successor = islandAnalyzerPlaceholder;
    331       islandAnalyzerPlaceholder.Successor = null;
     376      islandAnalyzerPlaceholder.Successor = islandResultsCollector;
     377      islandResultsCollector.Successor = setIslandEvaluatedSolutions;
     378      setIslandEvaluatedSolutions.Successor = incrementIslandGeneration;
     379      incrementIslandGeneration.Successor = migrateComparator;
     380      migrateComparator.Successor = migrateCondBranch;
     381      migrateCondBranch.FalseBranch = matingPoolCreator;
     382      migrateCondBranch.TrueBranch = null;
     383
    332384      processIslandsUssp.Successor = incrementGenerationDr;
    333385      incrementGenerationDr.Successor = incrementEvaluatedSolutionDr;
    334386      incrementEvaluatedSolutionDr.Successor = globalAnalyzerPlacerholder;
    335       globalAnalyzerPlacerholder.Successor = terminator;
     387      globalAnalyzerPlacerholder.Successor = groupingOperator;
     388      groupingOperator.Operator = groupAnalyzer;
     389      groupAnalyzer.Successor = null;
     390      groupingOperator.Successor = groupResultsExtractor;
     391      groupResultsExtractor.Successor = groupResultsCollector;
     392      groupResultsCollector.Successor = terminator;
    336393      terminator.ContinueBranch = processIslandsUssp;
    337394
     
    454511      createChildrenViaCrossover.Successor = incrEvaluatedSolutionsForNewLayer;
    455512
    456       incrEvaluatedSolutionsForNewLayer.ValueParameter.ActualName = EvaluatedSolutions.Name;
     513      incrEvaluatedSolutionsForNewLayer.ValueParameter.ActualName = LayerEvaluatedSolutionsParameter.Name;
    457514      incrEvaluatedSolutionsForNewLayer.AccumulateParameter.Value = new BoolValue(true);
    458515
    459516      incrOpenLayers.ValueParameter.ActualName = "OpenLayers";
    460517      incrOpenLayers.Increment = new IntValue(1);
    461       //incrOpenLayers.Successor = newLayerResultsCollector;
    462 
    463       //newLayerResultsCollector.CollectedValues.Add(new ScopeTreeLookupParameter<ResultCollection>("LayerResults", "Result set for each layer", "LayerResults"));
    464       //newLayerResultsCollector.CopyValue = new BoolValue(false);
    465       //newLayerResultsCollector.Successor = null;
    466518
    467519      return layerOpener;
     
    494546      initializeAge.CollectedValues.Add(new ValueParameter<DoubleValue>(AgeParameter.Name, new DoubleValue(0)));
    495547
    496       incrEvaluatedSolutionsAfterReseeding.ValueParameter.ActualName = EvaluatedSolutions.Name;
     548      incrEvaluatedSolutionsAfterReseeding.ValueParameter.ActualName = LayerEvaluatedSolutionsParameter.Name;
    497549      incrEvaluatedSolutionsAfterReseeding.AccumulateParameter.Value = new BoolValue(true);
    498550
Note: See TracChangeset for help on using the changeset viewer.