Free cookie consent management tool by TermsFeed Policy Generator

Ignore:
Timestamp:
02/18/13 16:51:42 (11 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:
2 edited

Legend:

Unmodified
Added
Removed
  • branches/LearningClassifierSystems

    • Property svn:ignore
      •  

        old new  
        11*.suo
         2bin
  • 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}
Note: See TracChangeset for help on using the changeset viewer.