Changeset 296 for trunk/sources/HeuristicLab.Selection.OffspringSelection
- Timestamp:
- 06/05/08 11:55:26 (17 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/sources/HeuristicLab.Selection.OffspringSelection/OffspringSelector.cs
r77 r296 49 49 IScope children = scope.SubScopes[1]; 50 50 51 // retrieve good and bad children 52 ItemList<IScope> goodChildren = GetVariableValue<ItemList<IScope>>("GoodChildren", scope, false, false); 53 if (goodChildren == null) { 54 goodChildren = new ItemList<IScope>(); 55 IVariableInfo goodChildrenInfo = GetVariableInfo("GoodChildren"); 56 if (goodChildrenInfo.Local) 57 AddVariable(new Variable(goodChildrenInfo.ActualName, goodChildren)); 58 else 59 scope.AddVariable(new Variable(scope.TranslateName(goodChildrenInfo.FormalName), goodChildren)); 60 } 61 ItemList<IScope> badChildren = GetVariableValue<ItemList<IScope>>("BadChildren", scope, false, false); 62 if (badChildren == null) { 63 badChildren = new ItemList<IScope>(); 64 IVariableInfo badChildrenInfo = GetVariableInfo("BadChildren"); 65 if (badChildrenInfo.Local) 66 AddVariable(new Variable(badChildrenInfo.ActualName, badChildren)); 67 else 68 scope.AddVariable(new Variable(scope.TranslateName(badChildrenInfo.FormalName), badChildren)); 69 } 70 71 // separate new children in good and bad children 72 IVariableInfo successfulInfo = GetVariableInfo("SuccessfulChild"); 73 while (children.SubScopes.Count > 0) { 74 IScope child = children.SubScopes[0]; 75 bool successful = child.GetVariableValue<BoolData>(successfulInfo.FormalName, false).Data; 76 if (successful) goodChildren.Add(child); 77 else badChildren.Add(child); 78 children.RemoveSubScope(child); 79 } 80 81 // calculate actual selection pressure and success ratio 51 // retrieve actual selection pressure and success ratio 82 52 DoubleData selectionPressure = GetVariableValue<DoubleData>("SelectionPressure", scope, false, false); 83 53 if (selectionPressure == null) { … … 98 68 scope.AddVariable(new Variable(scope.TranslateName(successRatioInfo.FormalName), successRatio)); 99 69 } 100 int goodCount = goodChildren.Count; 101 int badCount = badChildren.Count; 102 selectionPressure.Data = (goodCount + badCount) / ((double)parents.SubScopes.Count); 70 71 // retrieve good and bad children 72 ItemList<IScope> goodChildren = GetVariableValue<ItemList<IScope>>("GoodChildren", scope, false, false); 73 if (goodChildren == null) { 74 goodChildren = new ItemList<IScope>(); 75 IVariableInfo goodChildrenInfo = GetVariableInfo("GoodChildren"); 76 if (goodChildrenInfo.Local) 77 AddVariable(new Variable(goodChildrenInfo.ActualName, goodChildren)); 78 else 79 scope.AddVariable(new Variable(scope.TranslateName(goodChildrenInfo.FormalName), goodChildren)); 80 81 // no good children available -> first iteration of this generation -> initialize selection pressure 82 selectionPressure.Data = 0; 83 } 84 ItemList<IScope> badChildren = GetVariableValue<ItemList<IScope>>("BadChildren", scope, false, false); 85 if (badChildren == null) { 86 badChildren = new ItemList<IScope>(); 87 IVariableInfo badChildrenInfo = GetVariableInfo("BadChildren"); 88 if (badChildrenInfo.Local) 89 AddVariable(new Variable(badChildrenInfo.ActualName, badChildren)); 90 else 91 scope.AddVariable(new Variable(scope.TranslateName(badChildrenInfo.FormalName), badChildren)); 92 } 93 94 // separate new children in good and bad children 95 int goodCount = 0; 96 int badCount = 0; 97 IVariableInfo successfulInfo = GetVariableInfo("SuccessfulChild"); 98 while (children.SubScopes.Count > 0) { 99 IScope child = children.SubScopes[0]; 100 bool successful = child.GetVariableValue<BoolData>(successfulInfo.FormalName, false).Data; 101 if (successful) { 102 goodCount++; 103 goodChildren.Add(child); 104 } else { 105 badCount++; 106 // only keep the child if we have not filled up the pool or if we reached the 107 // selection pressure limit in which case we have to keep more lucky losers than usual 108 if ((1 - successRatioLimit) * parents.SubScopes.Count >= badChildren.Count || 109 selectionPressure.Data >= selectionPressureLimit) { 110 badChildren.Add(child); 111 } 112 } 113 children.RemoveSubScope(child); 114 } 115 116 // calculate actual selection pressure and success ratio 117 selectionPressure.Data += (goodCount + badCount) / ((double)parents.SubScopes.Count); 103 118 successRatio.Data = goodCount / ((double)parents.SubScopes.Count); 104 119 105 120 // check if enough children have been generated 106 121 if (((selectionPressure.Data < selectionPressureLimit) && (successRatio.Data < successRatioLimit)) || 107 ((goodC ount + badCount) < parents.SubScopes.Count)) {122 ((goodChildren.Count + badChildren.Count) < parents.SubScopes.Count)) { 108 123 // more children required -> reduce left and start children generation again 109 124 scope.RemoveSubScope(parents); … … 136 151 else 137 152 scope.RemoveVariable(scope.TranslateName(badChildrenInfo.FormalName)); 138 153 IVariableInfo badCountInfo = GetVariableInfo("BadCount"); 154 if(badCountInfo.Local) 155 RemoveVariable(badCountInfo.ActualName); 156 else 157 scope.RemoveVariable(scope.TranslateName("BadCount")); 139 158 return null; 140 159 }
Note: See TracChangeset
for help on using the changeset viewer.