Changeset 9242 for branches/LearningClassifierSystems/HeuristicLab.Encodings.VariableVector/3.3/VariableVectorCondition.cs
- Timestamp:
- 02/25/13 12:37:18 (11 years ago)
- Location:
- branches/LearningClassifierSystems/HeuristicLab.Encodings.VariableVector/3.3
- Files:
-
- 2 edited
Legend:
- Unmodified
- Added
- Removed
-
branches/LearningClassifierSystems/HeuristicLab.Encodings.VariableVector/3.3
- Property svn:ignore
-
old new 1 1 obj 2 Plugin.cs
-
- Property svn:ignore
-
branches/LearningClassifierSystems/HeuristicLab.Encodings.VariableVector/3.3/VariableVectorCondition.cs
r9226 r9242 20 20 #endregion 21 21 22 using System;23 22 using System.Collections.Generic; 24 using System.Drawing;25 23 using System.Linq; 26 24 using System.Text; … … 33 31 [StorableClass] 34 32 [Item("VariableVectorCondition", "")] 35 public class VariableVectorCondition : Dictionary<string, IVariable>, ICondition {33 public class VariableVectorCondition : Item, ICondition { 36 34 37 public IOrderedEnumerable<string> Order { get { return this.Keys.OrderBy(x => x); } } 35 [Storable] 36 private Dictionary<string, IVariable> variableDictionary; 37 public Dictionary<string, IVariable> VariableDictionary { 38 get { return variableDictionary; } 39 protected set { variableDictionary = value; } 40 } 38 41 39 public int VirtualLength { get { return this.Values.Sum(x => x.VirtualLength); } } 42 public IOrderedEnumerable<string> Order { get { return VariableDictionary.Keys.OrderBy(x => x); } } 43 44 public int VirtualLength { get { return VariableDictionary.Values.Sum(x => x.VirtualLength); } } 40 45 41 46 [StorableConstructor] 42 47 protected VariableVectorCondition(bool deserializing) { } 43 48 protected VariableVectorCondition(VariableVectorCondition original, Cloner cloner) { 44 foreach (var item in original) { 45 Add((string)item.Key.Clone(), (IVariable)item.Value.Clone()); 49 VariableDictionary = new Dictionary<string, IVariable>(original.VariableDictionary.Count); 50 foreach (var item in original.VariableDictionary) { 51 VariableDictionary.Add(item.Key, cloner.Clone(item.Value)); 46 52 } 47 53 } 48 public VariableVectorCondition() : base() { } 49 public VariableVectorCondition(int capacity) : base(capacity) { } 50 public VariableVectorCondition(IDictionary<string, IVariable> dictionary) : base(dictionary) { } 54 public VariableVectorCondition() 55 : base() { 56 VariableDictionary = new Dictionary<string, IVariable>(); 57 } 58 public VariableVectorCondition(int capacity) 59 : base() { 60 VariableDictionary = new Dictionary<string, IVariable>(capacity); 61 } 62 public VariableVectorCondition(IDictionary<string, IVariable> dictionary) 63 : base() { 64 VariableDictionary = new Dictionary<string, IVariable>(dictionary); 65 } 66 public override IDeepCloneable Clone(Cloner cloner) { 67 return new VariableVectorCondition(this, cloner); 68 } 51 69 52 70 public bool Match(IInput target) { 53 71 var targetCast = target as VariableVectorInput; 54 72 if (targetCast == null) { return false; } 55 if (!this.Keys.All(x => targetCast.Keys.Contains(x))) { return false; } 56 foreach (var key in this.Keys) { 57 if (!this[key].MatchInput(targetCast[key])) { 73 foreach (var key in VariableDictionary.Keys) { 74 if (!targetCast.InputDictionary.ContainsKey(key) || !VariableDictionary[key].MatchInput(targetCast.InputDictionary[key])) { 58 75 return false; 59 76 } … … 64 81 public void Add(IEnumerable<IVariable> condition) { 65 82 foreach (var variable in condition) { 66 this.Add(variable.VariableName, variable);83 VariableDictionary.Add(variable.VariableName, variable); 67 84 } 68 85 } … … 71 88 StringBuilder sb = new StringBuilder(); 72 89 bool first = true; 73 foreach (var variable in this.Values) {90 foreach (var variable in VariableDictionary.Values) { 74 91 if (first) { 75 92 first = false; … … 83 100 84 101 public void Randomize(IRandom random, double spreadPercentage) { 85 foreach (var variable in this.Values) {102 foreach (var variable in VariableDictionary.Values) { 86 103 if (variable is DoubleVariable) { 87 104 ((DoubleVariable)variable).Randomize(random, spreadPercentage); … … 94 111 public bool Identical(VariableVectorCondition target) { 95 112 if (!this.Order.SequenceEqual(target.Order)) { return false; } 96 foreach (var keyValuePair in target ) {97 if (! this[keyValuePair.Key].Identical(keyValuePair.Value)) {113 foreach (var keyValuePair in target.VariableDictionary) { 114 if (!VariableDictionary[keyValuePair.Key].Identical(keyValuePair.Value)) { 98 115 return false; 99 116 } … … 101 118 return true; 102 119 } 103 104 public virtual string ItemName {105 get { return ItemAttribute.GetName(this.GetType()); }106 }107 public virtual string ItemDescription {108 get { return ItemAttribute.GetDescription(this.GetType()); }109 }110 public Version ItemVersion {111 get { return ItemAttribute.GetVersion(this.GetType()); }112 }113 public static Image StaticItemImage {114 get { return HeuristicLab.Common.Resources.VSImageLibrary.Class; }115 }116 public virtual Image ItemImage {117 get { return ItemAttribute.GetImage(this.GetType()); }118 }119 120 public virtual IDeepCloneable Clone(Cloner cloner) {121 return new VariableVectorCondition(this, cloner);122 }123 124 public object Clone() {125 return Clone(new Cloner());126 }127 128 public event EventHandler ItemImageChanged;129 protected virtual void OnItemImageChanged() {130 EventHandler handler = ItemImageChanged;131 if (handler != null) handler(this, EventArgs.Empty);132 }133 public event EventHandler ToStringChanged;134 protected virtual void OnToStringChanged() {135 EventHandler handler = ToStringChanged;136 if (handler != null) handler(this, EventArgs.Empty);137 }138 120 } 139 121 }
Note: See TracChangeset
for help on using the changeset viewer.