Free cookie consent management tool by TermsFeed Policy Generator

source: branches/HeuristicLab.MetaOptimization/HeuristicLab.Problems.MetaOptimization/3.3/Encodings/RangeConstraints/ConstrainedValue.cs @ 5110

Last change on this file since 5110 was 5110, checked in by cneumuel, 13 years ago

#1215

  • optional parameter values now can be null
  • problem type can now be set specifically
  • values are constrained to the encoding of the Problem
  • moved repetitions parameter to MetaOptimizationProblem
File size: 2.8 KB
Line 
1using System;
2using System.Collections.Generic;
3using System.Linq;
4using System.Text;
5using HeuristicLab.Core;
6using HeuristicLab.Common;
7using HeuristicLab.Persistence.Default.CompositeSerializers.Storable;
8using HeuristicLab.Data;
9
10namespace HeuristicLab.Problems.MetaOptimization {
11  [StorableClass]
12  public class ConstrainedValue : Item {
13    [Storable]
14    protected Type valueDataType;
15    public Type ValueDataType {
16      get { return this.valueDataType; }
17      protected set { this.valueDataType = value; }
18    }
19
20    [Storable]
21    protected IItem value;
22    public IItem Value {
23      get { return value; }
24      set {
25        if (this.value != value) {
26          if(this.value != null) DeregisterEvents();
27          this.value = value;
28          if(this.value != null) RegisterEvents();
29          OnToStringChanged();
30        }
31      }
32    }
33
34    [Storable]
35    protected IItemSet<IItem> validValues;
36    public IItemSet<IItem> ValidValues {
37      get { return validValues; }
38      protected set {
39        if (this.validValues != value) {
40          this.validValues = value;
41        }
42      }
43    }
44
45    [Storable]
46    protected bool isNullable;
47    public bool IsNullable {
48      get { return isNullable; }
49      protected set {
50        if (this.isNullable != value) {
51          this.isNullable = value;
52        }
53      }
54    }
55
56    private void RegisterEvents() {
57      this.value.ToStringChanged += new EventHandler(value_ToStringChanged);
58    }
59    private void DeregisterEvents() {
60      this.value.ToStringChanged -= new EventHandler(value_ToStringChanged);
61    }
62
63    #region constructors and cloning
64    public ConstrainedValue() { }
65    [StorableConstructor]
66    protected ConstrainedValue(bool deserializing) : base(deserializing) { }
67    public ConstrainedValue(IItem value, Type valueDataType, IItemSet<IItem> validValues, bool isNullable) {
68      this.Value = value;
69      this.ValueDataType = valueDataType;
70      this.ValidValues = validValues;
71      this.isNullable = isNullable;
72    }
73    protected ConstrainedValue(ConstrainedValue original, Cloner cloner) : base(original, cloner) {
74      this.valueDataType = original.valueDataType;
75      this.Value = cloner.Clone(original.value);
76      this.ValidValues = cloner.Clone(original.ValidValues);
77      this.isNullable = original.isNullable;
78    }
79    public override IDeepCloneable Clone(Cloner cloner) {
80      return new ConstrainedValue(this, cloner);
81    }
82    [StorableHook(HookType.AfterDeserialization)]
83    private void AfterDeserialization() {
84      if (this.value != null) RegisterEvents();
85    }
86    #endregion
87
88    void value_ToStringChanged(object sender, EventArgs e) {
89      OnToStringChanged();
90    }
91
92    public override string ToString() {
93      return value != null ? value.ToString() : base.ToString();
94    }
95  }
96}
Note: See TracBrowser for help on using the repository browser.