Free cookie consent management tool by TermsFeed Policy Generator

Ignore:
Timestamp:
11/23/15 15:15:27 (7 years ago)
Author:
mkommend
Message:

#2521: Refactored encodings and problems.

File:
1 edited

Legend:

Unmodified
Added
Removed
  • branches/ProblemRefactoring/HeuristicLab.Optimization/3.3/BasicProblems/Encoding.cs

    r12981 r13336  
    3131  [Item("Encoding", "Base class for describing different encodings.")]
    3232  [StorableClass]
    33   public abstract class Encoding<T> : ParameterizedNamedItem, IEncoding
    34     where T : class,ISolutionCreator {
     33  public abstract class Encoding<TSolution> : ParameterizedNamedItem, IEncoding<TSolution>
     34    where TSolution : class,ISolution {
    3535    public override sealed bool CanChangeName {
    3636      get { return false; }
     
    4848      get { return encodingOperators; }
    4949      set {
    50         if (!value.OfType<T>().Any())
     50        if (!value.OfType<ISolutionCreator<TSolution>>().Any())
    5151          throw new ArgumentException("The provided operators contain no suitable solution creator");
    5252        encodingOperators.Clear();
    5353        foreach (var op in value) encodingOperators.Add(op);
    5454
    55         T newSolutionCreator = (T)encodingOperators.FirstOrDefault(o => o.GetType() == solutionCreator.GetType()) ??
    56                                encodingOperators.OfType<T>().First();
     55        ISolutionCreator<TSolution> newSolutionCreator = (ISolutionCreator<TSolution>)encodingOperators.FirstOrDefault(o => o.GetType() == solutionCreator.GetType()) ??
     56                               encodingOperators.OfType<ISolutionCreator<TSolution>>().First();
    5757        SolutionCreator = newSolutionCreator;
    5858        OnOperatorsChanged();
     
    6060    }
    6161
    62     ISolutionCreator IEncoding.SolutionCreator {
    63       get { return SolutionCreator; }
    64       set {
    65         if (!(value is T)) throw new ArgumentException(string.Format("Cannot assign the solution creator {0} to the encoding {1}.", value.GetType().GetPrettyName(), GetType().GetPrettyName()));
    66         SolutionCreator = (T)value;
    67       }
    68     }
    6962    [Storable]
    70     private T solutionCreator;
    71     public T SolutionCreator {
     63    private ISolutionCreator<TSolution> solutionCreator;
     64    public ISolutionCreator<TSolution> SolutionCreator {
    7265      get {
    7366        return solutionCreator;
     
    8578    [StorableConstructor]
    8679    protected Encoding(bool deserializing) : base(deserializing) { }
    87     protected Encoding(Encoding<T> original, Cloner cloner)
     80    protected Encoding(Encoding<TSolution> original, Cloner cloner)
    8881      : base(original, cloner) {
    8982      encodingOperators = cloner.Clone(original.encodingOperators);
     
    9386      : base(name) {
    9487      Parameters.Add(new FixedValueParameter<ReadOnlyItemSet<IOperator>>(name + ".Operators", "The operators that the encoding specifies.", encodingOperators.AsReadOnly()));
    95     }
    96 
    97     public virtual Individual GetIndividual(IScope scope) {
    98       return new SingleEncodingIndividual(this, scope);
    9988    }
    10089
Note: See TracChangeset for help on using the changeset viewer.