Free cookie consent management tool by TermsFeed Policy Generator

source: trunk/sources/HeuristicLab.Problems.ExternalEvaluation.GP/3.3/Symbols/Variable.cs @ 4722

Last change on this file since 4722 was 4722, checked in by swagner, 14 years ago

Merged cloning refactoring branch back into trunk (#922)

File size: 3.9 KB
Line 
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.ExternalEvaluation.GP {
31  [StorableClass]
32  [Item("Variable", "Represents a variable value.")]
33  public sealed class Variable : Symbol {
34    #region Properties
35    [Storable]
36    private double weightNu;
37    public double WeightNu {
38      get { return weightNu; }
39      set {
40        if (value != weightNu) {
41          weightNu = value;
42          OnChanged(EventArgs.Empty);
43        }
44      }
45    }
46    [Storable]
47    private double weightSigma;
48    public double WeightSigma {
49      get { return weightSigma; }
50      set {
51        if (weightSigma < 0.0) throw new ArgumentException("Negative sigma is not allowed.");
52        if (value != weightSigma) {
53          weightSigma = value;
54          OnChanged(EventArgs.Empty);
55        }
56      }
57    }
58    [Storable]
59    private double weightManipulatorNu;
60    public double WeightManipulatorNu {
61      get { return weightManipulatorNu; }
62      set {
63        if (value != weightManipulatorNu) {
64          weightManipulatorNu = value;
65          OnChanged(EventArgs.Empty);
66        }
67      }
68    }
69    [Storable]
70    private double weightManipulatorSigma;
71    public double WeightManipulatorSigma {
72      get { return weightManipulatorSigma; }
73      set {
74        if (weightManipulatorSigma < 0.0) throw new ArgumentException("Negative sigma is not allowed.");
75        if (value != weightManipulatorSigma) {
76          weightManipulatorSigma = value;
77          OnChanged(EventArgs.Empty);
78        }
79      }
80    }
81    private List<string> variableNames;
82    [Storable]
83    public IEnumerable<string> VariableNames {
84      get { return variableNames; }
85      set {
86        if (value == null) throw new ArgumentNullException();
87        variableNames.Clear();
88        variableNames.AddRange(value);
89        OnChanged(EventArgs.Empty);
90      }
91    }
92    #endregion
93
94    [StorableConstructor]
95    private Variable(bool deserializing) : base(deserializing) { }
96    private Variable(Variable original, Cloner cloner)
97      : base(original, cloner) {
98      weightNu = original.weightNu;
99      weightSigma = original.weightSigma;
100      variableNames = new List<string>(original.variableNames);
101      weightManipulatorNu = original.weightManipulatorNu;
102      weightManipulatorSigma = original.weightManipulatorSigma;
103    }
104    public override IDeepCloneable Clone(Cloner cloner) {
105      return new Variable(this, cloner);
106    }
107
108    public Variable()
109      : base("Variable", "Represents a variable value.") {
110      weightNu = 1.0;
111      weightSigma = 1.0;
112      weightManipulatorNu = 0.0;
113      weightManipulatorSigma = 1.0;
114      variableNames = new List<string>();
115    }
116
117    public override SymbolicExpressionTreeNode CreateTreeNode() {
118      return new VariableTreeNode(this);
119    }
120  }
121}
Note: See TracBrowser for help on using the repository browser.