Free cookie consent management tool by TermsFeed Policy Generator

Ignore:
Timestamp:
01/11/11 16:00:17 (14 years ago)
Author:
cneumuel
Message:

#1215

  • implemented crossover and manipulator operators for int and double values
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  
    66using HeuristicLab.Common;
    77using HeuristicLab.Persistence.Default.CompositeSerializers.Storable;
     8using HeuristicLab.Collections;
    89
    910namespace HeuristicLab.Problems.MetaOptimization {
     
    1112  // todo: control creatable item types
    1213  [StorableClass]
    13   public class CheckedValueConfigurationCollection : CheckedItemCollection<IValueConfiguration>, ICheckedValueConfigurationCollection {
     14  public class CheckedValueConfigurationList : CheckedItemList<IValueConfiguration>, ICheckedValueConfigurationList {
    1415    [Storable]
    1516    private int minItemCount = 1;
     
    2425    }
    2526
    26     public CheckedValueConfigurationCollection(ItemSet<IItem> validValues) {
     27    public CheckedValueConfigurationList(ItemSet<IItem> validValues) {
    2728      this.validValues = validValues;
    2829      RegisterEvents();
    2930    }
    30     public CheckedValueConfigurationCollection() {
     31    public CheckedValueConfigurationList() {
    3132      RegisterEvents();
    3233    }
    3334    [StorableConstructor]
    34     protected CheckedValueConfigurationCollection(bool deserializing) : base(deserializing) {
     35    protected CheckedValueConfigurationList(bool deserializing) : base(deserializing) {
    3536      RegisterEvents();
    3637    }
    37     protected CheckedValueConfigurationCollection(CheckedValueConfigurationCollection original, Cloner cloner) : base(original, cloner) {
     38    protected CheckedValueConfigurationList(CheckedValueConfigurationList original, Cloner cloner) : base(original, cloner) {
    3839      this.minItemCount = original.MinItemCount;
    3940      this.validValues = original.validValues;
     
    4142    }
    4243    public override IDeepCloneable Clone(Cloner cloner) {
    43       return new CheckedValueConfigurationCollection(this, cloner);
     44      return new CheckedValueConfigurationList(this, cloner);
    4445    }
    4546    [StorableHook(HookType.AfterDeserialization)]
     
    4950
    5051    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);
    5553    }
    5654
    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) {
    5860      // auch collectionreset gehört berücksichtigt
    5961      // funktioniert so nicht ganz, weil die view das hinzufügen nicht mitkriegt
     
    6668      //}
    6769    }
     70
    6871  }
    6972}
  • branches/HeuristicLab.MetaOptimization/HeuristicLab.Problems.MetaOptimization/3.3/Encoding/ValueConfigurations/ValueConfiguration.cs

    r5231 r5277  
    245245    }
    246246
    247     public void Mutate(IRandom random, MutateDelegate mutate, ParameterConfigurationManipulator pcmanip) {
     247    public void Mutate(IRandom random, MutateDelegate mutate, IIntValueManipulator intValueManipulator, IDoubleValueManipulator doubleValueManipulator) {
    248248      if (Optimize) {
    249249        if (rangeConstraint != null) {
    250           mutate(random, this, pcmanip);
     250          mutate(random, this, intValueManipulator, doubleValueManipulator);
    251251        } else {
    252252          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) {
    260260      if (Optimize) {
    261         IValueConfiguration otherVc = (IValueConfiguration)other;
    262261        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;
    309265          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);
    311267          }
    312268        }
Note: See TracChangeset for help on using the changeset viewer.