Free cookie consent management tool by TermsFeed Policy Generator

source: branches/ProgrammableProblem/HeuristicLab.Problems.Programmable/3.3/Encodings/Encoding.cs @ 11582

Last change on this file since 11582 was 11582, checked in by mkommend, 9 years ago

#2174: Configured solution creator in single encodings.

File size: 3.3 KB
Line 
1#region License Information
2/* HeuristicLab
3 * Copyright (C) 2002-2014 Heuristic and Evolutionary Algorithms Laboratory (HEAL)
4 *
5 * This file is part of HeuristicLab.
6 *
7 * HeuristicLab is free software: you can redistribute it and/or modify
8 * it under the terms of the GNU General Public License as published by
9 * the Free Software Foundation, either version 3 of the License, or
10 * (at your option) any later version.
11 *
12 * HeuristicLab is distributed in the hope that it will be useful,
13 * but WITHOUT ANY WARRANTY; without even the implied warranty of
14 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
15 * GNU General Public License for more details.
16 *
17 * You should have received a copy of the GNU General Public License
18 * along with HeuristicLab. If not, see <http://www.gnu.org/licenses/>.
19 */
20#endregion
21
22using System;
23using System.Collections.Generic;
24using System.Linq;
25using HeuristicLab.Common;
26using HeuristicLab.Core;
27using HeuristicLab.Optimization;
28using HeuristicLab.Persistence.Default.CompositeSerializers.Storable;
29
30namespace HeuristicLab.Problems.Programmable {
31  [Item("Encoding", "Base class for describing different encodings.")]
32  [StorableClass]
33  public abstract class Encoding<T> : NamedItem, IEncoding
34    where T : class,ISolutionCreator {
35    public override sealed bool CanChangeName {
36      get { return false; }
37    }
38
39    public virtual IEnumerable<IValueParameter> Parameters {
40      get { return Enumerable.Empty<IValueParameter>(); }
41    }
42
43    protected List<IOperator> encodingOperators = new List<IOperator>();
44    [Storable]
45    public IEnumerable<IOperator> Operators {
46      get { return encodingOperators; }
47      protected set { encodingOperators = new List<IOperator>(value); }
48    }
49
50
51    ISolutionCreator IEncoding.SolutionCreator {
52      get { return SolutionCreator; }
53      set {
54        if (!(value is T)) throw new ArgumentException("???");
55        SolutionCreator = (T)value;
56      }
57    }
58    private T solutionCreator;
59    public T SolutionCreator {
60      get {
61        return solutionCreator;
62      }
63      set {
64        if (value == null) throw new ArgumentNullException("SolutionCreator must not be null.");
65        if (solutionCreator == value) return;
66        solutionCreator = value;
67        OnSolutionCreatorChanged();
68      }
69    }
70
71    [StorableConstructor]
72    protected Encoding(bool deserializing) : base(deserializing) { }
73
74    protected Encoding(Encoding<T> original, Cloner cloner)
75      : base(original, cloner) {
76      encodingOperators = original.Operators.Select(cloner.Clone).ToList();
77      solutionCreator = cloner.Clone(original.solutionCreator);
78    }
79    protected Encoding(string name) : base(name) { }
80
81
82
83    public void ConfigureOperator(IOperator @operator) {
84      ConfigureOperators(new[] { @operator });
85    }
86    public virtual void ConfigureOperators(IEnumerable<IOperator> operators) {
87
88    }
89
90    protected virtual void OnSolutionCreatorChanged() {
91      ConfigureOperator(SolutionCreator);
92    }
93
94
95    public event EventHandler ParameterConfigurationChanged;
96    protected virtual void OnParameterConfigurationChanged() {
97      var handler = ParameterConfigurationChanged;
98      if (handler != null) handler(this, EventArgs.Empty);
99    }
100  }
101}
Note: See TracBrowser for help on using the repository browser.