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:
7 edited

Legend:

Unmodified
Added
Removed
  • branches/LearningClassifierSystems

    • Property svn:ignore
      •  

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