- Timestamp:
- 02/18/13 16:51:42 (12 years ago)
- Location:
- branches/LearningClassifierSystems
- Files:
-
- 1 added
- 18 edited
Legend:
- Unmodified
- Added
- Removed
-
branches/LearningClassifierSystems
- Property svn:ignore
-
old new 1 1 *.suo 2 bin
-
- Property svn:ignore
-
branches/LearningClassifierSystems/HeuristicLab.Encodings.VariableVector/3.3/Covering/VariableVectorCoveringCreator.cs
r9204 r9226 29 29 using HeuristicLab.Persistence.Default.CompositeSerializers.Storable; 30 30 31 namespace HeuristicLab.Encodings.VariableVector .Covering{31 namespace HeuristicLab.Encodings.VariableVector { 32 32 [Item("VariableVectorCoveringCreator", "Description missing")] 33 33 [StorableClass] … … 63 63 private IEnumerable<IVariable> CoverInput(VariableVectorInput input, VariableVectorCondition sample, IRandom random, double changeSymbolProbability) { 64 64 var conditionVariables = new List<IVariable>(); 65 if (! input.Order.SequenceEqual(sample.Order)) {66 throw new ArgumentException(" Sample and input do not contain the same variable names");65 if (!sample.Keys.All(x => input.ContainsKey(x))) { 66 throw new ArgumentException("Input does not contain all variable names from sample"); 67 67 } 68 68 foreach (var keyValuePair in sample) { 69 69 IVariable variable = keyValuePair.Value.GetEmptyCopy(); 70 variable.Cover(random, input[keyValuePair.Key] .Value, changeSymbolProbability);70 variable.Cover(random, input[keyValuePair.Key], changeSymbolProbability); 71 71 conditionVariables.Add(variable); 72 72 } -
branches/LearningClassifierSystems/HeuristicLab.Encodings.VariableVector/3.3/Creators/UniformRandomVariableVectorCreator.cs
r9194 r9226 20 20 #endregion 21 21 22 using System.Linq;23 22 using HeuristicLab.Common; 24 23 using HeuristicLab.Core; 25 24 using HeuristicLab.Persistence.Default.CompositeSerializers.Storable; 26 25 27 namespace HeuristicLab.Encodings.VariableVector .Creators{26 namespace HeuristicLab.Encodings.VariableVector { 28 27 [Item("UniformRandomVariableVectorCreator", "Description missing")] 29 28 [StorableClass] … … 46 45 47 46 protected override VariableVector Create(IRandom random, VariableVector sampleVariableVector, double spreadPercentage) { 48 var result = new VariableVector(sampleVariableVector.Condition.Values.Select(x => x.GetEmptyCopy()), sampleVariableVector.Action.Values.Select(x => x.GetEmptyCopy()));47 var result = sampleVariableVector.GetEmptyCopy(); 49 48 result.Randomize(random, spreadPercentage); 50 49 return result; -
branches/LearningClassifierSystems/HeuristicLab.Encodings.VariableVector/3.3/Crossover/SinglePointCrossover.cs
r9204 r9226 27 27 using HeuristicLab.Persistence.Default.CompositeSerializers.Storable; 28 28 29 namespace HeuristicLab.Encodings.VariableVector .Crossover{29 namespace HeuristicLab.Encodings.VariableVector { 30 30 [Item("SinglePointCrossover", "Description missing")] 31 31 [StorableClass] -
branches/LearningClassifierSystems/HeuristicLab.Encodings.VariableVector/3.3/HeuristicLab.Encodings.VariableVector-3.3.csproj
r9204 r9226 44 44 <HintPath>..\..\..\..\trunk\sources\bin\HeuristicLab.Common-3.3.dll</HintPath> 45 45 </Reference> 46 <Reference Include="HeuristicLab.Common.Resources-3.3, Version=3.3.0.0, Culture=neutral, PublicKeyToken=ba48961d6f65dcec, processorArchitecture=MSIL" /> 46 47 <Reference Include="HeuristicLab.Data-3.3"> 47 48 <HintPath>..\..\..\..\trunk\sources\bin\HeuristicLab.Data-3.3.dll</HintPath> … … 64 65 <Reference Include="System" /> 65 66 <Reference Include="System.Core" /> 67 <Reference Include="System.Drawing" /> 66 68 <Reference Include="System.Xml.Linq" /> 67 69 <Reference Include="System.Data.DataSetExtensions" /> … … 79 81 <Compile Include="Manipulator\UniformOnePositionInConditionManipulator.cs" /> 80 82 <Compile Include="Manipulator\UniformSomePositionManipulator.cs" /> 83 <Compile Include="VariableVectorActionComparer.cs" /> 81 84 <Compile Include="VariableVectorCrossover.cs" /> 82 85 <Compile Include="VariableVectorManipulator.cs" /> -
branches/LearningClassifierSystems/HeuristicLab.Encodings.VariableVector/3.3/Manipulator/UniformOnePositionInConditionManipulator.cs
r9204 r9226 56 56 var keyEnumerator = condition.Order.GetEnumerator(); 57 57 int count = 0; 58 while (keyEnumerator.MoveNext() && count < condition.VirtualLength59 && count < index && count + condition[keyEnumerator.Current].VirtualLength <index) {58 keyEnumerator.MoveNext(); 59 while (count < condition.VirtualLength && count < index && count + condition[keyEnumerator.Current].VirtualLength <= index) { 60 60 count += condition[keyEnumerator.Current].VirtualLength; 61 keyEnumerator.MoveNext(); 61 62 } 62 condition[keyEnumerator.Current].Manipulate(random, input[keyEnumerator.Current] .Value, index - count - 1);63 condition[keyEnumerator.Current].Manipulate(random, input[keyEnumerator.Current], index - count); 63 64 return child; 64 65 } -
branches/LearningClassifierSystems/HeuristicLab.Encodings.VariableVector/3.3/Plugin.cs
r9204 r9226 23 23 24 24 namespace HeuristicLab.Encodings.VariableVector { 25 [Plugin("HeuristicLab.Encodings.VariableVector", "3.3.7.9 194")]25 [Plugin("HeuristicLab.Encodings.VariableVector", "3.3.7.9204")] 26 26 [PluginFile("HeuristicLab.Encodings.VariableVector-3.3.dll", PluginFileType.Assembly)] 27 27 [PluginDependency("HeuristicLab.Common.Resources", "3.3")] -
branches/LearningClassifierSystems/HeuristicLab.Encodings.VariableVector/3.3/Properties/AssemblyInfo.cs
r9204 r9226 55 55 // [assembly: AssemblyVersion("1.0.*")] 56 56 [assembly: AssemblyVersion("3.3.0.0")] 57 [assembly: AssemblyFileVersion("3.3.7.9 194")]57 [assembly: AssemblyFileVersion("3.3.7.9204")] -
branches/LearningClassifierSystems/HeuristicLab.Encodings.VariableVector/3.3/Variable/DoubleVariable.cs
r9204 r9226 100 100 } 101 101 102 public new DoubleVariable GetEmptyCopy() {102 public override IVariable GetEmptyCopy() { 103 103 return new DoubleVariable(variableName, min, max); 104 104 } 105 public new DoubleVariable GetSetCopy() {106 DoubleVariable copy = GetEmptyCopy();105 public override IVariable GetSetCopy() { 106 DoubleVariable copy = (DoubleVariable)GetEmptyCopy(); 107 107 copy.CurrentCenter = this.CurrentCenter; 108 108 copy.CurrentSpread = this.CurrentSpread; … … 153 153 if (parent2Cast == null) { throw new ArgumentException("Argument is not of the correct type."); } 154 154 if (pos > 1 || pos < 0) { throw new ArgumentOutOfRangeException(); } 155 DoubleVariable crossed = this.GetSetCopy();155 DoubleVariable crossed = (DoubleVariable)this.GetSetCopy(); 156 156 if (pos == 0) { 157 157 crossed.CurrentSpread = parent2Cast.CurrentSpread; -
branches/LearningClassifierSystems/HeuristicLab.Encodings.VariableVector/3.3/Variable/IActionVariable.cs
r9194 r9226 20 20 #endregion 21 21 22 using System.Collections.Generic; 22 23 23 24 namespace HeuristicLab.Encodings.VariableVector { 24 25 // variables which can be used in the action 25 26 public interface IActionVariable : IVariable { 27 new IActionVariable GetEmptyCopy(); 28 new IActionVariable GetSetCopy(); 29 30 void SetTo(string value); 31 IEnumerable<string> GetAllPossibleActions(); 26 32 } 27 33 } -
branches/LearningClassifierSystems/HeuristicLab.Encodings.VariableVector/3.3/Variable/IVariable.cs
r9204 r9226 31 31 IVariable GetEmptyCopy(); 32 32 IVariable GetSetCopy(); 33 33 34 void Randomize(IRandom random); 34 35 bool MatchInput(string target); -
branches/LearningClassifierSystems/HeuristicLab.Encodings.VariableVector/3.3/Variable/IntVariable.cs
r9204 r9226 63 63 this.possibleFeatures = new List<int>(original.possibleFeatures); 64 64 this.Wildcard = original.Wildcard; 65 this.currentValue = original.currentValue; 65 66 } 66 67 public IntVariable() … … 70 71 public IntVariable(string variableName, IEnumerable<int> variableValues) 71 72 : base(variableName) { 72 if (variableValues.Count() != variableValues.Distinct().Count()) {73 throw new ArgumentException("variableValues have to be distinct .");73 if (variableValues.Count() > 0 && variableValues.Count() != variableValues.Distinct().Count()) { 74 throw new ArgumentException("variableValues have to be distinct and there has to be at least one value."); 74 75 } 75 76 possibleFeatures = variableValues; 76 77 Wildcard = false; 78 currentValue = possibleFeatures.First(); 77 79 } 78 80 public IntVariable(string variableName, IEnumerable<int> variableValues, int currentValue) … … 102 104 } 103 105 104 public new IntVariable GetEmptyCopy() {106 public override IVariable GetEmptyCopy() { 105 107 return new IntVariable(variableName, possibleFeatures); 106 108 } 107 public new IntVariable GetSetCopy() { 108 IntVariable copy = GetEmptyCopy(); 109 110 public override IVariable GetSetCopy() { 111 IntVariable copy = (IntVariable)GetEmptyCopy(); 109 112 copy.Wildcard = this.Wildcard; 110 113 copy.CurrentValue = this.CurrentValue; 111 114 return copy; 115 } 116 117 IActionVariable IActionVariable.GetEmptyCopy() { 118 return (IntVariable)GetEmptyCopy(); 119 } 120 IActionVariable IActionVariable.GetSetCopy() { 121 return (IntVariable)GetSetCopy(); 112 122 } 113 123 … … 143 153 if (parent2Cast == null) { throw new ArgumentException("Argument is not of the correct type."); } 144 154 if (pos != 0) { throw new ArgumentOutOfRangeException(); } 145 return this.GetSetCopy();155 return (IntVariable)this.GetSetCopy(); 146 156 } 147 157 … … 160 170 } 161 171 } 172 173 public override int GetHashCode() { 174 int result = 1; 175 int wildcardInt = Wildcard ? 1 : 0; 176 result = 37 * result + wildcardInt; 177 result = 37 * result + currentValue; 178 foreach (var feature in possibleFeatures) { 179 result = 37 * result + feature; 180 } 181 return result; 182 } 183 184 #region IActionVariable Members 185 public void SetTo(string value) { 186 currentValue = int.Parse(value); 187 } 188 189 public IEnumerable<string> GetAllPossibleActions() { 190 return possibleFeatures.Select(x => x.ToString()); 191 } 192 #endregion 162 193 } 163 194 } -
branches/LearningClassifierSystems/HeuristicLab.Encodings.VariableVector/3.3/Variable/StringVariable.cs
r9204 r9226 74 74 this.featureMapping = new Dictionary<int, string>(original.featureMapping); 75 75 this.Wildcard = original.Wildcard; 76 this.currentValue = original.currentValue; 76 77 } 77 78 public StringVariable() … … 150 151 } 151 152 152 public new StringVariable GetEmptyCopy() {153 public override IVariable GetEmptyCopy() { 153 154 return new StringVariable(variableName, featureMapping); 154 155 } 155 public new StringVariable GetSetCopy() {156 StringVariable copy = GetEmptyCopy();156 public override IVariable GetSetCopy() { 157 StringVariable copy = (StringVariable)GetEmptyCopy(); 157 158 copy.Wildcard = this.Wildcard; 158 159 copy.CurrentValue = this.CurrentValue; 159 160 return copy; 161 } 162 IActionVariable IActionVariable.GetEmptyCopy() { 163 return (StringVariable)GetEmptyCopy(); 164 } 165 IActionVariable IActionVariable.GetSetCopy() { 166 return (StringVariable)GetSetCopy(); 160 167 } 161 168 … … 195 202 if (parent2Cast == null) { throw new ArgumentException("Argument is not of the correct type."); } 196 203 if (pos != 0) { throw new ArgumentOutOfRangeException(); } 197 return this.GetSetCopy();204 return (StringVariable)this.GetSetCopy(); 198 205 } 199 206 … … 202 209 Wildcard = !Wildcard; 203 210 if (!Wildcard) { 204 int newValue = featureMapping.First(x => x.Value.Equals(stringValue)).Key; 205 currentValue = newValue; 211 currentValue = featureMapping.First(x => x.Value.Equals(stringValue)).Key; 206 212 } 207 213 } … … 210 216 Wildcard = random.NextDouble() < changeSymbolProbability; 211 217 if (!Wildcard) { 212 int newValue = featureMapping.First(x => x.Value.Equals(stringValue)).Key; 213 currentValue = newValue; 214 } 215 } 218 currentValue = featureMapping.First(x => x.Value.Equals(stringValue)).Key; 219 } 220 } 221 222 public override int GetHashCode() { 223 int result = 1; 224 int wildcardInt = Wildcard ? 1 : 0; 225 result = 37 * result + wildcardInt; 226 result = 37 * result + currentValue; 227 foreach (var feature in featureMapping) { 228 result = 37 * result + feature.Key; 229 result = 37 * result + feature.Value.GetHashCode(); 230 } 231 return result; 232 } 233 234 #region IActionVariable Members 235 public void SetTo(string value) { 236 currentValue = featureMapping.First(x => x.Value.Equals(value)).Key; 237 } 238 239 public IEnumerable<string> GetAllPossibleActions() { 240 return featureMapping.Values; 241 } 242 #endregion 216 243 } 217 244 } -
branches/LearningClassifierSystems/HeuristicLab.Encodings.VariableVector/3.3/Variable/Variable.cs
r9204 r9226 52 52 } 53 53 54 public virtual IVariable GetEmptyCopy() { throw new NotSupportedException("This method is not supported. It should be implemented by every non abstract class."); }55 public virtual IVariable GetSetCopy() { throw new NotSupportedException("This method is not supported. It should be implemented by every non abstract class."); }54 public abstract IVariable GetEmptyCopy(); 55 public abstract IVariable GetSetCopy(); 56 56 57 57 public abstract void Randomize(IRandom random); -
branches/LearningClassifierSystems/HeuristicLab.Encodings.VariableVector/3.3/VariableVector.cs
r9204 r9226 54 54 protected VariableVector(VariableVector original, Cloner cloner) 55 55 : base(original, cloner) { 56 condition = new VariableVectorCondition(original.condition);57 action = new VariableVectorAction(original.action);56 condition = (VariableVectorCondition)original.condition.Clone(); 57 action = (VariableVectorAction)original.action; 58 58 } 59 59 public VariableVector() { … … 64 64 : this() { 65 65 if (condition == null || action == null) { throw new ArgumentNullException(); } 66 if ( action.All(x => x is IActionVariable)) { throw new ArgumentException("Action can only use IActionVariable"); }66 if (!action.All(x => x is IActionVariable)) { throw new ArgumentException("Action can only use IActionVariable"); } 67 67 this.Condition.Add(condition); 68 68 this.Action.Add(action.Cast<IActionVariable>()); … … 70 70 public override IDeepCloneable Clone(Cloner cloner) { 71 71 return new VariableVector(this, cloner); 72 } 73 74 public VariableVector GetEmptyCopy() { 75 return new VariableVector(Condition.Values.Select(x => x.GetEmptyCopy()), Action.Values.Select(x => x.GetEmptyCopy())); 72 76 } 73 77 … … 128 132 var targetCast = target as VariableVector; 129 133 if (targetCast == null) { return false; } 130 if (!condition.Identical(targetCast. condition)) { return false; }131 if (!action.Identical(targetCast. condition)) { return false; }134 if (!condition.Identical(targetCast.Condition)) { return false; } 135 if (!action.Identical(targetCast.Action)) { return false; } 132 136 return true; 133 }134 135 [StorableClass]136 [Item("VariableVectorActionComparer", "")]137 public class VariableVectorActionComparer : Item, IEqualityComparer<VariableVectorAction>, IClassifierComparer {138 139 [StorableConstructor]140 protected VariableVectorActionComparer(bool deserializing) : base(deserializing) { }141 protected VariableVectorActionComparer(VariableVectorActionComparer original, Cloner cloner)142 : base(original, cloner) {143 }144 public override IDeepCloneable Clone(Cloner cloner) {145 return new VariableVectorActionComparer(this, cloner);146 }147 public VariableVectorActionComparer() : base() { }148 149 public bool Equals(VariableVectorAction x, VariableVectorAction y) {150 throw new NotImplementedException();151 }152 153 public int GetHashCode(VariableVectorAction obj) {154 throw new NotImplementedException();155 }156 157 public bool Equals(IAction x, IAction y) {158 var xCast = x as VariableVectorAction;159 var yCast = y as VariableVectorAction;160 return x != null && y != null && Equals(xCast, yCast);161 }162 163 public int GetHashCode(IAction obj) {164 var objCast = obj as VariableVectorAction;165 return objCast != null ? GetHashCode(objCast) : obj.GetHashCode();166 }167 137 } 168 138 } -
branches/LearningClassifierSystems/HeuristicLab.Encodings.VariableVector/3.3/VariableVectorAction.cs
r9204 r9226 22 22 using System; 23 23 using System.Collections.Generic; 24 using System.Drawing; 24 25 using System.Linq; 25 26 using System.Text; 26 27 using HeuristicLab.Common; 27 28 using HeuristicLab.Core; 28 using HeuristicLab.Data;29 29 using HeuristicLab.Encodings.ConditionActionEncoding; 30 30 using HeuristicLab.Persistence.Default.CompositeSerializers.Storable; … … 33 33 [StorableClass] 34 34 [Item("VariableVectorAction", "")] 35 public class VariableVectorAction : ItemDictionary<StringValue, IActionVariable>, IAction {35 public class VariableVectorAction : Dictionary<string, IActionVariable>, IAction { 36 36 37 public IOrderedEnumerable< StringValue> Order { get { return this.Keys.OrderBy(x => x.Value); } }37 public IOrderedEnumerable<string> Order { get { return this.Keys.OrderBy(x => x); } } 38 38 39 39 public int VirtualLength { get { return this.Values.Sum(x => x.VirtualLength); } } 40 40 41 41 [StorableConstructor] 42 protected VariableVectorAction(bool deserializing) : base(deserializing) { } 43 protected VariableVectorAction(VariableVectorAction original, Cloner cloner) 44 : base(original, cloner) { 42 protected VariableVectorAction(bool deserializing) { } 43 protected VariableVectorAction(VariableVectorAction original, Cloner cloner) { 44 foreach (var item in original) { 45 Add((string)item.Key.Clone(), (IActionVariable)item.Value.Clone()); 46 } 45 47 } 46 48 public VariableVectorAction() : base() { } 47 49 public VariableVectorAction(int capacity) : base(capacity) { } 48 public VariableVectorAction(IDictionary<StringValue, IActionVariable> dictionary) : base(dictionary) { } 49 public override IDeepCloneable Clone(Cloner cloner) { 50 return new VariableVectorAction(this, cloner); 50 public VariableVectorAction(IDictionary<string, IActionVariable> dictionary) : base(dictionary) { } 51 52 //protected override void OnItemsAdded(IEnumerable<KeyValuePair<string, IActionVariable>> items) { 53 // foreach (var item in items) { 54 // if (!(item.Value is StringVariable || item.Value is IntVariable)) { 55 // throw new ArgumentException("Value has to be of type 'StringVariable' or 'IntVariable'"); 56 // } 57 // } 58 //} 59 60 public VariableVectorAction GetEmptyCopy() { 61 VariableVectorAction emptyCopy = new VariableVectorAction(this.Count); 62 foreach (var keyValuePair in this) { 63 emptyCopy.Add(keyValuePair.Key, keyValuePair.Value.GetEmptyCopy()); 64 } 65 return emptyCopy; 51 66 } 52 67 53 protected override void OnItemsAdded(IEnumerable<KeyValuePair<StringValue, IActionVariable>> items) { 54 foreach (var item in items) { 55 if (!(item.Value is StringVariable || item.Value is IntVariable)) { 56 throw new ArgumentException("Value has to be of type 'StringVariable' or 'IntVariable'"); 57 } 68 public VariableVectorAction GetSetCopy() { 69 VariableVectorAction setCopy = new VariableVectorAction(this.Count); 70 foreach (var keyValuePair in this) { 71 setCopy.Add(keyValuePair.Key, keyValuePair.Value.GetSetCopy()); 58 72 } 59 base.OnItemsAdded(items);73 return setCopy; 60 74 } 61 75 … … 63 77 var targetCast = target as VariableVectorAction; 64 78 if (targetCast == null) { return false; } 65 if ( this.Order.SequenceEqual(targetCast.Order)) { return false; }79 if (!this.Order.SequenceEqual(targetCast.Order)) { return false; } 66 80 foreach (var keyValuePair in targetCast) { 67 81 if (!this[keyValuePair.Key].MatchVariable(keyValuePair.Value)) { … … 74 88 public void Add(IEnumerable<IActionVariable> action) { 75 89 foreach (var variable in action) { 76 this.Add( new StringValue(variable.VariableName), variable);90 this.Add(variable.VariableName, variable); 77 91 } 78 92 } … … 82 96 bool first = true; 83 97 foreach (var variable in this.Values) { 84 if ( !first) {98 if (first) { 85 99 first = false; 86 100 } else { … … 98 112 } 99 113 100 public bool Identical(VariableVector Condition target) {114 public bool Identical(VariableVectorAction target) { 101 115 if (this.Order.SequenceEqual(target.Order)) { return false; } 102 116 foreach (var keyValuePair in target) { … … 107 121 return true; 108 122 } 123 124 public virtual string ItemName { 125 get { return ItemAttribute.GetName(this.GetType()); } 126 } 127 public virtual string ItemDescription { 128 get { return ItemAttribute.GetDescription(this.GetType()); } 129 } 130 public Version ItemVersion { 131 get { return ItemAttribute.GetVersion(this.GetType()); } 132 } 133 public static Image StaticItemImage { 134 get { return HeuristicLab.Common.Resources.VSImageLibrary.Class; } 135 } 136 public virtual Image ItemImage { 137 get { return ItemAttribute.GetImage(this.GetType()); } 138 } 139 140 public virtual IDeepCloneable Clone(Cloner cloner) { 141 return new VariableVectorAction(this, cloner); 142 } 143 144 public object Clone() { 145 return Clone(new Cloner()); 146 } 147 148 public event EventHandler ItemImageChanged; 149 protected virtual void OnItemImageChanged() { 150 EventHandler handler = ItemImageChanged; 151 if (handler != null) handler(this, EventArgs.Empty); 152 } 153 public event EventHandler ToStringChanged; 154 protected virtual void OnToStringChanged() { 155 EventHandler handler = ToStringChanged; 156 if (handler != null) handler(this, EventArgs.Empty); 157 } 109 158 } 110 159 } -
branches/LearningClassifierSystems/HeuristicLab.Encodings.VariableVector/3.3/VariableVectorCondition.cs
r9204 r9226 20 20 #endregion 21 21 22 using System; 22 23 using System.Collections.Generic; 24 using System.Drawing; 23 25 using System.Linq; 24 26 using System.Text; 25 27 using HeuristicLab.Common; 26 28 using HeuristicLab.Core; 27 using HeuristicLab.Data;28 29 using HeuristicLab.Encodings.ConditionActionEncoding; 29 30 using HeuristicLab.Persistence.Default.CompositeSerializers.Storable; … … 32 33 [StorableClass] 33 34 [Item("VariableVectorCondition", "")] 34 public class VariableVectorCondition : ItemDictionary<StringValue, IVariable>, ICondition {35 public class VariableVectorCondition : Dictionary<string, IVariable>, ICondition { 35 36 36 public IOrderedEnumerable< StringValue> Order { get { return this.Keys.OrderBy(x => x.Value); } }37 public IOrderedEnumerable<string> Order { get { return this.Keys.OrderBy(x => x); } } 37 38 38 39 public int VirtualLength { get { return this.Values.Sum(x => x.VirtualLength); } } 39 40 40 41 [StorableConstructor] 41 protected VariableVectorCondition(bool deserializing) : base(deserializing) { } 42 protected VariableVectorCondition(VariableVectorCondition original, Cloner cloner) 43 : base(original, cloner) { 42 protected VariableVectorCondition(bool deserializing) { } 43 protected VariableVectorCondition(VariableVectorCondition original, Cloner cloner) { 44 foreach (var item in original) { 45 Add((string)item.Key.Clone(), (IVariable)item.Value.Clone()); 46 } 44 47 } 45 48 public VariableVectorCondition() : base() { } 46 49 public VariableVectorCondition(int capacity) : base(capacity) { } 47 public VariableVectorCondition(IDictionary<StringValue, IVariable> dictionary) : base(dictionary) { } 48 public override IDeepCloneable Clone(Cloner cloner) { 49 return new VariableVectorCondition(this, cloner); 50 } 50 public VariableVectorCondition(IDictionary<string, IVariable> dictionary) : base(dictionary) { } 51 51 52 52 public bool Match(IInput target) { 53 53 var targetCast = target as VariableVectorInput; 54 54 if (targetCast == null) { return false; } 55 if ( this.Order.SequenceEqual(targetCast.Order)) { return false; }56 foreach (var key ValuePair in targetCast) {57 if (!this[key ValuePair.Key].MatchInput(keyValuePair.Value.Value)) {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])) { 58 58 return false; 59 59 } … … 64 64 public void Add(IEnumerable<IVariable> condition) { 65 65 foreach (var variable in condition) { 66 this.Add( new StringValue(variable.VariableName), variable);66 this.Add(variable.VariableName, variable); 67 67 } 68 68 } … … 72 72 bool first = true; 73 73 foreach (var variable in this.Values) { 74 if ( !first) {74 if (first) { 75 75 first = false; 76 76 } else { … … 93 93 94 94 public bool Identical(VariableVectorCondition target) { 95 if ( this.Order.SequenceEqual(target.Order)) { return false; }95 if (!this.Order.SequenceEqual(target.Order)) { return false; } 96 96 foreach (var keyValuePair in target) { 97 97 if (!this[keyValuePair.Key].Identical(keyValuePair.Value)) { … … 101 101 return true; 102 102 } 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 } 103 138 } 104 139 } -
branches/LearningClassifierSystems/HeuristicLab.Encodings.VariableVector/3.3/VariableVectorInput.cs
r9204 r9226 20 20 #endregion 21 21 22 using System; 22 23 using System.Collections.Generic; 24 using System.Drawing; 23 25 using System.Linq; 26 using System.Text; 24 27 using HeuristicLab.Common; 25 28 using HeuristicLab.Core; 26 using HeuristicLab.Data;27 29 using HeuristicLab.Encodings.ConditionActionEncoding; 28 30 using HeuristicLab.Persistence.Default.CompositeSerializers.Storable; … … 31 33 [StorableClass] 32 34 [Item("VariableVectorInput", "")] 33 public class VariableVectorInput : ItemDictionary<StringValue, StringValue>, IInput {35 public class VariableVectorInput : Dictionary<string, string>, IInput { 34 36 35 public IOrderedEnumerable< StringValue> Order { get { return this.Keys.OrderBy(x => x.Value); } }37 public IOrderedEnumerable<string> Order { get { return this.Keys.OrderBy(x => x); } } 36 38 37 39 [StorableConstructor] 38 protected VariableVectorInput(bool deserializing) : base(deserializing) { } 39 protected VariableVectorInput(VariableVectorInput original, Cloner cloner) 40 : base(original, cloner) { 40 protected VariableVectorInput(bool deserializing) { } 41 protected VariableVectorInput(VariableVectorInput original, Cloner cloner) { 42 foreach (var item in original) { 43 Add((string)item.Key.Clone(), (string)item.Value.Clone()); 44 } 41 45 } 42 46 public VariableVectorInput() : base() { } 43 47 public VariableVectorInput(int capacity) : base(capacity) { } 44 public VariableVectorInput(IDictionary<StringValue, StringValue> dictionary) : base(dictionary) { } 45 public override IDeepCloneable Clone(Cloner cloner) { 48 public VariableVectorInput(IDictionary<string, string> dictionary) : base(dictionary) { } 49 50 public override string ToString() { 51 StringBuilder sb = new StringBuilder(); 52 bool first = true; 53 foreach (var item in this) { 54 if (first) { 55 first = false; 56 } else { 57 sb.Append("; "); 58 } 59 sb.Append(String.Format("{0}: {1}", item.Key, item.Value)); 60 } 61 return sb.ToString(); 62 } 63 64 public virtual string ItemName { 65 get { return ItemAttribute.GetName(this.GetType()); } 66 } 67 public virtual string ItemDescription { 68 get { return ItemAttribute.GetDescription(this.GetType()); } 69 } 70 public Version ItemVersion { 71 get { return ItemAttribute.GetVersion(this.GetType()); } 72 } 73 public static Image StaticItemImage { 74 get { return HeuristicLab.Common.Resources.VSImageLibrary.Class; } 75 } 76 public virtual Image ItemImage { 77 get { return ItemAttribute.GetImage(this.GetType()); } 78 } 79 80 public virtual IDeepCloneable Clone(Cloner cloner) { 46 81 return new VariableVectorInput(this, cloner); 82 } 83 84 public object Clone() { 85 return Clone(new Cloner()); 86 } 87 88 public event EventHandler ItemImageChanged; 89 protected virtual void OnItemImageChanged() { 90 EventHandler handler = ItemImageChanged; 91 if (handler != null) handler(this, EventArgs.Empty); 92 } 93 public event EventHandler ToStringChanged; 94 protected virtual void OnToStringChanged() { 95 EventHandler handler = ToStringChanged; 96 if (handler != null) handler(this, EventArgs.Empty); 47 97 } 48 98 }
Note: See TracChangeset
for help on using the changeset viewer.