[14233] | 1 | #region License Information
|
---|
| 2 | /* HeuristicLab
|
---|
[17181] | 3 | * Copyright (C) Heuristic and Evolutionary Algorithms Laboratory (HEAL)
|
---|
[14233] | 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 System.Linq;
|
---|
| 25 | using HeuristicLab.Common;
|
---|
| 26 | using HeuristicLab.Core;
|
---|
| 27 | using HeuristicLab.Encodings.SymbolicExpressionTreeEncoding;
|
---|
[17097] | 28 | using HEAL.Attic;
|
---|
[14233] | 29 | namespace HeuristicLab.Problems.DataAnalysis.Symbolic {
|
---|
[17097] | 30 | [StorableType("241007AC-B461-4028-BA3A-79F393FF3ACB")]
|
---|
[14243] | 31 | [Item("BinaryFactorVariable", "Represents a categorical variable (comparable to factors as in R) and it's value.")]
|
---|
[15132] | 32 | public sealed class BinaryFactorVariable : VariableBase {
|
---|
[14233] | 33 |
|
---|
[14249] | 34 | private readonly Dictionary<string, List<string>> variableValues;
|
---|
[14233] | 35 |
|
---|
| 36 | [Storable]
|
---|
| 37 | public IEnumerable<KeyValuePair<string, List<string>>> VariableValues {
|
---|
| 38 | get { return variableValues; }
|
---|
| 39 | set {
|
---|
| 40 | if (value == null) throw new ArgumentNullException();
|
---|
| 41 | variableValues.Clear();
|
---|
| 42 | foreach (var kvp in value) {
|
---|
| 43 | variableValues.Add(kvp.Key, new List<string>(kvp.Value));
|
---|
| 44 | }
|
---|
| 45 | }
|
---|
| 46 | }
|
---|
| 47 |
|
---|
| 48 | [StorableConstructor]
|
---|
[17097] | 49 | private BinaryFactorVariable(StorableConstructorFlag _) : base(_) {
|
---|
[14233] | 50 | variableValues = new Dictionary<string, List<string>>();
|
---|
| 51 | }
|
---|
[15132] | 52 | private BinaryFactorVariable(BinaryFactorVariable original, Cloner cloner)
|
---|
[14233] | 53 | : base(original, cloner) {
|
---|
| 54 | variableValues =
|
---|
| 55 | original.variableValues.ToDictionary(kvp => kvp.Key, kvp => new List<string>(kvp.Value));
|
---|
| 56 | }
|
---|
[14243] | 57 | public BinaryFactorVariable() : this("BinaryFactorVariable", "Represents a categorical variable (comparable to factors as in R) and it's value.") { }
|
---|
| 58 | public BinaryFactorVariable(string name, string description)
|
---|
[14233] | 59 | : base(name, description) {
|
---|
| 60 | variableValues = new Dictionary<string, List<string>>();
|
---|
| 61 | }
|
---|
| 62 |
|
---|
| 63 | public override ISymbolicExpressionTreeNode CreateTreeNode() {
|
---|
[14249] | 64 | return new BinaryFactorVariableTreeNode(this);
|
---|
[14233] | 65 | }
|
---|
| 66 |
|
---|
| 67 | public override IDeepCloneable Clone(Cloner cloner) {
|
---|
[14243] | 68 | return new BinaryFactorVariable(this, cloner);
|
---|
[14233] | 69 | }
|
---|
| 70 |
|
---|
| 71 | public IEnumerable<string> GetVariableValues(string variableName) {
|
---|
| 72 | return variableValues[variableName];
|
---|
| 73 | }
|
---|
| 74 | }
|
---|
| 75 | }
|
---|