Changeset 11511 for branches/VOSGA/HeuristicLab.Algorithms.VOffspringSelectionGeneticAlgorithm/ProbabilitiesGenerator.cs
- Timestamp:
- 10/30/14 11:49:08 (9 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
branches/VOSGA/HeuristicLab.Algorithms.VOffspringSelectionGeneticAlgorithm/ProbabilitiesGenerator.cs
r11492 r11511 34 34 [Item("ProbabilitiesGenerator", "An operator the generates the probability vector for Multi Crossovers/Mutators")] 35 35 [StorableClass] 36 public class ProbabilitiesGenerator : SingleSuccessorOperator { 36 public class ProbabilitiesGenerator : SingleSuccessorOperator, IAnalyzer { 37 public bool EnabledByDefault { 38 get { return false; } 39 } 37 40 public ValueParameter<StringValue> SuccessfulOffspringFlagParameter { 38 41 get { return (ValueParameter<StringValue>)Parameters["SuccessfulOffspringFlag"]; } 39 42 } 40 41 43 public ValueParameter<StringValue> OperatorNameVariableParameter { 42 44 get { return (ValueParameter<StringValue>)Parameters["OperatorNameVariable"]; } 43 45 } 44 public LookupParameter<ResultCollection> SuccessfulOffspringAnalysisParameter {45 get { return (LookupParameter<ResultCollection>)Parameters["SuccessfulOffspringAnalysis"]; }46 }47 46 public LookupParameter<IOperator> CrossoverParameter { 48 47 get { return (LookupParameter<IOperator>)Parameters["Crossover"]; } 49 }50 public ILookupParameter<IntValue> GenerationsParameter {51 get { return (LookupParameter<IntValue>)Parameters["Generations"]; }52 48 } 53 49 public LookupParameter<DoubleArray> ProbablilitiesParameter { … … 57 53 public ValueParameter<DoubleValue> MinimumOperatorUsageParameter { 58 54 get { return (ValueParameter<DoubleValue>)Parameters["MinimumOperatorUsage"]; } 55 } 56 public LookupParameter<ItemList<IScope>> GeneratedOffspringParameter { 57 get { return (LookupParameter<ItemList<IScope>>)Parameters["GeneratedOffspring"]; } 59 58 } 60 59 … … 69 68 Parameters.Add(new ValueParameter<StringValue>("SuccessfulOffspringFlag", "The name of the flag which indicates if the individual was successful.", new StringValue("SuccessfulOffspring"))); 70 69 Parameters.Add(new ValueParameter<StringValue>("OperatorNameVariable", "The properties of the successful offspring that should be collected.", new StringValue("SelectedCrossoverOperator"))); 71 Parameters.Add(new LookupParameter<IntValue>("Generations", "The current number of generations."));72 Parameters.Add(new LookupParameter<ResultCollection>("SuccessfulOffspringAnalysis", "The successful offspring analysis which is created."));73 70 Parameters.Add(new LookupParameter<DoubleArray>("Probabilities")); 74 71 Parameters.Add(new LookupParameter<IOperator>("Crossover")); 75 72 Parameters.Add(new ValueParameter<DoubleValue>("MinimumOperatorUsage", "Minimum percentage of operator usage. ", new DoubleValue(0.05))); 73 Parameters.Add(new LookupParameter<ItemList<IScope>>("GeneratedOffspring", "Temporary store of the offspring population.")); 76 74 } 77 75 78 76 public override IOperation Apply() { 79 IScope scope = ExecutionContext.Scope; 80 IScope offspring = scope.SubScopes[1]; 77 if (GeneratedOffspringParameter.ActualValue == null) { 78 GeneratedOffspringParameter.ActualValue = new ItemList<IScope>(); 79 } 80 81 var offspring = GeneratedOffspringParameter.ActualValue; 81 82 string operatorName = OperatorNameVariableParameter.Value.Value; 82 83 string succssFlag = SuccessfulOffspringFlagParameter.Value.Value; … … 88 89 x.GetGenericTypeDefinition() == typeof(ICheckedMultiOperator<>))) { 89 90 90 for (int i = 0; i < offspring. SubScopes.Count; i++) {91 for (int i = 0; i < offspring.Count; i++) { 91 92 // fetch values from scopes 92 93 IVariable tmpVar; 93 if (!offspring .SubScopes[i].Variables.TryGetValue(succssFlag, out tmpVar))94 if (!offspring[i].Variables.TryGetValue(succssFlag, out tmpVar)) 94 95 throw new InvalidOperationException(Name + ": Could not determine if an offspring was successful or not."); 95 96 BoolValue success = (tmpVar.Value as BoolValue); 96 97 if (success == null) throw new InvalidOperationException(Name + ": The variable that indicates whether an offspring is successful or not must contain a BoolValue."); 97 98 98 if (!offspring .SubScopes[i].Variables.TryGetValue(operatorName, out tmpVar))99 if (!offspring[i].Variables.TryGetValue(operatorName, out tmpVar)) 99 100 throw new InvalidOperationException(Name + ": Could not determine operator an offspring was created with."); 100 101 StringValue op = (tmpVar.Value as StringValue); … … 126 127 } 127 128 129 //initialize probabilities vector 130 if (ProbablilitiesParameter.ActualValue == null) { 131 ProbablilitiesParameter.ActualValue = new DoubleArray(crossoverCount); 132 for (int i = 0; i < crossoverCount; i++) { 133 ProbablilitiesParameter.ActualValue[i] = 1.0; 134 } 135 return base.Apply(); 136 } 137 128 138 //fill probabilities vector 129 139 for (int i = 0; i < crossoverCount; i++) { … … 152 162 } 153 163 } 164 165 GeneratedOffspringParameter.ActualValue.Clear(); 154 166 } 155 167
Note: See TracChangeset
for help on using the changeset viewer.