[5060] | 1 | #region License Information
|
---|
| 2 | /* HeuristicLab
|
---|
[14185] | 3 | * Copyright (C) 2002-2016 Heuristic and Evolutionary Algorithms Laboratory (HEAL)
|
---|
[5060] | 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 |
|
---|
| 22 | using System;
|
---|
| 23 | using System.Collections.Generic;
|
---|
| 24 | using HeuristicLab.Common;
|
---|
| 25 | using HeuristicLab.Core;
|
---|
| 26 | using HeuristicLab.Encodings.SymbolicExpressionTreeEncoding;
|
---|
| 27 | using HeuristicLab.Persistence.Default.CompositeSerializers.Storable;
|
---|
| 28 |
|
---|
[5532] | 29 | namespace HeuristicLab.Problems.DataAnalysis.Symbolic {
|
---|
[5060] | 30 | [StorableClass]
|
---|
[7671] | 31 | [Item("Variable Condition", "Represents a condition that tests a given variable against a specified threshold.")]
|
---|
[14826] | 32 | public sealed class VariableCondition : Symbol, IVariableSymbol {
|
---|
[5060] | 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();
|
---|
[8854] | 88 | variableNames.Clear();
|
---|
| 89 | variableNames.AddRange(value);
|
---|
[5060] | 90 | OnChanged(EventArgs.Empty);
|
---|
| 91 | }
|
---|
| 92 | }
|
---|
| 93 |
|
---|
[8853] | 94 | private List<string> allVariableNames;
|
---|
[5060] | 95 | [Storable]
|
---|
[8853] | 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 | }
|
---|
| 103 | }
|
---|
| 104 |
|
---|
| 105 | [Storable]
|
---|
[5060] | 106 | private double slopeInitializerMu;
|
---|
| 107 | public double SlopeInitializerMu {
|
---|
| 108 | get { return slopeInitializerMu; }
|
---|
| 109 | set {
|
---|
| 110 | if (value != slopeInitializerMu) {
|
---|
| 111 | slopeInitializerMu = value;
|
---|
| 112 | OnChanged(EventArgs.Empty);
|
---|
| 113 | }
|
---|
| 114 | }
|
---|
| 115 | }
|
---|
| 116 | [Storable]
|
---|
| 117 | private double slopeInitializerSigma;
|
---|
| 118 | public double SlopeInitializerSigma {
|
---|
| 119 | get { return slopeInitializerSigma; }
|
---|
| 120 | set {
|
---|
| 121 | if (slopeInitializerSigma < 0.0) throw new ArgumentException("Negative sigma is not allowed.");
|
---|
| 122 | if (value != slopeInitializerSigma) {
|
---|
| 123 | slopeInitializerSigma = value;
|
---|
| 124 | OnChanged(EventArgs.Empty);
|
---|
| 125 | }
|
---|
| 126 | }
|
---|
| 127 | }
|
---|
| 128 |
|
---|
| 129 | [Storable]
|
---|
| 130 | private double slopeManipulatorMu;
|
---|
| 131 | public double SlopeManipulatorMu {
|
---|
| 132 | get { return slopeManipulatorMu; }
|
---|
| 133 | set {
|
---|
| 134 | if (value != slopeManipulatorMu) {
|
---|
| 135 | slopeManipulatorMu = value;
|
---|
| 136 | OnChanged(EventArgs.Empty);
|
---|
| 137 | }
|
---|
| 138 | }
|
---|
| 139 | }
|
---|
| 140 | [Storable]
|
---|
| 141 | private double slopeManipulatorSigma;
|
---|
| 142 | public double SlopeManipulatorSigma {
|
---|
| 143 | get { return slopeManipulatorSigma; }
|
---|
| 144 | set {
|
---|
| 145 | if (slopeManipulatorSigma < 0.0) throw new ArgumentException("Negative sigma is not allowed.");
|
---|
| 146 | if (value != slopeManipulatorSigma) {
|
---|
| 147 | slopeManipulatorSigma = value;
|
---|
| 148 | OnChanged(EventArgs.Empty);
|
---|
| 149 | }
|
---|
| 150 | }
|
---|
| 151 | }
|
---|
[6803] | 152 |
|
---|
[14345] | 153 | /// <summary>
|
---|
| 154 | /// Flag to indicate if the interpreter should ignore the slope parameter (introduced for representation of expression trees)
|
---|
| 155 | /// </summary>
|
---|
| 156 | [Storable]
|
---|
| 157 | private bool ignoreSlope;
|
---|
| 158 | public bool IgnoreSlope {
|
---|
| 159 | get { return ignoreSlope; }
|
---|
| 160 | set { ignoreSlope = value; }
|
---|
| 161 | }
|
---|
| 162 |
|
---|
[13255] | 163 | public override bool Enabled {
|
---|
| 164 | get {
|
---|
| 165 | if (variableNames.Count == 0) return false;
|
---|
| 166 | return base.Enabled;
|
---|
| 167 | }
|
---|
| 168 | set {
|
---|
| 169 | if (variableNames.Count == 0) base.Enabled = false;
|
---|
| 170 | else base.Enabled = value;
|
---|
| 171 | }
|
---|
| 172 | }
|
---|
| 173 |
|
---|
[6803] | 174 | private const int minimumArity = 2;
|
---|
| 175 | private const int maximumArity = 2;
|
---|
| 176 |
|
---|
| 177 | public override int MinimumArity {
|
---|
| 178 | get { return minimumArity; }
|
---|
| 179 | }
|
---|
| 180 | public override int MaximumArity {
|
---|
| 181 | get { return maximumArity; }
|
---|
| 182 | }
|
---|
[5060] | 183 | #endregion
|
---|
| 184 |
|
---|
| 185 | #region persistence and cloning
|
---|
[8853] | 186 | [StorableHook(HookType.AfterDeserialization)]
|
---|
| 187 | private void AfterDeserialization() {
|
---|
| 188 | if (allVariableNames == null || (allVariableNames.Count == 0 && variableNames.Count > 0)) {
|
---|
| 189 | allVariableNames = variableNames;
|
---|
| 190 | }
|
---|
| 191 | }
|
---|
| 192 |
|
---|
[5060] | 193 | [StorableConstructor]
|
---|
[8854] | 194 | private VariableCondition(bool deserializing)
|
---|
| 195 | : base(deserializing) {
|
---|
| 196 | variableNames = new List<string>();
|
---|
| 197 | allVariableNames = new List<string>();
|
---|
| 198 | }
|
---|
[5484] | 199 | private VariableCondition(VariableCondition original, Cloner cloner)
|
---|
[5060] | 200 | : base(original, cloner) {
|
---|
| 201 | thresholdInitializerMu = original.thresholdInitializerMu;
|
---|
| 202 | thresholdInitializerSigma = original.thresholdInitializerSigma;
|
---|
| 203 | thresholdManipulatorMu = original.thresholdManipulatorMu;
|
---|
| 204 | thresholdManipulatorSigma = original.thresholdManipulatorSigma;
|
---|
| 205 |
|
---|
| 206 | variableNames = new List<string>(original.variableNames);
|
---|
[8853] | 207 | allVariableNames = new List<string>(original.allVariableNames);
|
---|
[5060] | 208 |
|
---|
| 209 | slopeInitializerMu = original.slopeInitializerMu;
|
---|
| 210 | slopeInitializerSigma = original.slopeInitializerSigma;
|
---|
| 211 | slopeManipulatorMu = original.slopeManipulatorMu;
|
---|
| 212 | slopeManipulatorSigma = original.slopeManipulatorSigma;
|
---|
| 213 | }
|
---|
| 214 | public override IDeepCloneable Clone(Cloner cloner) {
|
---|
| 215 | return new VariableCondition(this, cloner);
|
---|
| 216 | }
|
---|
| 217 | #endregion
|
---|
| 218 |
|
---|
| 219 | public VariableCondition() : this("Variable Condition", "Represents a condition that tests a given variable.") { }
|
---|
| 220 | public VariableCondition(string name, string description)
|
---|
| 221 | : base(name, description) {
|
---|
| 222 | thresholdInitializerMu = 0.0;
|
---|
[5467] | 223 | thresholdInitializerSigma = 0.1;
|
---|
[5060] | 224 | thresholdManipulatorMu = 0.0;
|
---|
[5467] | 225 | thresholdManipulatorSigma = 0.1;
|
---|
[5060] | 226 |
|
---|
| 227 | variableNames = new List<string>();
|
---|
[8853] | 228 | allVariableNames = new List<string>();
|
---|
[5060] | 229 |
|
---|
[7671] | 230 | slopeInitializerMu = 0.0;
|
---|
| 231 | slopeInitializerSigma = 0.0;
|
---|
[5060] | 232 | slopeManipulatorMu = 0.0;
|
---|
[7671] | 233 | slopeManipulatorSigma = 0.0;
|
---|
[5060] | 234 | }
|
---|
| 235 |
|
---|
[5532] | 236 | public override ISymbolicExpressionTreeNode CreateTreeNode() {
|
---|
[5060] | 237 | return new VariableConditionTreeNode(this);
|
---|
| 238 | }
|
---|
| 239 | }
|
---|
| 240 | }
|
---|