Free cookie consent management tool by TermsFeed Policy Generator

Ignore:
Timestamp:
01/21/15 11:54:43 (9 years ago)
Author:
mkommend
Message:

#2174: Updated views and renamed programmable problem to basic problem and added individual extension methods.

File:
1 edited

Legend:

Unmodified
Added
Removed
  • branches/ProgrammableProblem/HeuristicLab.Problems.Programmable/3.3/Individuals/MultiEncodingIndividual.cs

    r11737 r11813  
    2323using System.Collections.Generic;
    2424using System.Linq;
     25using HeuristicLab.Common;
    2526using HeuristicLab.Core;
    2627
     
    4647    public override IItem this[string name] {
    4748      get {
    48         var individual = individuals.FirstOrDefault(i => i.Name == name);
     49        var individual = individuals.SingleOrDefault(i => i.Name == name);
    4950        if (individual == null) throw new ArgumentException(string.Format("{0} is not part of the specified encoding.", name));
    5051        return individual[name];
    5152      }
    5253      set {
    53         var individual = individuals.FirstOrDefault(i => i.Name == name);
     54        var individual = individuals.SingleOrDefault(i => i.Name == name);
    5455        if (individual == null) throw new ArgumentException(string.Format("{0} is not part of the specified encoding.", name));
    5556        individual[name] = value;
    5657      }
     58    }
     59
     60    public override TEncoding GetEncoding<TEncoding>() {
     61      TEncoding encoding;
     62      try {
     63        encoding = (TEncoding)Encoding.Encodings.SingleOrDefault(e => e is TEncoding);
     64      }
     65      catch (InvalidOperationException) {
     66        throw new InvalidOperationException(string.Format("The individual uses multiple {0} .", typeof(TEncoding).GetPrettyName()));
     67      }
     68      if (encoding == null) throw new InvalidOperationException(string.Format("The individual does not use a {0}.", typeof(TEncoding).GetPrettyName()));
     69      return encoding;
    5770    }
    5871
Note: See TracChangeset for help on using the changeset viewer.