Free cookie consent management tool by TermsFeed Policy Generator

Ignore:
Timestamp:
11/26/14 13:24:20 (9 years ago)
Author:
mkommend
Message:

#2174: Implemented multi-encoding operators and adapated wiring of operators in the programmable problems.

File:
1 edited

Legend:

Unmodified
Added
Removed
  • branches/ProgrammableProblem/HeuristicLab.Problems.Programmable/3.3/Encodings/Encoding.cs

    r11582 r11587  
    3737    }
    3838
    39     public virtual IEnumerable<IValueParameter> Parameters {
    40       get { return Enumerable.Empty<IValueParameter>(); }
    41     }
     39    public abstract IEnumerable<IValueParameter> Parameters { get; }
    4240
    43     protected List<IOperator> encodingOperators = new List<IOperator>();
     41    protected HashSet<IOperator> encodingOperators = new HashSet<IOperator>(new TypeEqualityComparer<IOperator>());
    4442    [Storable]
    4543    public IEnumerable<IOperator> Operators {
    4644      get { return encodingOperators; }
    47       protected set { encodingOperators = new List<IOperator>(value); }
     45      private set { encodingOperators = new HashSet<IOperator>(value, new TypeEqualityComparer<IOperator>()); }
    4846    }
    49 
    5047
    5148    ISolutionCreator IEncoding.SolutionCreator {
    5249      get { return SolutionCreator; }
    5350      set {
    54         if (!(value is T)) throw new ArgumentException("???");
     51        if (!(value is T)) throw new ArgumentException(string.Format("Cannot assign the solution creator {0} to the encoding {1}.", value.GetType().GetPrettyName(), GetType().GetPrettyName()));
    5552        SolutionCreator = (T)value;
    5653      }
     
    6461        if (value == null) throw new ArgumentNullException("SolutionCreator must not be null.");
    6562        if (solutionCreator == value) return;
     63        encodingOperators.Remove(solutionCreator);
     64        encodingOperators.Add(value);
    6665        solutionCreator = value;
    6766        OnSolutionCreatorChanged();
     
    7473    protected Encoding(Encoding<T> original, Cloner cloner)
    7574      : base(original, cloner) {
    76       encodingOperators = original.Operators.Select(cloner.Clone).ToList();
     75      encodingOperators = new HashSet<IOperator>(original.Operators.Select(cloner.Clone));
    7776      solutionCreator = cloner.Clone(original.solutionCreator);
    7877    }
     
    8079
    8180
     81    public abstract void ConfigureOperators(IEnumerable<IOperator> operators);
     82    public void ConfigureOperator(IOperator @operator) { ConfigureOperators(new[] { @operator }); }
    8283
    83     public void ConfigureOperator(IOperator @operator) {
    84       ConfigureOperators(new[] { @operator });
    85     }
    86     public virtual void ConfigureOperators(IEnumerable<IOperator> operators) {
    87 
    88     }
    89 
     84    public event EventHandler SolutionCreatorChanged;
    9085    protected virtual void OnSolutionCreatorChanged() {
    9186      ConfigureOperator(SolutionCreator);
     87      var handler = SolutionCreatorChanged;
     88      if (handler != null) handler(this, EventArgs.Empty);
    9289    }
    9390
Note: See TracChangeset for help on using the changeset viewer.