Changeset 5682 for branches/SuccessProgressAnalysis/HeuristicLab.Algorithms.OffspringSelectionGeneticAlgorithm/3.3/SuccessfulOffspringAnalysis/SuccessfulOffspringAnalyzer.cs
- Timestamp:
- 03/15/11 09:51:22 (14 years ago)
- Location:
- branches/SuccessProgressAnalysis/HeuristicLab.Algorithms.OffspringSelectionGeneticAlgorithm/3.3/SuccessfulOffspringAnalysis
- Files:
-
- 1 added
- 1 copied
Legend:
- Unmodified
- Added
- Removed
-
branches/SuccessProgressAnalysis/HeuristicLab.Algorithms.OffspringSelectionGeneticAlgorithm/3.3/SuccessfulOffspringAnalysis/SuccessfulOffspringAnalyzer.cs
r5674 r5682 33 33 using HeuristicLab.Analysis; 34 34 35 namespace HeuristicLab.Algorithms.OffspringSelection Algorithm.SuccessProgressAnalysis{35 namespace HeuristicLab.Algorithms.OffspringSelectionGeneticAlgorithm { 36 36 /// <summary> 37 37 /// An operator for analyzing the solution diversity in a population. 38 38 /// </summary> 39 [Item("Success ProgressAnalyzer", "An operator for analyzing the success progress in a population.")]39 [Item("SuccessfulOffspringAnalyzer", "An operator for analyzing certain properties in the successful offspring. The properties to be analyzed can be specified in the CollectedValues parameter.")] 40 40 [StorableClass] 41 public sealed class Success ProgressAnalyzer: SingleSuccessorOperator, IAnalyzer {41 public sealed class SuccessfulOffspringAnalyzer : SingleSuccessorOperator, IAnalyzer { 42 42 public ValueParameter<StringValue> SuccessfulOffspringFlag { 43 43 get { return (ValueParameter<StringValue>)Parameters["SuccessfulOffspringFlag"]; } … … 52 52 } 53 53 54 public LookupParameter<IntValue> Generations{54 public ILookupParameter<IntValue> GenerationsParameter { 55 55 get { return (LookupParameter<IntValue>)Parameters["Generations"]; } 56 } 57 58 public ValueParameter<IntValue> DepthParameter { 59 get { return (ValueParameter<IntValue>)Parameters["Depth"]; } 56 60 } 57 61 58 62 public override IDeepCloneable Clone(Cloner cloner) { 59 return new Success ProgressAnalyzer(this, cloner);63 return new SuccessfulOffspringAnalyzer(this, cloner); 60 64 } 61 65 [StorableConstructor] 62 private Success ProgressAnalyzer(bool deserializing) : base(deserializing) { }63 private Success ProgressAnalyzer(SuccessProgressAnalyzer original, Cloner cloner) : base(original, cloner) { }64 public Success ProgressAnalyzer()66 private SuccessfulOffspringAnalyzer(bool deserializing) : base(deserializing) { } 67 private SuccessfulOffspringAnalyzer(SuccessfulOffspringAnalyzer original, Cloner cloner) : base(original, cloner) { } 68 public SuccessfulOffspringAnalyzer() 65 69 : base() { 66 Parameters.Add(new ValueParameter<StringValue>("SuccessfulOffspringFlag", " Indicates if the individual was successful.", new StringValue("SuccessfulOffspring")));67 Parameters.Add(new ValueParameter<ItemCollection<StringValue>>("CollectedValues", "The valuesthat should be collected.", new ItemCollection<StringValue>()));70 Parameters.Add(new ValueParameter<StringValue>("SuccessfulOffspringFlag", "The name of the flag which indicates if the individual was successful.", new StringValue("SuccessfulOffspring"))); 71 Parameters.Add(new ValueParameter<ItemCollection<StringValue>>("CollectedValues", "The properties of the successful offspring that should be collected.", new ItemCollection<StringValue>())); 68 72 Parameters.Add(new ValueLookupParameter<ResultCollection>("Results", "The result collection where the succedd progress analysis results should be stored.")); 69 73 Parameters.Add(new LookupParameter<IntValue>("Generations", "The current number of generations.")); 74 Parameters.Add(new ValueParameter<IntValue>("Depth", "The depth of the individuals in the scope tree.", new IntValue(1))); 70 75 } 71 76 72 77 public override IOperation Apply() { 73 78 ResultCollection results = ResultsParameter.ActualValue; 74 79 80 List<IScope> scopes = new List<IScope>() { ExecutionContext.Scope }; 81 for (int i = 0; i < DepthParameter.Value.Value; i++) 82 scopes = scopes.Select(x => (IEnumerable<IScope>)x.SubScopes).Aggregate((a, b) => a.Concat(b)).ToList(); 83 75 84 ItemCollection<StringValue> collectedValues = CollectedValues.Value; 76 85 foreach (StringValue collected in collectedValues) { 86 //collect the values of the successful offspring 77 87 Dictionary<String, int> counts = new Dictionary<String, int>(); 78 for (int i = 0; i < ExecutionContext.Scope.SubScopes.Count; i++) {79 IScope child = ExecutionContext.Scope.SubScopes[i];88 for (int i = 0; i < scopes.Count; i++) { 89 IScope child = scopes[i]; 80 90 string successfulOffspringFlag = SuccessfulOffspringFlag.Value.Value; 81 91 if (child.Variables.ContainsKey(collected.Value) && … … 92 102 } 93 103 104 //create a data table containing the collected values 94 105 DataTable successProgressAnalysis; 95 106 string resultKey = "Success Progress " + collected.Value; … … 111 122 if (!successProgressAnalysis.Rows.ContainsKey(value)) { 112 123 row = new DataRow(value); 113 int iterations = Generations .ActualValue.Value;124 int iterations = GenerationsParameter.ActualValue.Value; 114 125 126 //fill up all values seen the first time 115 127 for (int i = 1; i < iterations; i++) 116 128 row.Values.Add(0); … … 124 136 } 125 137 138 //fill up all values that are not present in the current generation 126 139 foreach (DataRow row in successProgressAnalysis.Rows) { 127 140 if (!counts.ContainsKey(row.Name))
Note: See TracChangeset
for help on using the changeset viewer.