Free cookie consent management tool by TermsFeed Policy Generator

Ignore:
Timestamp:
02/18/13 16:51:42 (12 years ago)
Author:
sforsten
Message:

#1980:

  • made classes in Problems.ConditionActionClassification abstract
  • added Problems.VariableVectorClassification and Problems.CombinedIntegerVectorClassification
  • LCS works now with arbitrary problems, which implement ConditionActionClassificationProblem
Location:
branches/LearningClassifierSystems
Files:
1 added
18 edited

Legend:

Unmodified
Added
Removed
  • branches/LearningClassifierSystems

    • Property svn:ignore
      •  

        old new  
        11*.suo
         2bin
  • branches/LearningClassifierSystems/HeuristicLab.Encodings.VariableVector/3.3/Covering/VariableVectorCoveringCreator.cs

    r9204 r9226  
    2929using HeuristicLab.Persistence.Default.CompositeSerializers.Storable;
    3030
    31 namespace HeuristicLab.Encodings.VariableVector.Covering {
     31namespace HeuristicLab.Encodings.VariableVector {
    3232  [Item("VariableVectorCoveringCreator", "Description missing")]
    3333  [StorableClass]
     
    6363    private IEnumerable<IVariable> CoverInput(VariableVectorInput input, VariableVectorCondition sample, IRandom random, double changeSymbolProbability) {
    6464      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");
    6767      }
    6868      foreach (var keyValuePair in sample) {
    6969        IVariable variable = keyValuePair.Value.GetEmptyCopy();
    70         variable.Cover(random, input[keyValuePair.Key].Value, changeSymbolProbability);
     70        variable.Cover(random, input[keyValuePair.Key], changeSymbolProbability);
    7171        conditionVariables.Add(variable);
    7272      }
  • branches/LearningClassifierSystems/HeuristicLab.Encodings.VariableVector/3.3/Creators/UniformRandomVariableVectorCreator.cs

    r9194 r9226  
    2020#endregion
    2121
    22 using System.Linq;
    2322using HeuristicLab.Common;
    2423using HeuristicLab.Core;
    2524using HeuristicLab.Persistence.Default.CompositeSerializers.Storable;
    2625
    27 namespace HeuristicLab.Encodings.VariableVector.Creators {
     26namespace HeuristicLab.Encodings.VariableVector {
    2827  [Item("UniformRandomVariableVectorCreator", "Description missing")]
    2928  [StorableClass]
     
    4645
    4746    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();
    4948      result.Randomize(random, spreadPercentage);
    5049      return result;
  • branches/LearningClassifierSystems/HeuristicLab.Encodings.VariableVector/3.3/Crossover/SinglePointCrossover.cs

    r9204 r9226  
    2727using HeuristicLab.Persistence.Default.CompositeSerializers.Storable;
    2828
    29 namespace HeuristicLab.Encodings.VariableVector.Crossover {
     29namespace HeuristicLab.Encodings.VariableVector {
    3030  [Item("SinglePointCrossover", "Description missing")]
    3131  [StorableClass]
  • branches/LearningClassifierSystems/HeuristicLab.Encodings.VariableVector/3.3/HeuristicLab.Encodings.VariableVector-3.3.csproj

    r9204 r9226  
    4444      <HintPath>..\..\..\..\trunk\sources\bin\HeuristicLab.Common-3.3.dll</HintPath>
    4545    </Reference>
     46    <Reference Include="HeuristicLab.Common.Resources-3.3, Version=3.3.0.0, Culture=neutral, PublicKeyToken=ba48961d6f65dcec, processorArchitecture=MSIL" />
    4647    <Reference Include="HeuristicLab.Data-3.3">
    4748      <HintPath>..\..\..\..\trunk\sources\bin\HeuristicLab.Data-3.3.dll</HintPath>
     
    6465    <Reference Include="System" />
    6566    <Reference Include="System.Core" />
     67    <Reference Include="System.Drawing" />
    6668    <Reference Include="System.Xml.Linq" />
    6769    <Reference Include="System.Data.DataSetExtensions" />
     
    7981    <Compile Include="Manipulator\UniformOnePositionInConditionManipulator.cs" />
    8082    <Compile Include="Manipulator\UniformSomePositionManipulator.cs" />
     83    <Compile Include="VariableVectorActionComparer.cs" />
    8184    <Compile Include="VariableVectorCrossover.cs" />
    8285    <Compile Include="VariableVectorManipulator.cs" />
  • branches/LearningClassifierSystems/HeuristicLab.Encodings.VariableVector/3.3/Manipulator/UniformOnePositionInConditionManipulator.cs

    r9204 r9226  
    5656      var keyEnumerator = condition.Order.GetEnumerator();
    5757      int count = 0;
    58       while (keyEnumerator.MoveNext() && count < condition.VirtualLength
    59         && count < index && count + condition[keyEnumerator.Current].VirtualLength < index) {
     58      keyEnumerator.MoveNext();
     59      while (count < condition.VirtualLength && count < index && count + condition[keyEnumerator.Current].VirtualLength <= index) {
    6060        count += condition[keyEnumerator.Current].VirtualLength;
     61        keyEnumerator.MoveNext();
    6162      }
    62       condition[keyEnumerator.Current].Manipulate(random, input[keyEnumerator.Current].Value, index - count - 1);
     63      condition[keyEnumerator.Current].Manipulate(random, input[keyEnumerator.Current], index - count);
    6364      return child;
    6465    }
  • branches/LearningClassifierSystems/HeuristicLab.Encodings.VariableVector/3.3/Plugin.cs

    r9204 r9226  
    2323
    2424namespace HeuristicLab.Encodings.VariableVector {
    25   [Plugin("HeuristicLab.Encodings.VariableVector", "3.3.7.9194")]
     25  [Plugin("HeuristicLab.Encodings.VariableVector", "3.3.7.9204")]
    2626  [PluginFile("HeuristicLab.Encodings.VariableVector-3.3.dll", PluginFileType.Assembly)]
    2727  [PluginDependency("HeuristicLab.Common.Resources", "3.3")]
  • branches/LearningClassifierSystems/HeuristicLab.Encodings.VariableVector/3.3/Properties/AssemblyInfo.cs

    r9204 r9226  
    5555// [assembly: AssemblyVersion("1.0.*")]
    5656[assembly: AssemblyVersion("3.3.0.0")]
    57 [assembly: AssemblyFileVersion("3.3.7.9194")]
     57[assembly: AssemblyFileVersion("3.3.7.9204")]
  • branches/LearningClassifierSystems/HeuristicLab.Encodings.VariableVector/3.3/Variable/DoubleVariable.cs

    r9204 r9226  
    100100    }
    101101
    102     public new DoubleVariable GetEmptyCopy() {
     102    public override IVariable GetEmptyCopy() {
    103103      return new DoubleVariable(variableName, min, max);
    104104    }
    105     public new DoubleVariable GetSetCopy() {
    106       DoubleVariable copy = GetEmptyCopy();
     105    public override IVariable GetSetCopy() {
     106      DoubleVariable copy = (DoubleVariable)GetEmptyCopy();
    107107      copy.CurrentCenter = this.CurrentCenter;
    108108      copy.CurrentSpread = this.CurrentSpread;
     
    153153      if (parent2Cast == null) { throw new ArgumentException("Argument is not of the correct type."); }
    154154      if (pos > 1 || pos < 0) { throw new ArgumentOutOfRangeException(); }
    155       DoubleVariable crossed = this.GetSetCopy();
     155      DoubleVariable crossed = (DoubleVariable)this.GetSetCopy();
    156156      if (pos == 0) {
    157157        crossed.CurrentSpread = parent2Cast.CurrentSpread;
  • branches/LearningClassifierSystems/HeuristicLab.Encodings.VariableVector/3.3/Variable/IActionVariable.cs

    r9194 r9226  
    2020#endregion
    2121
     22using System.Collections.Generic;
    2223
    2324namespace HeuristicLab.Encodings.VariableVector {
    2425  // variables which can be used in the action
    2526  public interface IActionVariable : IVariable {
     27    new IActionVariable GetEmptyCopy();
     28    new IActionVariable GetSetCopy();
     29
     30    void SetTo(string value);
     31    IEnumerable<string> GetAllPossibleActions();
    2632  }
    2733}
  • branches/LearningClassifierSystems/HeuristicLab.Encodings.VariableVector/3.3/Variable/IVariable.cs

    r9204 r9226  
    3131    IVariable GetEmptyCopy();
    3232    IVariable GetSetCopy();
     33
    3334    void Randomize(IRandom random);
    3435    bool MatchInput(string target);
  • branches/LearningClassifierSystems/HeuristicLab.Encodings.VariableVector/3.3/Variable/IntVariable.cs

    r9204 r9226  
    6363      this.possibleFeatures = new List<int>(original.possibleFeatures);
    6464      this.Wildcard = original.Wildcard;
     65      this.currentValue = original.currentValue;
    6566    }
    6667    public IntVariable()
     
    7071    public IntVariable(string variableName, IEnumerable<int> variableValues)
    7172      : 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.");
    7475      }
    7576      possibleFeatures = variableValues;
    7677      Wildcard = false;
     78      currentValue = possibleFeatures.First();
    7779    }
    7880    public IntVariable(string variableName, IEnumerable<int> variableValues, int currentValue)
     
    102104    }
    103105
    104     public new IntVariable GetEmptyCopy() {
     106    public override IVariable GetEmptyCopy() {
    105107      return new IntVariable(variableName, possibleFeatures);
    106108    }
    107     public new IntVariable GetSetCopy() {
    108       IntVariable copy = GetEmptyCopy();
     109
     110    public override IVariable GetSetCopy() {
     111      IntVariable copy = (IntVariable)GetEmptyCopy();
    109112      copy.Wildcard = this.Wildcard;
    110113      copy.CurrentValue = this.CurrentValue;
    111114      return copy;
     115    }
     116
     117    IActionVariable IActionVariable.GetEmptyCopy() {
     118      return (IntVariable)GetEmptyCopy();
     119    }
     120    IActionVariable IActionVariable.GetSetCopy() {
     121      return (IntVariable)GetSetCopy();
    112122    }
    113123
     
    143153      if (parent2Cast == null) { throw new ArgumentException("Argument is not of the correct type."); }
    144154      if (pos != 0) { throw new ArgumentOutOfRangeException(); }
    145       return this.GetSetCopy();
     155      return (IntVariable)this.GetSetCopy();
    146156    }
    147157
     
    160170      }
    161171    }
     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
    162193  }
    163194}
  • branches/LearningClassifierSystems/HeuristicLab.Encodings.VariableVector/3.3/Variable/StringVariable.cs

    r9204 r9226  
    7474      this.featureMapping = new Dictionary<int, string>(original.featureMapping);
    7575      this.Wildcard = original.Wildcard;
     76      this.currentValue = original.currentValue;
    7677    }
    7778    public StringVariable()
     
    150151    }
    151152
    152     public new StringVariable GetEmptyCopy() {
     153    public override IVariable GetEmptyCopy() {
    153154      return new StringVariable(variableName, featureMapping);
    154155    }
    155     public new StringVariable GetSetCopy() {
    156       StringVariable copy = GetEmptyCopy();
     156    public override IVariable GetSetCopy() {
     157      StringVariable copy = (StringVariable)GetEmptyCopy();
    157158      copy.Wildcard = this.Wildcard;
    158159      copy.CurrentValue = this.CurrentValue;
    159160      return copy;
     161    }
     162    IActionVariable IActionVariable.GetEmptyCopy() {
     163      return (StringVariable)GetEmptyCopy();
     164    }
     165    IActionVariable IActionVariable.GetSetCopy() {
     166      return (StringVariable)GetSetCopy();
    160167    }
    161168
     
    195202      if (parent2Cast == null) { throw new ArgumentException("Argument is not of the correct type."); }
    196203      if (pos != 0) { throw new ArgumentOutOfRangeException(); }
    197       return this.GetSetCopy();
     204      return (StringVariable)this.GetSetCopy();
    198205    }
    199206
     
    202209      Wildcard = !Wildcard;
    203210      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;
    206212      }
    207213    }
     
    210216      Wildcard = random.NextDouble() < changeSymbolProbability;
    211217      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
    216243  }
    217244}
  • branches/LearningClassifierSystems/HeuristicLab.Encodings.VariableVector/3.3/Variable/Variable.cs

    r9204 r9226  
    5252    }
    5353
    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();
    5656
    5757    public abstract void Randomize(IRandom random);
  • branches/LearningClassifierSystems/HeuristicLab.Encodings.VariableVector/3.3/VariableVector.cs

    r9204 r9226  
    5454    protected VariableVector(VariableVector original, Cloner cloner)
    5555      : 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;
    5858    }
    5959    public VariableVector() {
     
    6464      : this() {
    6565      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"); }
    6767      this.Condition.Add(condition);
    6868      this.Action.Add(action.Cast<IActionVariable>());
     
    7070    public override IDeepCloneable Clone(Cloner cloner) {
    7171      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()));
    7276    }
    7377
     
    128132      var targetCast = target as VariableVector;
    129133      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; }
    132136      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       }
    167137    }
    168138  }
  • branches/LearningClassifierSystems/HeuristicLab.Encodings.VariableVector/3.3/VariableVectorAction.cs

    r9204 r9226  
    2222using System;
    2323using System.Collections.Generic;
     24using System.Drawing;
    2425using System.Linq;
    2526using System.Text;
    2627using HeuristicLab.Common;
    2728using HeuristicLab.Core;
    28 using HeuristicLab.Data;
    2929using HeuristicLab.Encodings.ConditionActionEncoding;
    3030using HeuristicLab.Persistence.Default.CompositeSerializers.Storable;
     
    3333  [StorableClass]
    3434  [Item("VariableVectorAction", "")]
    35   public class VariableVectorAction : ItemDictionary<StringValue, IActionVariable>, IAction {
     35  public class VariableVectorAction : Dictionary<string, IActionVariable>, IAction {
    3636
    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); } }
    3838
    3939    public int VirtualLength { get { return this.Values.Sum(x => x.VirtualLength); } }
    4040
    4141    [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      }
    4547    }
    4648    public VariableVectorAction() : base() { }
    4749    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;
    5166    }
    5267
    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());
    5872      }
    59       base.OnItemsAdded(items);
     73      return setCopy;
    6074    }
    6175
     
    6377      var targetCast = target as VariableVectorAction;
    6478      if (targetCast == null) { return false; }
    65       if (this.Order.SequenceEqual(targetCast.Order)) { return false; }
     79      if (!this.Order.SequenceEqual(targetCast.Order)) { return false; }
    6680      foreach (var keyValuePair in targetCast) {
    6781        if (!this[keyValuePair.Key].MatchVariable(keyValuePair.Value)) {
     
    7488    public void Add(IEnumerable<IActionVariable> action) {
    7589      foreach (var variable in action) {
    76         this.Add(new StringValue(variable.VariableName), variable);
     90        this.Add(variable.VariableName, variable);
    7791      }
    7892    }
     
    8296      bool first = true;
    8397      foreach (var variable in this.Values) {
    84         if (!first) {
     98        if (first) {
    8599          first = false;
    86100        } else {
     
    98112    }
    99113
    100     public bool Identical(VariableVectorCondition target) {
     114    public bool Identical(VariableVectorAction target) {
    101115      if (this.Order.SequenceEqual(target.Order)) { return false; }
    102116      foreach (var keyValuePair in target) {
     
    107121      return true;
    108122    }
     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    }
    109158  }
    110159}
  • branches/LearningClassifierSystems/HeuristicLab.Encodings.VariableVector/3.3/VariableVectorCondition.cs

    r9204 r9226  
    2020#endregion
    2121
     22using System;
    2223using System.Collections.Generic;
     24using System.Drawing;
    2325using System.Linq;
    2426using System.Text;
    2527using HeuristicLab.Common;
    2628using HeuristicLab.Core;
    27 using HeuristicLab.Data;
    2829using HeuristicLab.Encodings.ConditionActionEncoding;
    2930using HeuristicLab.Persistence.Default.CompositeSerializers.Storable;
     
    3233  [StorableClass]
    3334  [Item("VariableVectorCondition", "")]
    34   public class VariableVectorCondition : ItemDictionary<StringValue, IVariable>, ICondition {
     35  public class VariableVectorCondition : Dictionary<string, IVariable>, ICondition {
    3536
    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); } }
    3738
    3839    public int VirtualLength { get { return this.Values.Sum(x => x.VirtualLength); } }
    3940
    4041    [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      }
    4447    }
    4548    public VariableVectorCondition() : base() { }
    4649    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) { }
    5151
    5252    public bool Match(IInput target) {
    5353      var targetCast = target as VariableVectorInput;
    5454      if (targetCast == null) { return false; }
    55       if (this.Order.SequenceEqual(targetCast.Order)) { return false; }
    56       foreach (var keyValuePair in targetCast) {
    57         if (!this[keyValuePair.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])) {
    5858          return false;
    5959        }
     
    6464    public void Add(IEnumerable<IVariable> condition) {
    6565      foreach (var variable in condition) {
    66         this.Add(new StringValue(variable.VariableName), variable);
     66        this.Add(variable.VariableName, variable);
    6767      }
    6868    }
     
    7272      bool first = true;
    7373      foreach (var variable in this.Values) {
    74         if (!first) {
     74        if (first) {
    7575          first = false;
    7676        } else {
     
    9393
    9494    public bool Identical(VariableVectorCondition target) {
    95       if (this.Order.SequenceEqual(target.Order)) { return false; }
     95      if (!this.Order.SequenceEqual(target.Order)) { return false; }
    9696      foreach (var keyValuePair in target) {
    9797        if (!this[keyValuePair.Key].Identical(keyValuePair.Value)) {
     
    101101      return true;
    102102    }
     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    }
    103138  }
    104139}
  • branches/LearningClassifierSystems/HeuristicLab.Encodings.VariableVector/3.3/VariableVectorInput.cs

    r9204 r9226  
    2020#endregion
    2121
     22using System;
    2223using System.Collections.Generic;
     24using System.Drawing;
    2325using System.Linq;
     26using System.Text;
    2427using HeuristicLab.Common;
    2528using HeuristicLab.Core;
    26 using HeuristicLab.Data;
    2729using HeuristicLab.Encodings.ConditionActionEncoding;
    2830using HeuristicLab.Persistence.Default.CompositeSerializers.Storable;
     
    3133  [StorableClass]
    3234  [Item("VariableVectorInput", "")]
    33   public class VariableVectorInput : ItemDictionary<StringValue, StringValue>, IInput {
     35  public class VariableVectorInput : Dictionary<string, string>, IInput {
    3436
    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); } }
    3638
    3739    [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      }
    4145    }
    4246    public VariableVectorInput() : base() { }
    4347    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) {
    4681      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);
    4797    }
    4898  }
Note: See TracChangeset for help on using the changeset viewer.