Free cookie consent management tool by TermsFeed Policy Generator

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

Last change on this file since 4089 was 4089, checked in by abeham, 14 years ago

#1041

  • Added project with operators to convert expression trees to protocol buffer messages
File size: 3.7 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    public Variable()
94      : base("Variable", "Represents a variable value.") {
95      weightNu = 1.0;
96      weightSigma = 1.0;
97      weightManipulatorNu = 0.0;
98      weightManipulatorSigma = 1.0;
99      variableNames = new List<string>();
100    }
101
102    public override SymbolicExpressionTreeNode CreateTreeNode() {
103      return new VariableTreeNode(this);
104    }
105
106    public override IDeepCloneable Clone(Cloner cloner) {
107      Variable clone = (Variable)base.Clone(cloner);
108      clone.weightNu = weightNu;
109      clone.weightSigma = weightSigma;
110      clone.variableNames = new List<string>(variableNames);
111      clone.weightManipulatorNu = weightManipulatorNu;
112      clone.weightManipulatorSigma = weightManipulatorSigma;
113      return clone;
114    }
115  }
116}
Note: See TracBrowser for help on using the repository browser.