Changeset 9226 for branches/LearningClassifierSystems/HeuristicLab.Encodings.VariableVector/3.3/Variable
- Timestamp:
- 02/18/13 16:51:42 (12 years ago)
- Location:
- branches/LearningClassifierSystems
- Files:
-
- 7 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/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);
Note: See TracChangeset
for help on using the changeset viewer.