Free cookie consent management tool by TermsFeed Policy Generator

source: branches/gteufl/HeuristicLab.Problems.DataAnalysis.Symbolic/3.4/Symbols/VariableCondition.cs @ 10331

Last change on this file since 10331 was 9456, checked in by swagner, 11 years ago

Updated copyright year and added some missing license headers (#1889)

File size: 7.3 KB
Line 
1#region License Information
2/* HeuristicLab
3 * Copyright (C) 2002-2013 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 HeuristicLab.Common;
25using HeuristicLab.Core;
26using HeuristicLab.Encodings.SymbolicExpressionTreeEncoding;
27using HeuristicLab.Persistence.Default.CompositeSerializers.Storable;
28
29namespace HeuristicLab.Problems.DataAnalysis.Symbolic {
30  [StorableClass]
31  [Item("Variable Condition", "Represents a condition that tests a given variable against a specified threshold.")]
32  public sealed class VariableCondition : Symbol {
33    #region properties
34    [Storable]
35    private double thresholdInitializerMu;
36    public double ThresholdInitializerMu {
37      get { return thresholdInitializerMu; }
38      set {
39        if (value != thresholdInitializerMu) {
40          thresholdInitializerMu = value;
41          OnChanged(EventArgs.Empty);
42        }
43      }
44    }
45    [Storable]
46    private double thresholdInitializerSigma;
47    public double ThresholdInitializerSigma {
48      get { return thresholdInitializerSigma; }
49      set {
50        if (thresholdInitializerSigma < 0.0) throw new ArgumentException("Negative sigma is not allowed.");
51        if (value != thresholdInitializerSigma) {
52          thresholdInitializerSigma = value;
53          OnChanged(EventArgs.Empty);
54        }
55      }
56    }
57
58    [Storable]
59    private double thresholdManipulatorMu;
60    public double ThresholdManipulatorMu {
61      get { return thresholdManipulatorMu; }
62      set {
63        if (value != thresholdManipulatorMu) {
64          thresholdManipulatorMu = value;
65          OnChanged(EventArgs.Empty);
66        }
67      }
68    }
69    [Storable]
70    private double thresholdManipulatorSigma;
71    public double ThresholdManipulatorSigma {
72      get { return thresholdManipulatorSigma; }
73      set {
74        if (thresholdManipulatorSigma < 0.0) throw new ArgumentException("Negative sigma is not allowed.");
75        if (value != thresholdManipulatorSigma) {
76          thresholdManipulatorSigma = value;
77          OnChanged(EventArgs.Empty);
78        }
79      }
80    }
81
82    private List<string> variableNames;
83    [Storable]
84    public IEnumerable<string> VariableNames {
85      get { return variableNames; }
86      set {
87        if (value == null) throw new ArgumentNullException();
88        variableNames.Clear();
89        variableNames.AddRange(value);
90        OnChanged(EventArgs.Empty);
91      }
92    }
93
94    private List<string> allVariableNames;
95    [Storable]
96    public IEnumerable<string> AllVariableNames {
97      get { return allVariableNames; }
98      set {
99        if (value == null) throw new ArgumentNullException();
100        allVariableNames.Clear();
101        allVariableNames.AddRange(value);
102        VariableNames = value;
103      }
104    }
105
106    [Storable]
107    private double slopeInitializerMu;
108    public double SlopeInitializerMu {
109      get { return slopeInitializerMu; }
110      set {
111        if (value != slopeInitializerMu) {
112          slopeInitializerMu = value;
113          OnChanged(EventArgs.Empty);
114        }
115      }
116    }
117    [Storable]
118    private double slopeInitializerSigma;
119    public double SlopeInitializerSigma {
120      get { return slopeInitializerSigma; }
121      set {
122        if (slopeInitializerSigma < 0.0) throw new ArgumentException("Negative sigma is not allowed.");
123        if (value != slopeInitializerSigma) {
124          slopeInitializerSigma = value;
125          OnChanged(EventArgs.Empty);
126        }
127      }
128    }
129
130    [Storable]
131    private double slopeManipulatorMu;
132    public double SlopeManipulatorMu {
133      get { return slopeManipulatorMu; }
134      set {
135        if (value != slopeManipulatorMu) {
136          slopeManipulatorMu = value;
137          OnChanged(EventArgs.Empty);
138        }
139      }
140    }
141    [Storable]
142    private double slopeManipulatorSigma;
143    public double SlopeManipulatorSigma {
144      get { return slopeManipulatorSigma; }
145      set {
146        if (slopeManipulatorSigma < 0.0) throw new ArgumentException("Negative sigma is not allowed.");
147        if (value != slopeManipulatorSigma) {
148          slopeManipulatorSigma = value;
149          OnChanged(EventArgs.Empty);
150        }
151      }
152    }
153
154    private const int minimumArity = 2;
155    private const int maximumArity = 2;
156
157    public override int MinimumArity {
158      get { return minimumArity; }
159    }
160    public override int MaximumArity {
161      get { return maximumArity; }
162    }
163    #endregion
164
165    #region persistence and cloning
166    [StorableHook(HookType.AfterDeserialization)]
167    private void AfterDeserialization() {
168      if (allVariableNames == null || (allVariableNames.Count == 0 && variableNames.Count > 0)) {
169        allVariableNames = variableNames;
170      }
171    }
172
173    [StorableConstructor]
174    private VariableCondition(bool deserializing)
175      : base(deserializing) {
176      variableNames = new List<string>();
177      allVariableNames = new List<string>();
178    }
179    private VariableCondition(VariableCondition original, Cloner cloner)
180      : base(original, cloner) {
181      thresholdInitializerMu = original.thresholdInitializerMu;
182      thresholdInitializerSigma = original.thresholdInitializerSigma;
183      thresholdManipulatorMu = original.thresholdManipulatorMu;
184      thresholdManipulatorSigma = original.thresholdManipulatorSigma;
185
186      variableNames = new List<string>(original.variableNames);
187      allVariableNames = new List<string>(original.allVariableNames);
188
189      slopeInitializerMu = original.slopeInitializerMu;
190      slopeInitializerSigma = original.slopeInitializerSigma;
191      slopeManipulatorMu = original.slopeManipulatorMu;
192      slopeManipulatorSigma = original.slopeManipulatorSigma;
193    }
194    public override IDeepCloneable Clone(Cloner cloner) {
195      return new VariableCondition(this, cloner);
196    }
197    #endregion
198
199    public VariableCondition() : this("Variable Condition", "Represents a condition that tests a given variable.") { }
200    public VariableCondition(string name, string description)
201      : base(name, description) {
202      thresholdInitializerMu = 0.0;
203      thresholdInitializerSigma = 0.1;
204      thresholdManipulatorMu = 0.0;
205      thresholdManipulatorSigma = 0.1;
206
207      variableNames = new List<string>();
208      allVariableNames = new List<string>();
209
210      slopeInitializerMu = 0.0;
211      slopeInitializerSigma = 0.0;
212      slopeManipulatorMu = 0.0;
213      slopeManipulatorSigma = 0.0;
214    }
215
216    public override ISymbolicExpressionTreeNode CreateTreeNode() {
217      return new VariableConditionTreeNode(this);
218    }
219  }
220}
Note: See TracBrowser for help on using the repository browser.