Free cookie consent management tool by TermsFeed Policy Generator

Ignore:
Timestamp:
02/25/13 12:37:18 (11 years ago)
Author:
sforsten
Message:

#1980:

  • fixed several bugs (crossover, subsumption, serialization etc.)
  • added ModuloOperator
  • CombinedIntegerVectorClassificationProblem\Data and VariableVectorClassificationProblem\Data inherit from ConditionActionClassificationProblem\Data
  • it can now be set how often the analyzers have to be executed
  • VariableVectorAction, VariableVectorCondition and VariableVectorInput now inherit from Item
Location:
branches/LearningClassifierSystems/HeuristicLab.Encodings.VariableVector/3.3
Files:
2 edited

Legend:

Unmodified
Added
Removed
  • branches/LearningClassifierSystems/HeuristicLab.Encodings.VariableVector/3.3

    • Property svn:ignore
      •  

        old new  
        11obj
         2Plugin.cs
  • branches/LearningClassifierSystems/HeuristicLab.Encodings.VariableVector/3.3/VariableVectorCondition.cs

    r9226 r9242  
    2020#endregion
    2121
    22 using System;
    2322using System.Collections.Generic;
    24 using System.Drawing;
    2523using System.Linq;
    2624using System.Text;
     
    3331  [StorableClass]
    3432  [Item("VariableVectorCondition", "")]
    35   public class VariableVectorCondition : Dictionary<string, IVariable>, ICondition {
     33  public class VariableVectorCondition : Item, ICondition {
    3634
    37     public IOrderedEnumerable<string> Order { get { return this.Keys.OrderBy(x => x); } }
     35    [Storable]
     36    private Dictionary<string, IVariable> variableDictionary;
     37    public Dictionary<string, IVariable> VariableDictionary {
     38      get { return variableDictionary; }
     39      protected set { variableDictionary = value; }
     40    }
    3841
    39     public int VirtualLength { get { return this.Values.Sum(x => x.VirtualLength); } }
     42    public IOrderedEnumerable<string> Order { get { return VariableDictionary.Keys.OrderBy(x => x); } }
     43
     44    public int VirtualLength { get { return VariableDictionary.Values.Sum(x => x.VirtualLength); } }
    4045
    4146    [StorableConstructor]
    4247    protected VariableVectorCondition(bool deserializing) { }
    4348    protected VariableVectorCondition(VariableVectorCondition original, Cloner cloner) {
    44       foreach (var item in original) {
    45         Add((string)item.Key.Clone(), (IVariable)item.Value.Clone());
     49      VariableDictionary = new Dictionary<string, IVariable>(original.VariableDictionary.Count);
     50      foreach (var item in original.VariableDictionary) {
     51        VariableDictionary.Add(item.Key, cloner.Clone(item.Value));
    4652      }
    4753    }
    48     public VariableVectorCondition() : base() { }
    49     public VariableVectorCondition(int capacity) : base(capacity) { }
    50     public VariableVectorCondition(IDictionary<string, IVariable> dictionary) : base(dictionary) { }
     54    public VariableVectorCondition()
     55      : base() {
     56      VariableDictionary = new Dictionary<string, IVariable>();
     57    }
     58    public VariableVectorCondition(int capacity)
     59      : base() {
     60      VariableDictionary = new Dictionary<string, IVariable>(capacity);
     61    }
     62    public VariableVectorCondition(IDictionary<string, IVariable> dictionary)
     63      : base() {
     64      VariableDictionary = new Dictionary<string, IVariable>(dictionary);
     65    }
     66    public override IDeepCloneable Clone(Cloner cloner) {
     67      return new VariableVectorCondition(this, cloner);
     68    }
    5169
    5270    public bool Match(IInput target) {
    5371      var targetCast = target as VariableVectorInput;
    5472      if (targetCast == null) { return false; }
    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])) {
     73      foreach (var key in VariableDictionary.Keys) {
     74        if (!targetCast.InputDictionary.ContainsKey(key) || !VariableDictionary[key].MatchInput(targetCast.InputDictionary[key])) {
    5875          return false;
    5976        }
     
    6481    public void Add(IEnumerable<IVariable> condition) {
    6582      foreach (var variable in condition) {
    66         this.Add(variable.VariableName, variable);
     83        VariableDictionary.Add(variable.VariableName, variable);
    6784      }
    6885    }
     
    7188      StringBuilder sb = new StringBuilder();
    7289      bool first = true;
    73       foreach (var variable in this.Values) {
     90      foreach (var variable in VariableDictionary.Values) {
    7491        if (first) {
    7592          first = false;
     
    83100
    84101    public void Randomize(IRandom random, double spreadPercentage) {
    85       foreach (var variable in this.Values) {
     102      foreach (var variable in VariableDictionary.Values) {
    86103        if (variable is DoubleVariable) {
    87104          ((DoubleVariable)variable).Randomize(random, spreadPercentage);
     
    94111    public bool Identical(VariableVectorCondition target) {
    95112      if (!this.Order.SequenceEqual(target.Order)) { return false; }
    96       foreach (var keyValuePair in target) {
    97         if (!this[keyValuePair.Key].Identical(keyValuePair.Value)) {
     113      foreach (var keyValuePair in target.VariableDictionary) {
     114        if (!VariableDictionary[keyValuePair.Key].Identical(keyValuePair.Value)) {
    98115          return false;
    99116        }
     
    101118      return true;
    102119    }
    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     }
    138120  }
    139121}
Note: See TracChangeset for help on using the changeset viewer.