Changeset 5277 for branches/HeuristicLab.MetaOptimization/HeuristicLab.Problems.MetaOptimization/3.3/Encoding/ParameterConfigurations
- Timestamp:
- 01/11/11 16:00:17 (14 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
branches/HeuristicLab.MetaOptimization/HeuristicLab.Problems.MetaOptimization/3.3/Encoding/ParameterConfigurations/ParameterConfiguration.cs
r5267 r5277 12 12 using System.Reflection; 13 13 using HeuristicLab.Optimization; 14 using HeuristicLab.Collections; 14 15 15 16 namespace HeuristicLab.Problems.MetaOptimization { … … 78 79 79 80 [Storable] 80 protected ICheckedValueConfiguration CollectionvalueConfigurations;81 public ICheckedValueConfiguration CollectionValueConfigurations {81 protected ICheckedValueConfigurationList valueConfigurations; 82 public ICheckedValueConfigurationList ValueConfigurations { 82 83 get { return this.valueConfigurations; } 83 84 protected set { … … 135 136 validTypes = new List<Type>(validTypes) { typeof(NullValue) }.ToArray(); 136 137 } 137 this.ValueConfigurations = new CheckedValueConfiguration Collection();138 this.ValueConfigurations = new CheckedValueConfigurationList(); 138 139 this.ActualValue = new ConstrainedValue( 139 140 valueParameter.Value != null ? (IItem)valueParameter.Value.Clone() : null, … … 173 174 174 175 private void RegisterValueConfigurationEvents() { 175 this.ValueConfigurations.CheckedItemsChanged += new Collection s.CollectionItemsChangedEventHandler<IValueConfiguration>(ValueConfigurations_CheckedItemsChanged);176 this.ValueConfigurations.ItemsAdded += new Collection s.CollectionItemsChangedEventHandler<IValueConfiguration>(ValueConfigurations_ItemsAdded);177 this.ValueConfigurations.ItemsRemoved += new Collection s.CollectionItemsChangedEventHandler<IValueConfiguration>(ValueConfigurations_ItemsRemoved);176 this.ValueConfigurations.CheckedItemsChanged += new CollectionItemsChangedEventHandler<IndexedItem<IValueConfiguration>>(ValueConfigurations_CheckedItemsChanged); 177 this.ValueConfigurations.ItemsAdded += new CollectionItemsChangedEventHandler<IndexedItem<IValueConfiguration>>(ValueConfigurations_ItemsAdded); 178 this.ValueConfigurations.ItemsRemoved += new CollectionItemsChangedEventHandler<IndexedItem<IValueConfiguration>>(ValueConfigurations_ItemsRemoved); 178 179 } 179 180 180 181 private void DeregisterValueConfigurationEvents() { 181 this.ValueConfigurations.CheckedItemsChanged -= new Collection s.CollectionItemsChangedEventHandler<IValueConfiguration>(ValueConfigurations_CheckedItemsChanged);182 this.ValueConfigurations.ItemsAdded -= new Collection s.CollectionItemsChangedEventHandler<IValueConfiguration>(ValueConfigurations_ItemsAdded);183 this.ValueConfigurations.ItemsRemoved -= new Collection s.CollectionItemsChangedEventHandler<IValueConfiguration>(ValueConfigurations_ItemsRemoved);182 this.ValueConfigurations.CheckedItemsChanged -= new CollectionItemsChangedEventHandler<IndexedItem<IValueConfiguration>>(ValueConfigurations_CheckedItemsChanged); 183 this.ValueConfigurations.ItemsAdded -= new CollectionItemsChangedEventHandler<IndexedItem<IValueConfiguration>>(ValueConfigurations_ItemsAdded); 184 this.ValueConfigurations.ItemsRemoved -= new CollectionItemsChangedEventHandler<IndexedItem<IValueConfiguration>>(ValueConfigurations_ItemsRemoved); 184 185 } 185 186 … … 268 269 } 269 270 270 void ValueConfigurations_CheckedItemsChanged(object sender, Collections.CollectionItemsChangedEventArgs<I ValueConfiguration> e) {271 void ValueConfigurations_CheckedItemsChanged(object sender, Collections.CollectionItemsChangedEventArgs<IndexedItem<IValueConfiguration>> e) { 271 272 OnToStringChanged(); 272 273 } 273 void ValueConfigurations_ItemsRemoved(object sender, Collections.CollectionItemsChangedEventArgs<I ValueConfiguration> e) {274 void ValueConfigurations_ItemsRemoved(object sender, Collections.CollectionItemsChangedEventArgs<IndexedItem<IValueConfiguration>> e) { 274 275 OnToStringChanged(); 275 276 } 276 void ValueConfigurations_ItemsAdded(object sender, Collections.CollectionItemsChangedEventArgs<I ValueConfiguration> e) {277 void ValueConfigurations_ItemsAdded(object sender, Collections.CollectionItemsChangedEventArgs<IndexedItem<IValueConfiguration>> e) { 277 278 OnToStringChanged(); 278 279 } … … 360 361 361 362 if (this.ActualValue.Value is IParameterizedItem) { 362 string subParams = this.ValueConfigurations .CheckedItems.ElementAt(actualValueConfigurationIndex).ParameterInfoString;363 string subParams = this.ValueConfigurations[actualValueConfigurationIndex].ParameterInfoString; 363 364 if (!string.IsNullOrEmpty(subParams)) { 364 365 sb.Append(" ("); … … 383 384 if (Optimize) { 384 385 if (this.ActualValue.Value is IParameterizedItem) { 385 this.ValueConfigurations .CheckedItems.ElementAt(actualValueConfigurationIndex).Parameterize((IParameterizedItem)this.ActualValue.Value);386 this.ValueConfigurations[actualValueConfigurationIndex].Parameterize((IParameterizedItem)this.ActualValue.Value); 386 387 } 387 388 } … … 410 411 public void Randomize(IRandom random) { 411 412 if (Optimize) { 412 foreach (var vc in this.ValueConfigurations.CheckedItems) { 413 vc.Randomize(random); 414 } 415 actualValueConfigurationIndex = random.Next(ValueConfigurations.CheckedItems.Count()); 416 this.ActualValue = this.ValueConfigurations.CheckedItems.ElementAt(actualValueConfigurationIndex).ActualValue; 417 } 418 } 419 420 public void Mutate(IRandom random, MutateDelegate mutate, ParameterConfigurationManipulator pcmanip) { 421 if (Optimize) { 422 foreach (IValueConfiguration vc in this.ValueConfigurations.CheckedItems) { 423 vc.Mutate(random, mutate, pcmanip); 424 } 425 mutate(random, this, pcmanip); 426 } 427 } 428 429 public void Cross(IRandom random, IOptimizable other, CrossDelegate cross, ParameterConfigurationCrossover pccross) { 413 foreach (var vc in this.ValueConfigurations) { 414 if (this.ValueConfigurations.ItemChecked(vc)) { 415 vc.Randomize(random); 416 } 417 } 418 do { 419 actualValueConfigurationIndex = random.Next(ValueConfigurations.Count()); 420 } while (!this.ValueConfigurations.ItemChecked(this.ValueConfigurations[actualValueConfigurationIndex])); 421 this.ActualValue = this.ValueConfigurations[actualValueConfigurationIndex].ActualValue; 422 } 423 } 424 425 public void Mutate(IRandom random, MutateDelegate mutate, IIntValueManipulator intValueManipulator, IDoubleValueManipulator doubleValueManipulator) { 426 if (Optimize) { 427 foreach (var vc in this.ValueConfigurations) { 428 if (this.ValueConfigurations.ItemChecked(vc)) { 429 vc.Mutate(random, mutate, intValueManipulator, doubleValueManipulator); 430 } 431 } 432 mutate(random, this, intValueManipulator, doubleValueManipulator); 433 } 434 } 435 436 public void Cross(IRandom random, IOptimizable other, CrossDelegate cross, IIntValueCrossover intValueCrossover, IDoubleValueCrossover doubleValueCrossover) { 430 437 if (Optimize) { 431 438 IParameterConfiguration otherPc = (IParameterConfiguration)other; 432 439 for (int i = 0; i < this.ValueConfigurations.Count; i++) { 433 cross(random, other, pccross); 434 //this.ValueConfigurations.ElementAt(i).Cross(otherPc.ValueConfigurations.ElementAt(i), random); 435 } 436 //if (random.NextDouble() > 0.5) { 437 // actualValueConfigurationIndex = ((ParameterConfiguration)other).actualValueConfigurationIndex; 438 //} 439 //this.ActualValue = this.ValueConfigurations.CheckedItems.ElementAt(actualValueConfigurationIndex).ActualValue; 440 if (this.ValueConfigurations.ItemChecked(this.ValueConfigurations[i])) { 441 this.ValueConfigurations[i].Cross(random, otherPc.ValueConfigurations[i], cross, intValueCrossover, doubleValueCrossover); 442 } 443 } 444 cross(random, this, other, intValueCrossover, doubleValueCrossover); 440 445 } 441 446 } 442 447 443 448 public void UpdateActualValueIndexToItem(IValueConfiguration vc) { 444 for (int i = 0; i < this.ValueConfigurations.C heckedItems.Count(); i++) {445 if (this.ValueConfigurations. CheckedItems.ElementAt(i) == vc) {449 for (int i = 0; i < this.ValueConfigurations.Count(); i++) { 450 if (this.ValueConfigurations.ElementAt(i) == vc) { 446 451 this.actualValueConfigurationIndex = i; 447 452 return;
Note: See TracChangeset
for help on using the changeset viewer.