Free cookie consent management tool by TermsFeed Policy Generator

Ignore:
Timestamp:
01/28/13 17:54:46 (12 years ago)
Author:
sforsten
Message:

#1980:

  • added necessary interface ICondition, IAction, IInput
  • removed not used class MatchSelector and interface IMatchSelector
  • added constructors to ItemDictionary
  • added new encoding
File:
1 edited

Legend:

Unmodified
Added
Removed
  • branches/LearningClassifierSystems/HeuristicLab.Encodings.CombinedIntegerVectorEncoding/3.3/CombinedIntegerVector.cs

    r9175 r9194  
    2121
    2222using System;
     23using System.Collections.Generic;
    2324using System.Linq;
    2425using System.Text;
     
    3334  [StorableClass]
    3435  [Item("CombinedIntegerVector", "Represents a combined vector of integer values.")]
    35   public class CombinedIntegerVector : IntegerVector, IClassifier {
     36  public class CombinedIntegerVector : IntegerVector, IClassifier, ICondition, IAction, IInput {
    3637
    3738    [Storable]
     
    121122    }
    122123
    123     public IClassifier Condition {
     124    public ICondition Condition {
    124125      get {
    125126        int[] condition = new int[Length - actionLength];
     
    129130    }
    130131
    131     public IClassifier Action {
     132    public IAction Action {
    132133      get {
    133134        int[] action = new int[actionLength];
     
    152153    }
    153154
    154     public bool MatchCondition(IClassifier target) {
     155    public bool MatchInput(IInput target) {
    155156      var targetVector = target as CombinedIntegerVector;
    156157      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;
    158159
    159160      int curbounds;
     
    171172    }
    172173
     174    public bool MatchAction(IClassifier target) {
     175      return MatchAction(target.Action);
     176    }
     177
    173178    // no "don't care" symbols have to be considered
    174     public bool MatchAction(IClassifier target) {
     179    public bool MatchAction(IAction target) {
    175180      var targetVector = target as CombinedIntegerVector;
    176181      if (targetVector == null) return false;
     
    188193
    189194    public bool IsMoreGeneral(IClassifier target) {
     195      return IsMoreGeneral(target as ICondition);
     196    }
     197
     198    public bool IsMoreGeneral(ICondition target) {
    190199      var targetVector = target as CombinedIntegerVector;
    191200      int curbounds;
     
    201210      return true;
    202211    }
     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
    203224
    204225    private int NumberOfGeneralSymbols() {
     
    233254    }
    234255
    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;
    245258      if (cast == null) { return false; }
    246259      for (int i = 0; i < array.Length; i++) {
     
    252265    }
    253266
     267    public override bool Equals(object obj) {
     268      return base.Equals(obj);
     269    }
     270
    254271    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      }
    260316    }
    261317  }
Note: See TracChangeset for help on using the changeset viewer.