Free cookie consent management tool by TermsFeed Policy Generator

Ignore:
Timestamp:
02/06/15 15:22:27 (9 years ago)
Author:
abeham
Message:

#2174:

  • Made encodingOperators hash set an ItemSet and private
  • Added a parameter that displays the operators of an encoding (fixedvalue showing a readonly version of the itemset)
  • Added protected methods to Encoding to add and remove operators
  • Adapted MultiEncodingView to derive from ParameterizedNamedItemView
  • Added name of MultiEncoding itself to list of forbidden names
Location:
branches/ProgrammableProblem/HeuristicLab.Optimization/3.3/BasicProblems
Files:
2 edited

Legend:

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

    r11949 r11952  
    2626using HeuristicLab.Core;
    2727using HeuristicLab.Optimization;
     28using HeuristicLab.Parameters;
    2829using HeuristicLab.Persistence.Default.CompositeSerializers.Storable;
    2930
     
    3738    }
    3839
    39     protected HashSet<IOperator> encodingOperators = new HashSet<IOperator>(new TypeEqualityComparer<IOperator>());
     40    private ItemSet<IOperator> encodingOperators = new ItemSet<IOperator>(new TypeEqualityComparer<IOperator>());
    4041
    4142    [Storable(Name = "Operators")]
    4243    private IEnumerable<IOperator> StorableOperators {
    4344      get { return encodingOperators; }
    44       set { encodingOperators = new HashSet<IOperator>(value, new TypeEqualityComparer<IOperator>()); ; }
     45      set { encodingOperators = new ItemSet<IOperator>(value, new TypeEqualityComparer<IOperator>()); ; }
    4546    }
    4647
     
    5051        if (!value.OfType<T>().Any())
    5152          throw new ArgumentException("The provided operators contain no suitable solution creator");
    52         encodingOperators = new HashSet<IOperator>(value, new TypeEqualityComparer<IOperator>());
     53        encodingOperators.Clear();
     54        foreach (var op in value) encodingOperators.Add(op);
    5355
    5456        T newSolutionCreator = (T)encodingOperators.FirstOrDefault(o => o.GetType() == solutionCreator.GetType()) ??
     
    8587    protected Encoding(Encoding<T> original, Cloner cloner)
    8688      : base(original, cloner) {
    87       encodingOperators = new HashSet<IOperator>(original.Operators.Select(cloner.Clone), new TypeEqualityComparer<IOperator>());
     89      encodingOperators = cloner.Clone(original.encodingOperators);
    8890      solutionCreator = cloner.Clone(original.solutionCreator);
    8991    }
    90     protected Encoding(string name) : base(name) { }
     92    protected Encoding(string name)
     93      : base(name) {
     94      Parameters.Add(new FixedValueParameter<ReadOnlyItemSet<IOperator>>(name + ".Operators", "The operators that the encoding specifies.", encodingOperators.AsReadOnly()));
     95    }
    9196
    9297    public virtual Individual GetIndividual(IScope scope) {
    9398      return new SingleEncodingIndividual(this, scope);
     99    }
     100
     101    protected bool AddOperator(IOperator @operator) {
     102      return encodingOperators.Add(@operator);
     103    }
     104
     105    protected bool RemoveOperator(IOperator @operator) {
     106      return encodingOperators.Remove(@operator);
    94107    }
    95108
  • branches/ProgrammableProblem/HeuristicLab.Optimization/3.3/BasicProblems/MultiEncoding.cs

    r11949 r11952  
    5656
    5757      foreach (var @operator in ApplicationManager.Manager.GetInstances<IMultiEncodingOperator>())
    58         encodingOperators.Add(@operator);
     58        AddOperator(@operator);
    5959    }
    6060
Note: See TracChangeset for help on using the changeset viewer.