Ignore:
Timestamp:
01/13/15 18:47:19 (7 years ago)
Author:
mkommend
Message:

#2174: First working version of refactored programmable problem.

File:
1 edited

Legend:

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

    r11737 r11753  
    3838
    3939    protected HashSet<IOperator> encodingOperators = new HashSet<IOperator>(new TypeEqualityComparer<IOperator>());
    40     [Storable]
     40
     41    [Storable(Name = "Operators")]
     42    private IEnumerable<IOperator> StorableOperators {
     43      get { return encodingOperators; }
     44      set { encodingOperators = new HashSet<IOperator>(value, new TypeEqualityComparer<IOperator>()); ; }
     45    }
     46
    4147    public IEnumerable<IOperator> Operators {
    4248      get { return encodingOperators; }
    43       private set { encodingOperators = new HashSet<IOperator>(value, new TypeEqualityComparer<IOperator>()); }
     49      set {
     50        if (!value.OfType<T>().Any())
     51          throw new ArgumentException("The provided operators contain no suitable solution creator");
     52        encodingOperators = new HashSet<IOperator>(value, new TypeEqualityComparer<IOperator>());
     53
     54        T newSolutionCreator = (T)encodingOperators.FirstOrDefault(o => o.GetType() == solutionCreator.GetType());
     55        if (newSolutionCreator == null) newSolutionCreator = encodingOperators.OfType<T>().First();
     56        SolutionCreator = newSolutionCreator;
     57        OnOperatorsChanged();
     58      }
    4459    }
    4560
     
    90105      if (handler != null) handler(this, EventArgs.Empty);
    91106    }
     107
     108    public event EventHandler OperatorsChanged;
     109    protected virtual void OnOperatorsChanged() {
     110      ConfigureOperators(Operators);
     111      var handler = OperatorsChanged;
     112      if (handler != null) handler(this, EventArgs.Empty);
     113    }
    92114  }
    93115}
Note: See TracChangeset for help on using the changeset viewer.