Changeset 5277 for branches/HeuristicLab.MetaOptimization/HeuristicLab.Problems.MetaOptimization/3.3/Encoding/ValueConfigurations
- Timestamp:
- 01/11/11 16:00:17 (14 years ago)
- Location:
- branches/HeuristicLab.MetaOptimization/HeuristicLab.Problems.MetaOptimization/3.3/Encoding/ValueConfigurations
- Files:
-
- 2 edited
Legend:
- Unmodified
- Added
- Removed
-
branches/HeuristicLab.MetaOptimization/HeuristicLab.Problems.MetaOptimization/3.3/Encoding/ValueConfigurations/CheckedValueConfigurationCollection.cs
r5231 r5277 6 6 using HeuristicLab.Common; 7 7 using HeuristicLab.Persistence.Default.CompositeSerializers.Storable; 8 using HeuristicLab.Collections; 8 9 9 10 namespace HeuristicLab.Problems.MetaOptimization { … … 11 12 // todo: control creatable item types 12 13 [StorableClass] 13 public class CheckedValueConfiguration Collection : CheckedItemCollection<IValueConfiguration>, ICheckedValueConfigurationCollection{14 public class CheckedValueConfigurationList : CheckedItemList<IValueConfiguration>, ICheckedValueConfigurationList { 14 15 [Storable] 15 16 private int minItemCount = 1; … … 24 25 } 25 26 26 public CheckedValueConfiguration Collection(ItemSet<IItem> validValues) {27 public CheckedValueConfigurationList(ItemSet<IItem> validValues) { 27 28 this.validValues = validValues; 28 29 RegisterEvents(); 29 30 } 30 public CheckedValueConfiguration Collection() {31 public CheckedValueConfigurationList() { 31 32 RegisterEvents(); 32 33 } 33 34 [StorableConstructor] 34 protected CheckedValueConfiguration Collection(bool deserializing) : base(deserializing) {35 protected CheckedValueConfigurationList(bool deserializing) : base(deserializing) { 35 36 RegisterEvents(); 36 37 } 37 protected CheckedValueConfiguration Collection(CheckedValueConfigurationCollectionoriginal, Cloner cloner) : base(original, cloner) {38 protected CheckedValueConfigurationList(CheckedValueConfigurationList original, Cloner cloner) : base(original, cloner) { 38 39 this.minItemCount = original.MinItemCount; 39 40 this.validValues = original.validValues; … … 41 42 } 42 43 public override IDeepCloneable Clone(Cloner cloner) { 43 return new CheckedValueConfiguration Collection(this, cloner);44 return new CheckedValueConfigurationList(this, cloner); 44 45 } 45 46 [StorableHook(HookType.AfterDeserialization)] … … 49 50 50 51 private void RegisterEvents() { 51 this.ItemsRemoved += new Collections.CollectionItemsChangedEventHandler<IValueConfiguration>(CheckedValueConfigurationCollection_ItemsRemoved); 52 } 53 private void DeregisterEvents() { 54 this.ItemsRemoved -= new Collections.CollectionItemsChangedEventHandler<IValueConfiguration>(CheckedValueConfigurationCollection_ItemsRemoved); 52 this.ItemsRemoved += new CollectionItemsChangedEventHandler<IndexedItem<IValueConfiguration>>(CheckedValueConfigurationList_ItemsRemoved); 55 53 } 56 54 57 private void CheckedValueConfigurationCollection_ItemsRemoved(object sender, Collections.CollectionItemsChangedEventArgs<IValueConfiguration> e) { 55 private void DeregisterEvents() { 56 this.ItemsRemoved -= new CollectionItemsChangedEventHandler<IndexedItem<IValueConfiguration>>(CheckedValueConfigurationList_ItemsRemoved); 57 } 58 59 private void CheckedValueConfigurationList_ItemsRemoved(object sender, CollectionItemsChangedEventArgs<IndexedItem<IValueConfiguration>> e) { 58 60 // auch collectionreset gehört berücksichtigt 59 61 // funktioniert so nicht ganz, weil die view das hinzufügen nicht mitkriegt … … 66 68 //} 67 69 } 70 68 71 } 69 72 } -
branches/HeuristicLab.MetaOptimization/HeuristicLab.Problems.MetaOptimization/3.3/Encoding/ValueConfigurations/ValueConfiguration.cs
r5231 r5277 245 245 } 246 246 247 public void Mutate(IRandom random, MutateDelegate mutate, ParameterConfigurationManipulator pcmanip) {247 public void Mutate(IRandom random, MutateDelegate mutate, IIntValueManipulator intValueManipulator, IDoubleValueManipulator doubleValueManipulator) { 248 248 if (Optimize) { 249 249 if (rangeConstraint != null) { 250 mutate(random, this, pcmanip);250 mutate(random, this, intValueManipulator, doubleValueManipulator); 251 251 } else { 252 252 foreach (IParameterConfiguration pc in this.ParameterConfigurations) { 253 pc.Mutate(random, mutate, pcmanip);254 } 255 } 256 } 257 } 258 259 public void Cross(IRandom random, IOptimizable other, CrossDelegate cross, ParameterConfigurationCrossover pccross) {253 pc.Mutate(random, mutate, intValueManipulator, doubleValueManipulator); 254 } 255 } 256 } 257 } 258 259 public void Cross(IRandom random, IOptimizable other, CrossDelegate cross, IIntValueCrossover intValueCrossover, IDoubleValueCrossover doubleValueCrossover) { 260 260 if (Optimize) { 261 IValueConfiguration otherVc = (IValueConfiguration)other;262 261 if (rangeConstraint != null) { 263 cross(random, this, pccross); 264 265 //if (this.actualValue.ValueDataType == typeof(IntValue)) { 266 // //this.actualValue.Value = new IntValue((((IntValue)this.actualValue.Value).Value + ((IntValue)other.ActualValue.Value).Value) / 2); 267 268 // IntegerVector[] parents = new IntegerVector[2]; 269 // parents[0] = new IntegerVector(new int[] { ((IntValue)this.actualValue.Value).Value }); 270 // parents[1] = new IntegerVector(new int[] { ((IntValue)other.ActualValue.Value).Value }); 271 272 // this.actualValue.Value = new IntValue(HeuristicLab.Encodings.IntegerVectorEncoding.DiscreteCrossover.Apply(random, parents[0], parents[1]).First()); 273 274 //} else if (this.actualValue.ValueDataType == typeof(DoubleValue)) { 275 // //this.actualValue.Value = new DoubleValue((((DoubleValue)this.actualValue.Value).Value + ((DoubleValue)other.ActualValue.Value).Value) / 2); 276 // RealVector[] parents = new RealVector[2]; 277 // parents[0] = new RealVector(new double[] { ((DoubleValue)this.actualValue.Value).Value }); 278 // parents[1] = new RealVector(new double[] { ((DoubleValue)other.ActualValue.Value).Value }); 279 280 // if (random.NextDouble() < 0.5) { 281 // this.actualValue.Value = new DoubleValue(AverageCrossover.Apply(random, new ItemArray<RealVector>(parents)).First()); 282 // } else { 283 // this.actualValue.Value = new DoubleValue(HeuristicLab.Encodings.RealVectorEncoding.DiscreteCrossover.Apply(random, new ItemArray<RealVector>(parents)).First()); 284 // } 285 // //this.actualValue.Value = new DoubleValue(AverageCrossover.Apply(random, new ItemArray<RealVector>(parents)).First()); 286 287 //} else if (this.actualValue.ValueDataType == typeof(PercentValue)) { 288 // //this.actualValue.Value = new PercentValue((((PercentValue)this.actualValue.Value).Value + ((PercentValue)other.ActualValue.Value).Value) / 2); 289 290 // RealVector[] parents = new RealVector[2]; 291 // parents[0] = new RealVector(new double[] { ((PercentValue)this.actualValue.Value).Value }); 292 // parents[1] = new RealVector(new double[] { ((PercentValue)other.ActualValue.Value).Value }); 293 294 // if (random.NextDouble() < 0.5) { 295 // this.actualValue.Value = new PercentValue(AverageCrossover.Apply(random, new ItemArray<RealVector>(parents)).First()); 296 // } else { 297 // this.actualValue.Value = new PercentValue(HeuristicLab.Encodings.RealVectorEncoding.DiscreteCrossover.Apply(random, new ItemArray<RealVector>(parents)).First()); 298 // } 299 300 //} else if (this.actualValue.ValueDataType == typeof(BoolValue)) { 301 // if (random.NextDouble() > 0.5) 302 // this.actualValue.Value = this.actualValue.Value; 303 // else 304 // this.actualValue.Value = other.ActualValue.Value; 305 //} else { 306 // throw new NotImplementedException(); 307 //} 308 } else { 262 cross(random, this, other, intValueCrossover, doubleValueCrossover); 263 } else { 264 IValueConfiguration otherVc = (IValueConfiguration)other; 309 265 for (int i = 0; i < this.ParameterConfigurations.Count; i++) { 310 this.ParameterConfigurations.ElementAt(i).Cross(random, otherVc.ParameterConfigurations.ElementAt(i), cross, pccross);266 this.ParameterConfigurations.ElementAt(i).Cross(random, otherVc.ParameterConfigurations.ElementAt(i), cross, intValueCrossover, doubleValueCrossover); 311 267 } 312 268 }
Note: See TracChangeset
for help on using the changeset viewer.