Free cookie consent management tool by TermsFeed Policy Generator

source: branches/2258_IslandALPS/IslandALPS/3.3/ResultsExtractor.cs @ 16574

Last change on this file since 16574 was 13595, checked in by pkuelzer, 9 years ago

#2558 Added GroupedLayerAnalyzer
Fixed an evaluated solutions bug

File size: 2.7 KB
Line 
1using System.Collections.Generic;
2using HeuristicLab.Common;
3using HeuristicLab.Core;
4using HeuristicLab.Data;
5using HeuristicLab.Operators;
6using HeuristicLab.Optimization;
7using HeuristicLab.Parameters;
8using HeuristicLab.Persistence.Default.CompositeSerializers.Storable;
9
10namespace HeuristicLab.Algorithms.IslandALPS {
11  /// <summary>
12  ///   Extracts values from a scope into the current scope
13  /// </summary>
14  [Item("ResultsExtractor", "Extracts values from a scope into the current scope")]
15  [StorableClass]
16  public class ResultsExtractor : InstrumentedOperator {
17    [StorableConstructor]
18    public ResultsExtractor(bool deserializing) : base(deserializing) {}
19
20    public ResultsExtractor(ResultsExtractor original, Cloner cloner) : base(original, cloner) {}
21
22    public ResultsExtractor() {
23      Parameters.Add(new ScopeParameter("CurrentScope", "The current scope where the operator gets executed."));
24      Parameters.Add(new ValueLookupParameter<StringValue>("SourceName", "The Scope where the variable is."));
25      Parameters.Add(new ValueParameter<StringValue>("TargetName", "The name of the ResultCollection.", new StringValue("Results")));
26    }
27
28    public ScopeParameter CurrentScopeParameter {
29      get { return (ScopeParameter) Parameters["CurrentScope"]; }
30    }
31
32    public ValueLookupParameter<StringValue> SourceNameParameter {
33      get { return (ValueLookupParameter<StringValue>) Parameters["SourceName"]; }
34      set { Parameters["SourceName"].ActualValue = value; }
35    }
36
37    public ValueParameter<StringValue> TargetNameParameter {
38      get { return (ValueParameter<StringValue>) Parameters["TargetName"]; }
39      set { Parameters["TargetName"].ActualValue = value; }
40    }
41
42    private IScope CurrentScope {
43      get { return CurrentScopeParameter.ActualValue; }
44    }
45
46    private IScope SourceScope {
47      get { return (IScope) CurrentScope.Variables[SourceNameParameter.Value.Value].Value; }
48    }
49
50    public override IDeepCloneable Clone(Cloner cloner) {
51      return new ResultsExtractor(this, cloner);
52    }
53
54    public override IOperation InstrumentedApply() {
55      var list = new List<ResultCollection>();
56      var key = TargetNameParameter.Value.Value;
57      for (var index = 0; index < SourceScope.SubScopes.Count; index++) {
58        var subScope = SourceScope.SubScopes[index];
59        if (subScope.Variables.ContainsKey(key))
60          list.Add(subScope.Variables[key].Value as ResultCollection);
61      }
62      if (!CurrentScope.Variables.ContainsKey(key))
63        CurrentScope.Variables.Add(new Variable(key));
64      CurrentScope.Variables[key].Value = new ItemArray<ResultCollection>(list);
65      return base.InstrumentedApply();
66    }
67  }
68}
Note: See TracBrowser for help on using the repository browser.