Changeset 9194 for branches/LearningClassifierSystems/HeuristicLab.Encodings.CombinedIntegerVectorEncoding/3.3/CombinedIntegerVector.cs
- Timestamp:
- 01/28/13 17:54:46 (12 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
branches/LearningClassifierSystems/HeuristicLab.Encodings.CombinedIntegerVectorEncoding/3.3/CombinedIntegerVector.cs
r9175 r9194 21 21 22 22 using System; 23 using System.Collections.Generic; 23 24 using System.Linq; 24 25 using System.Text; … … 33 34 [StorableClass] 34 35 [Item("CombinedIntegerVector", "Represents a combined vector of integer values.")] 35 public class CombinedIntegerVector : IntegerVector, IClassifier {36 public class CombinedIntegerVector : IntegerVector, IClassifier, ICondition, IAction, IInput { 36 37 37 38 [Storable] … … 121 122 } 122 123 123 public IC lassifierCondition {124 public ICondition Condition { 124 125 get { 125 126 int[] condition = new int[Length - actionLength]; … … 129 130 } 130 131 131 public I ClassifierAction {132 public IAction Action { 132 133 get { 133 134 int[] action = new int[actionLength]; … … 152 153 } 153 154 154 public bool Match Condition(IClassifiertarget) {155 public bool MatchInput(IInput target) { 155 156 var targetVector = target as CombinedIntegerVector; 156 157 if (targetVector == null) return false; 157 if (targetVector.Length != this.Length) return false;158 if (targetVector.Length - targetVector.actionLength != this.Length - this.actionLength) return false; 158 159 159 160 int curbounds; … … 171 172 } 172 173 174 public bool MatchAction(IClassifier target) { 175 return MatchAction(target.Action); 176 } 177 173 178 // no "don't care" symbols have to be considered 174 public bool MatchAction(I Classifiertarget) {179 public bool MatchAction(IAction target) { 175 180 var targetVector = target as CombinedIntegerVector; 176 181 if (targetVector == null) return false; … … 188 193 189 194 public bool IsMoreGeneral(IClassifier target) { 195 return IsMoreGeneral(target as ICondition); 196 } 197 198 public bool IsMoreGeneral(ICondition target) { 190 199 var targetVector = target as CombinedIntegerVector; 191 200 int curbounds; … … 201 210 return true; 202 211 } 212 213 #region ICondition Members 214 public bool Match(IInput target) { 215 return MatchInput(target); 216 } 217 #endregion 218 219 #region IAction Members 220 public bool Match(IAction target) { 221 return MatchAction(target); 222 } 223 #endregion 203 224 204 225 private int NumberOfGeneralSymbols() { … … 233 254 } 234 255 235 public override bool Equals(object obj) { 236 var cast = obj as CombinedIntegerVector; 237 if (cast != null) { 238 return this.Equals(cast); 239 } 240 return false; 241 } 242 243 public bool Equals(IClassifier other) { 244 var cast = other as CombinedIntegerVector; 256 public bool Identical(IClassifier target) { 257 var cast = target as CombinedIntegerVector; 245 258 if (cast == null) { return false; } 246 259 for (int i = 0; i < array.Length; i++) { … … 252 265 } 253 266 267 public override bool Equals(object obj) { 268 return base.Equals(obj); 269 } 270 254 271 public override int GetHashCode() { 255 int result = actionLength; 256 for (int i = 0; i < array.Length; i++) { 257 result ^= array[i]; 258 } 259 return result.GetHashCode(); 272 return base.GetHashCode(); 273 } 274 275 [StorableClass] 276 [Item("CombinedIntegerVectorComparer", "")] 277 public class CombinedIntegerVectorComparer : Item, IEqualityComparer<CombinedIntegerVector>, IClassifierComparer { 278 279 [StorableConstructor] 280 protected CombinedIntegerVectorComparer(bool deserializing) : base(deserializing) { } 281 protected CombinedIntegerVectorComparer(CombinedIntegerVectorComparer original, Cloner cloner) 282 : base(original, cloner) { 283 } 284 public override IDeepCloneable Clone(Cloner cloner) { 285 return new CombinedIntegerVectorComparer(this, cloner); 286 } 287 public CombinedIntegerVectorComparer() : base() { } 288 289 public bool Equals(CombinedIntegerVector x, CombinedIntegerVector y) { 290 for (int i = 0; i < x.array.Length; i++) { 291 if (!x.array[i].Equals(y.array[i])) { 292 return false; 293 } 294 } 295 return true; 296 } 297 298 public int GetHashCode(CombinedIntegerVector obj) { 299 int result = obj.actionLength; 300 for (int i = 0; i < obj.array.Length; i++) { 301 result ^= obj.array[i]; 302 } 303 return result.GetHashCode(); 304 } 305 306 public bool Equals(IAction x, IAction y) { 307 var xCast = x as CombinedIntegerVector; 308 var yCast = y as CombinedIntegerVector; 309 return x != null && y != null && Equals(xCast, yCast); 310 } 311 312 public int GetHashCode(IAction obj) { 313 var objCast = obj as CombinedIntegerVector; 314 return objCast != null ? GetHashCode(objCast) : obj.GetHashCode(); 315 } 260 316 } 261 317 }
Note: See TracChangeset
for help on using the changeset viewer.