- Timestamp:
- 10/30/14 11:49:08 (10 years ago)
- Location:
- branches/VOSGA/HeuristicLab.Algorithms.VOffspringSelectionGeneticAlgorithm
- Files:
-
- 1 added
- 3 edited
Legend:
- Unmodified
- Added
- Removed
-
branches/VOSGA/HeuristicLab.Algorithms.VOffspringSelectionGeneticAlgorithm/HeuristicLab.Algorithms.VOffspringSelectionGeneticAlgorithm-3.3.csproj
r11510 r11511 161 161 </ItemGroup> 162 162 <ItemGroup> 163 <Compile Include="OffspringCollector.cs" /> 163 164 <Compile Include="OffspringSelectors\IOffspringSelector.cs" /> 164 165 <Compile Include="OffspringSelectors\StandardOffspringSelector.cs" /> -
branches/VOSGA/HeuristicLab.Algorithms.VOffspringSelectionGeneticAlgorithm/OffspringSelectors/StandardOffspringSelector.cs
r11510 r11511 31 31 [Item("StandardOffspringSelector", "Selects among the offspring population those that are designated successful and discards the unsuccessful offspring, except for some lucky losers. It expects the parent scopes to be below the first sub-scope, and offspring scopes to be below the second sub-scope separated again in two sub-scopes, the first with the failed offspring and the second with successful offspring.")] 32 32 [StorableClass] 33 public class StandardOffspringSelector : SingleSuccessorOperator, IOffspringSelector {33 public class StandardOffspringSelector : InstrumentedOperator, IOffspringSelector { 34 34 public ValueLookupParameter<DoubleValue> MaximumSelectionPressureParameter { 35 35 get { return (ValueLookupParameter<DoubleValue>)Parameters["MaximumSelectionPressure"]; } … … 91 91 } 92 92 93 public override IOperation Apply() {93 public override IOperation InstrumentedApply() { 94 94 double maxSelPress = MaximumSelectionPressureParameter.ActualValue.Value; 95 95 double successRatio = SuccessRatioParameter.ActualValue.Value; … … 192 192 EnoughChildrenGeneratedParameter.ActualValue.Value = true; 193 193 } 194 return base. Apply();194 return base.InstrumentedApply(); 195 195 } 196 196 } -
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.