Free cookie consent management tool by TermsFeed Policy Generator

source: branches/VNS/HeuristicLab.Problems.ExternalEvaluation.GP/3.3/Symbols/Variable.cs @ 5594

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

Updated year of copyrights (#1406)

File size: 4.0 KB
Line 
1#region License Information
2/* HeuristicLab
3 * Copyright (C) 2002-2011 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      variableNames = new List<string>();
97    }
98    private Variable(Variable original, Cloner cloner)
99      : base(original, cloner) {
100      weightNu = original.weightNu;
101      weightSigma = original.weightSigma;
102      variableNames = new List<string>(original.variableNames);
103      weightManipulatorNu = original.weightManipulatorNu;
104      weightManipulatorSigma = original.weightManipulatorSigma;
105    }
106    public override IDeepCloneable Clone(Cloner cloner) {
107      return new Variable(this, cloner);
108    }
109
110    public Variable()
111      : base("Variable", "Represents a variable value.") {
112      weightNu = 1.0;
113      weightSigma = 1.0;
114      weightManipulatorNu = 0.0;
115      weightManipulatorSigma = 1.0;
116      variableNames = new List<string>();
117    }
118
119    public override SymbolicExpressionTreeNode CreateTreeNode() {
120      return new VariableTreeNode(this);
121    }
122  }
123}
Note: See TracBrowser for help on using the repository browser.