Ignore:
Timestamp:
04/19/10 23:34:34 (12 years ago)
Author:
abeham
Message:

Changed MultiCrossover to StochasticMultiOperator
Derived StochasticMultiBranch from StochasticMultiOperator
Derived encoding specific mutation/crossover operators from StochasticMultiOperator
#976

File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/sources/HeuristicLab.Encodings.PermutationEncoding/3.3/Crossovers/MultiPermutationCrossover.cs

    r3419 r3425  
    2020#endregion
    2121
     22using System.Linq;
    2223using HeuristicLab.Collections;
    2324using HeuristicLab.Core;
     
    2728using HeuristicLab.Persistence.Default.CompositeSerializers.Storable;
    2829
    29 namespace HeuristicLab.Encodings.PermutationEncoding.Crossovers {
     30namespace HeuristicLab.Encodings.PermutationEncoding {
    3031  [Item("MultiPermutationCrossover", "Randomly selects and applies one of its crossovers every time it is called.")]
    3132  [StorableClass]
    32   public class MultiPermutationCrossover : MultiCrossover<IPermutationCrossover>, IPermutationCrossover {
     33  public class MultiPermutationCrossover : StochasticMultiOperator<IPermutationCrossover>, IPermutationCrossover {
    3334    public override bool CanChangeName {
    3435      get { return false; }
    3536    }
     37    protected override bool CreateChildOperation {
     38      get { return true; }
     39    }
     40    public override bool AutomaticTypeDiscovery {
     41      get { return true; }
     42    }
     43
    3644    public ILookupParameter<ItemArray<Permutation>> ParentsParameter {
    3745      get { return (ILookupParameter<ItemArray<Permutation>>)Parameters["Parents"]; }
     
    5866    private void Initialize() {
    5967      Operators.ItemsAdded += new CollectionItemsChangedEventHandler<IndexedItem<IPermutationCrossover>>(Operators_ItemsAdded);
     68      Operators.ItemsReplaced += new CollectionItemsChangedEventHandler<IndexedItem<IPermutationCrossover>>(Operators_ItemsReplaced);
     69    }
     70
     71    private void Operators_ItemsReplaced(object sender, CollectionItemsChangedEventArgs<IndexedItem<IPermutationCrossover>> e) {
     72      ParameterizeCrossovers();
    6073    }
    6174
     
    6578
    6679    private void ParameterizeCrossovers() {
    67       foreach (IPermutationCrossover crossover in Operators) {
     80      foreach (IPermutationCrossover crossover in Operators.OfType<IPermutationCrossover>()) {
    6881        crossover.ChildParameter.ActualName = ChildParameter.Name;
    6982        crossover.ParentsParameter.ActualName = ParentsParameter.Name;
    7083      }
    71       foreach (IStochasticOperator crossover in Operators) {
     84      foreach (IStochasticOperator crossover in Operators.OfType<IStochasticOperator>()) {
    7285        crossover.RandomParameter.ActualName = RandomParameter.Name;
    7386      }
Note: See TracChangeset for help on using the changeset viewer.