Free cookie consent management tool by TermsFeed Policy Generator

source: branches/GP.Symbols (TimeLag, Diff, Integral)/HeuristicLab.Problems.DataAnalysis/3.3/Symbolic/Symbols/VariableCondition.cs @ 5076

Last change on this file since 5076 was 5076, checked in by mkommend, 13 years ago

Corrected persistence of VariableCondition and conditional evaluator (ticket #1256).

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