Free cookie consent management tool by TermsFeed Policy Generator

Changeset 9242


Ignore:
Timestamp:
02/25/13 12:37:18 (12 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
Files:
5 added
34 edited

Legend:

Unmodified
Added
Removed
  • branches/LearningClassifierSystems/HeuristicLab.Algorithms.LearningClassifierSystems/3.3/LearningClassifierSystem.cs

    r9204 r9242  
    123123    public IConstrainedValueParameter<IManipulator> MutatorParameter {
    124124      get { return (IConstrainedValueParameter<IManipulator>)Parameters["Mutator"]; }
     125    }
     126    public ValueParameter<IntValue> AnalyzeInIterationParameter {
     127      get { return (ValueParameter<IntValue>)Parameters["AnalyzeInIteration"]; }
    125128    }
    126129    #endregion
     
    253256      Parameters.Add(new ConstrainedValueParameter<ICrossover>("Crossover", "The operator used to cross solutions."));
    254257      Parameters.Add(new ConstrainedValueParameter<IManipulator>("Mutator", "The operator used to mutate solutions."));
     258      Parameters.Add(new ValueParameter<IntValue>("AnalyzeInIteration", "", new IntValue(50)));
    255259      #endregion
    256260
     
    275279      mainLoop.MutatorParameter.ActualName = MutatorParameter.Name;
    276280      mainLoop.CrossoverProbabilityParameter.ActualName = CrossoverProbabilityParameter.Name;
     281      mainLoop.AnalyzeInIterationParameter.ActualName = AnalyzeInIterationParameter.Name;
    277282      #endregion
    278283
  • branches/LearningClassifierSystems/HeuristicLab.Algorithms.LearningClassifierSystems/3.3/LearningClassifierSystemMainLoop.cs

    r9226 r9242  
    6969      get { return (ValueLookupParameter<IOperator>)Parameters["FinalAnalyzer"]; }
    7070    }
     71    public ValueLookupParameter<IntValue> AnalyzeInIterationParameter {
     72      get { return (ValueLookupParameter<IntValue>)Parameters["AnalyzeInIteration"]; }
     73    }
    7174    #endregion
    7275
     
    114117      Parameters.Add(new ValueLookupParameter<IOperator>("Analyzer", "The operator used to analyze each generation."));
    115118      Parameters.Add(new ValueLookupParameter<IOperator>("FinalAnalyzer", "The operator used to analyze the last generation."));
     119      Parameters.Add(new ValueLookupParameter<IntValue>("AnalyzeInIteration", ""));
    116120      #endregion
    117121
     
    119123      VariableCreator variableCreator = new VariableCreator();
    120124      ResultsCollector resultsCollector = new ResultsCollector();
     125      ModuloOperator moduloOperator = new ModuloOperator();
     126      Comparator analyzerComparator = new Comparator();
     127      ConditionalBranch analyzerConditionalBranch = new ConditionalBranch();
    121128      Placeholder analyzer = new Placeholder();
    122129      Placeholder finalAnalyzer = new Placeholder();
     
    183190      resultsCollector.CollectedValues.Add(new LookupParameter<IntValue>("Iteration"));
    184191      resultsCollector.ResultsParameter.ActualName = "Results";
     192
     193      moduloOperator.LeftSideParameter.ActualName = "Iteration";
     194      moduloOperator.RightSideParameter.ActualName = AnalyzeInIterationParameter.ActualName;
     195      moduloOperator.ResultParameter.ActualName = "ModuloResult";
     196
     197      analyzerComparator.LeftSideParameter.ActualName = "ModuloResult";
     198      analyzerComparator.RightSideParameter.Value = new IntValue(0);
     199      analyzerComparator.ResultParameter.ActualName = "DoAnalyzing";
     200
     201      analyzerConditionalBranch.ConditionParameter.ActualName = "DoAnalyzing";
    185202
    186203      analyzer.Name = "Analyzer";
     
    403420      deletionSelectorAfterGA.Successor = leftReducerAfterGA;
    404421      leftReducerAfterGA.Successor = iterationCounter;
    405       iterationCounter.Successor = analyzer;
    406       analyzer.Successor = maxIterationsComparator;
     422      iterationCounter.Successor = moduloOperator;
     423      moduloOperator.Successor = analyzerComparator;
     424      analyzerComparator.Successor = analyzerConditionalBranch;
     425      analyzerConditionalBranch.Successor = maxIterationsComparator;
     426      analyzerConditionalBranch.TrueBranch = analyzer;
    407427      #endregion
    408428    }
  • branches/LearningClassifierSystems/HeuristicLab.Encodings.CombinedIntegerVectorEncoding/3.3/CombinedIntegerVectorCreator.cs

    r9089 r9242  
    4141      get { return (LookupParameter<IRandom>)Parameters["Random"]; }
    4242    }
    43     public IValueLookupParameter<IntValue> LengthParameter {
    44       get { return (IValueLookupParameter<IntValue>)Parameters["Length"]; }
     43    public IValueLookupParameter<ICombinedIntegerVectorClassificationProblemData> ProblemDataParameter {
     44      get { return (IValueLookupParameter<ICombinedIntegerVectorClassificationProblemData>)Parameters["ProblemData"]; }
    4545    }
    46     public IValueLookupParameter<IntMatrix> BoundsParameter {
    47       get { return (IValueLookupParameter<IntMatrix>)Parameters["Bounds"]; }
     46    public ILookupParameter<CombinedIntegerVector> CombinedIntegerVectorParameter {
     47      get { return (ILookupParameter<CombinedIntegerVector>)Parameters["CombinedIntegerVector"]; }
    4848    }
    4949
    50     public IValueLookupParameter<IntValue> ActionPartLengthParameter {
    51       get { return (IValueLookupParameter<IntValue>)Parameters["ActionPartLength"]; }
    52     }
    53 
    54     public ILookupParameter<CombinedIntegerVector> CombinedIntegerVectorParameter {
    55       get { return (ILookupParameter<CombinedIntegerVector>)Parameters["CombinedIntegerVector"]; }
     50    protected ICombinedIntegerVectorClassificationProblemData ProblemData {
     51      get { return ProblemDataParameter.ActualValue; }
    5652    }
    5753
     
    6258      : base() {
    6359      Parameters.Add(new LookupParameter<IRandom>("Random", "The pseudo random number generator which should be used for stochastic manipulation operators."));
    64       Parameters.Add(new ValueLookupParameter<IntValue>("Length", "The length of the vector."));
    65       Parameters.Add(new ValueLookupParameter<IntMatrix>("Bounds", "The bounds matrix can contain one row for each dimension with three columns specifying minimum (inclusive), maximum (exclusive), and step size. If less rows are given the matrix is cycled."));
     60      Parameters.Add(new ValueLookupParameter<ICombinedIntegerVectorClassificationProblemData>("ProblemData", ""));
    6661      Parameters.Add(new LookupParameter<CombinedIntegerVector>("CombinedIntegerVector", "The vector which should be manipulated."));
    67       Parameters.Add(new ValueLookupParameter<IntValue>("ActionPartLength", "The length of the vector."));
    6862    }
    6963
    7064    public sealed override IOperation Apply() {
    71       CombinedIntegerVectorParameter.ActualValue = Create(RandomParameter.ActualValue, LengthParameter.ActualValue, BoundsParameter.ActualValue, ActionPartLengthParameter.ActualValue);
     65      CombinedIntegerVectorParameter.ActualValue = Create(RandomParameter.ActualValue, ProblemData.LengthParameter.Value, ProblemData.BoundsParameter.Value, ProblemData.ActionLengthParameter.Value);
    7266      return base.Apply();
    7367    }
  • branches/LearningClassifierSystems/HeuristicLab.Encodings.CombinedIntegerVectorEncoding/3.3/Covering/CombinedIntegerVectorCoveringCreator.cs

    r9204 r9242  
    4343
    4444    protected override IClassifier CreateCoveredClassifier(IInput input, IAction action, IRandom random, double changeSymbolProbability) {
    45       CombinedIntegerVector newCondition = (CombinedIntegerVector)input.Clone();
     45      CombinedIntegerVector newCondition = (CombinedIntegerVector)((CombinedIntegerVector)input.Clone()).Condition;
    4646
    4747      CombinedIntegerVector condition = (CombinedIntegerVector)input;
  • branches/LearningClassifierSystems/HeuristicLab.Encodings.CombinedIntegerVectorEncoding/3.3/HeuristicLab.Encodings.CombinedIntegerVectorEncoding-3.3.csproj

    r9228 r9242  
    128128    <Compile Include="Creators\UniformRandomCombinedIntegerVectorCreator.cs" />
    129129    <Compile Include="Crossovers\SinglePointCrossover.cs" />
     130    <Compile Include="Interfaces\ICombinedIntegerVectorClassificationProblem.cs" />
     131    <Compile Include="Interfaces\ICombinedIntegerVectorClassificationProblemData.cs" />
    130132    <Compile Include="Interfaces\ICombinedIntegerVectorManipulator.cs" />
    131133    <Compile Include="Interfaces\ICombinedIntegerVectorCrossover.cs" />
    132     <Compile Include="Interfaces\IBoundedCombinedIntegerVectorOperator.cs" />
    133134    <Compile Include="Interfaces\ICombinedIntegerVectorCreator.cs" />
    134135    <Compile Include="Interfaces\ICombinedIntegerVectorOperator.cs" />
  • branches/LearningClassifierSystems/HeuristicLab.Encodings.CombinedIntegerVectorEncoding/3.3/Interfaces/ICombinedIntegerVectorCreator.cs

    r9089 r9242  
    2323using HeuristicLab.Common;
    2424using HeuristicLab.Core;
    25 using HeuristicLab.Data;
    2625using HeuristicLab.Optimization;
    2726
    2827namespace HeuristicLab.Encodings.CombinedIntegerVectorEncoding {
    29   public interface ICombinedIntegerVectorCreator : ISolutionCreator, IBoundedCombinedIntegerVectorOperator, ICombinedIntegerVectorOperator, IOperator, IParameterizedNamedItem, INamedItem, IParameterizedItem, IItem, IContent, IDeepCloneable, ICloneable {
    30     IValueLookupParameter<IntValue> LengthParameter { get; }
    31     IValueLookupParameter<IntValue> ActionPartLengthParameter { get; }
     28  public interface ICombinedIntegerVectorCreator : ISolutionCreator, ICombinedIntegerVectorOperator, IOperator, IParameterizedNamedItem, INamedItem, IParameterizedItem, IItem, IContent, IDeepCloneable, ICloneable {
     29    IValueLookupParameter<ICombinedIntegerVectorClassificationProblemData> ProblemDataParameter { get; }
    3230    ILookupParameter<CombinedIntegerVector> CombinedIntegerVectorParameter { get; }
    3331  }
  • branches/LearningClassifierSystems/HeuristicLab.Encodings.ConditionActionEncoding/3.3/HeuristicLab.Encodings.ConditionActionEncoding-3.3.csproj

    r9228 r9242  
    118118    <Compile Include="GA\XCSCheckIfGAShouldBeApplied.cs" />
    119119    <Compile Include="Operator\CountNumberOfUniqueActions.cs" />
     120    <Compile Include="Operator\ModuloOperator.cs" />
    120121    <Compile Include="Operator\PredictionArrayCalculator.cs" />
    121122    <Compile Include="Operator\MatchActionOperator.cs" />
  • branches/LearningClassifierSystems/HeuristicLab.Encodings.VariableVector/3.3

    • Property svn:ignore
      •  

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

    r9226 r9242  
    3434  public class VariableVectorCoveringCreator : CoveringSolutionCreator, IVariableVectorCoveringCreator {
    3535
    36     public IValueLookupParameter<VariableVector> SampleVariableVectorParameter {
    37       get { return (IValueLookupParameter<VariableVector>)Parameters["SampleVariableVector"]; }
     36    public IValueLookupParameter<IVariableVectorClassificationProblemData> ProblemDataParameter {
     37      get { return (IValueLookupParameter<IVariableVectorClassificationProblemData>)Parameters["ProblemData"]; }
     38    }
     39
     40    private IVariableVectorClassificationProblemData ProblemData {
     41      get { return ProblemDataParameter.ActualValue; }
    3842    }
    3943
     
    4549    public VariableVectorCoveringCreator()
    4650      : base() {
    47       Parameters.Add(new ValueLookupParameter<VariableVector>("SampleVariableVector"));
     51      Parameters.Add(new ValueLookupParameter<IVariableVectorClassificationProblemData>("ProblemData"));
    4852    }
    4953    public override IDeepCloneable Clone(Cloner cloner) {
     
    5559      var actionCast = action as VariableVectorAction;
    5660
    57       VariableVectorCondition sampleVariableVectorCondition = SampleVariableVectorParameter.ActualValue.Condition;
     61      VariableVectorCondition sampleVariableVectorCondition = ProblemData.SampleVariableVectorParameter.Value.Condition;
    5862      IEnumerable<IVariable> newCondition = CoverInput(inputCast, sampleVariableVectorCondition, random, changeSymbolProbability);
    5963
    60       return new VariableVector(newCondition, actionCast.Values);
     64      return new VariableVector(newCondition, actionCast.VariableDictionary.Values);
    6165    }
    6266
    6367    private IEnumerable<IVariable> CoverInput(VariableVectorInput input, VariableVectorCondition sample, IRandom random, double changeSymbolProbability) {
    64       var conditionVariables = new List<IVariable>();
    65       if (!sample.Keys.All(x => input.ContainsKey(x))) {
     68      List<IVariable> conditionVariables = new List<IVariable>();
     69      if (!sample.VariableDictionary.Keys.All(x => input.InputDictionary.ContainsKey(x))) {
    6670        throw new ArgumentException("Input does not contain all variable names from sample");
    6771      }
    68       foreach (var keyValuePair in sample) {
     72      foreach (var keyValuePair in sample.VariableDictionary) {
    6973        IVariable variable = keyValuePair.Value.GetEmptyCopy();
    70         variable.Cover(random, input[keyValuePair.Key], changeSymbolProbability);
     74        variable.Cover(random, input.InputDictionary[keyValuePair.Key], changeSymbolProbability);
    7175        conditionVariables.Add(variable);
    7276      }
  • branches/LearningClassifierSystems/HeuristicLab.Encodings.VariableVector/3.3/Crossover/SinglePointCrossover.cs

    r9226 r9242  
    5454
    5555      if (parent1.Count != parent2.Count && parent1.VirtualLength != parent2.VirtualLength
    56         && parent1Condition.Count != parent2Condition.Count && parent1Condition.VirtualLength != parent2Condition.VirtualLength
    57         && parent1Action.Count != parent2Action.Count && parent1Action.VirtualLength != parent2Action.VirtualLength)
     56        && parent1Condition.VariableDictionary.Count != parent2Condition.VariableDictionary.Count && parent1Condition.VirtualLength != parent2Condition.VirtualLength
     57        && parent1Action.VariableDictionary.Count != parent2Action.VariableDictionary.Count && parent1Action.VirtualLength != parent2Action.VirtualLength)
    5858        throw new ArgumentException("SinglePointCrossover: The parents are of different length.");
    5959
    6060      int conditionLength = parent1Condition.VirtualLength;
    6161      int breakPoint = random.Next(1, conditionLength);
    62       IList<IVariable> newCondition = new List<IVariable>(parent1Condition.Count);
     62      IList<IVariable> newCondition = new List<IVariable>(parent1Condition.VariableDictionary.Count);
    6363
    6464      var keyEnumerator = parent1Condition.Order.GetEnumerator();
    6565
    6666      int index = 0;
    67       IVariable curVariable;
     67      IVariable curVariable = null;
    6868      while (index < breakPoint) {
    69         keyEnumerator.MoveNext();
    70         curVariable = parent1Condition[keyEnumerator.Current];
    71         if (curVariable.VirtualLength == 1 || index + curVariable.VirtualLength - 1 < breakPoint) {
     69        if (!keyEnumerator.MoveNext()) { throw new IndexOutOfRangeException("Enumerator has no next element!"); }
     70        curVariable = parent1Condition.VariableDictionary[keyEnumerator.Current];
     71        if (index + curVariable.VirtualLength <= breakPoint) {
    7272          newCondition.Add(curVariable.GetSetCopy());
    73           index += curVariable.VirtualLength;
    7473        }
     74        index += curVariable.VirtualLength;
    7575      }
    7676
    7777      // breakpoint is in between a variable
    7878      if (index != breakPoint) {
    79         newCondition.Add(parent1Condition[keyEnumerator.Current].CrossParentsAtPosition(parent2Condition[keyEnumerator.Current], breakPoint - index - 1));
     79        newCondition.Add(parent1Condition.VariableDictionary[keyEnumerator.Current].CrossParentsAtPosition(parent2Condition.VariableDictionary[keyEnumerator.Current], breakPoint - (index - curVariable.VirtualLength)));
    8080      }
    8181
    8282      while (index < conditionLength) {
    8383        keyEnumerator.MoveNext();
    84         curVariable = parent2Condition[keyEnumerator.Current];
     84        curVariable = parent2Condition.VariableDictionary[keyEnumerator.Current];
    8585        newCondition.Add(curVariable.GetSetCopy());
    8686        index += curVariable.VirtualLength;
    8787      }
    8888
    89       var action = random.Next(2) == 1 ? parent1Action.Values.Select(x => x.GetSetCopy()) : parent2Action.Values.Select(x => x.GetSetCopy());
     89      var action = random.Next(2) == 1 ? parent1Action.VariableDictionary.Values.Select(x => x.GetSetCopy()) : parent2Action.VariableDictionary.Values.Select(x => x.GetSetCopy());
    9090
    9191      return new VariableVector(newCondition, action);
  • branches/LearningClassifierSystems/HeuristicLab.Encodings.VariableVector/3.3/HeuristicLab.Encodings.VariableVector-3.3.csproj

    r9228 r9242  
    8585    <Compile Include="Covering\VariableVectorCoveringCreator.cs" />
    8686    <Compile Include="Crossover\SinglePointCrossover.cs" />
     87    <Compile Include="Interfaces\IVariableVectorClassificationProblem.cs" />
     88    <Compile Include="Interfaces\IVariableVectorClassificationProblemData.cs" />
    8789    <Compile Include="Interfaces\IVariableVectorCoveringCreator.cs" />
    8890    <Compile Include="Interfaces\IVariableVectorCrossover.cs" />
  • branches/LearningClassifierSystems/HeuristicLab.Encodings.VariableVector/3.3/Interfaces/IVariableVectorCoveringCreator.cs

    r9204 r9242  
    2525namespace HeuristicLab.Encodings.VariableVector {
    2626  public interface IVariableVectorCoveringCreator : ICoveringSolutionCreator, IVariableVectorOperator {
    27     IValueLookupParameter<VariableVector> SampleVariableVectorParameter { get; }
     27    IValueLookupParameter<IVariableVectorClassificationProblemData> ProblemDataParameter { get; }
    2828  }
    2929}
  • branches/LearningClassifierSystems/HeuristicLab.Encodings.VariableVector/3.3/Interfaces/IVariableVectorCreator.cs

    r9194 r9242  
    2121
    2222using HeuristicLab.Core;
    23 using HeuristicLab.Data;
    2423using HeuristicLab.Optimization;
    2524
    2625namespace HeuristicLab.Encodings.VariableVector {
    2726  public interface IVariableVectorCreator : ISolutionCreator, IVariableVectorOperator {
    28     IValueLookupParameter<PercentValue> SpreadPercentageParameter { get; }
    29     IValueLookupParameter<VariableVector> SampleVariableVectorParameter { get; }
     27    IValueLookupParameter<IVariableVectorClassificationProblemData> ProblemDataParameter { get; }
    3028    ILookupParameter<VariableVector> VariableVectorParameter { get; }
    31 
    3229  }
    3330}
  • branches/LearningClassifierSystems/HeuristicLab.Encodings.VariableVector/3.3/Manipulator/UniformActionManipulator.cs

    r9204 r9242  
    6060      int actionIndex = random.Next(otherActions.Count());
    6161      VariableVectorAction newAction = otherActions.ElementAt(actionIndex);
    62       return new VariableVector(child.Condition.Values.Select(x => x.GetSetCopy()), newAction.Values.Select(x => x.GetSetCopy()));
     62      return new VariableVector(child.Condition.VariableDictionary.Values.Select(x => x.GetSetCopy()), newAction.VariableDictionary.Values.Select(x => x.GetSetCopy()));
    6363    }
    6464  }
  • branches/LearningClassifierSystems/HeuristicLab.Encodings.VariableVector/3.3/Manipulator/UniformOnePositionInConditionManipulator.cs

    r9226 r9242  
    5757      int count = 0;
    5858      keyEnumerator.MoveNext();
    59       while (count < condition.VirtualLength && count < index && count + condition[keyEnumerator.Current].VirtualLength <= index) {
    60         count += condition[keyEnumerator.Current].VirtualLength;
     59      while (count < condition.VirtualLength && count < index && count + condition.VariableDictionary[keyEnumerator.Current].VirtualLength <= index) {
     60        count += condition.VariableDictionary[keyEnumerator.Current].VirtualLength;
    6161        keyEnumerator.MoveNext();
    6262      }
    63       condition[keyEnumerator.Current].Manipulate(random, input[keyEnumerator.Current], index - count);
     63      condition.VariableDictionary[keyEnumerator.Current].Manipulate(random, input.InputDictionary[keyEnumerator.Current], index - count);
    6464      return child;
    6565    }
  • branches/LearningClassifierSystems/HeuristicLab.Encodings.VariableVector/3.3/Properties

    • Property svn:ignore set to
      AssemblyInfo.cs
  • branches/LearningClassifierSystems/HeuristicLab.Encodings.VariableVector/3.3/Variable/DoubleVariable.cs

    r9226 r9242  
    6666      min = original.min;
    6767      max = original.max;
     68      currentSpread = original.currentSpread;
     69      currentCenter = original.currentCenter;
    6870    }
    6971    public DoubleVariable() : base() { }
     
    8991
    9092    public override string ToString() {
    91       return (currentCenter - currentCenter) + " - " + (currentCenter + currentSpread);
     93      return (currentCenter - currentSpread) + " - " + (currentCenter + currentSpread);
    9294    }
    9395
     
    9799
    98100    public override bool Match(double target) {
    99       return currentCenter - currentSpread < target && target < currentCenter + currentSpread;
     101      return currentCenter - currentSpread <= target && target <= currentCenter + currentSpread;
    100102    }
    101103
     
    128130      var targetCast = target as DoubleVariable;
    129131      if (targetCast == null) { return false; }
    130       if (variableName != targetCast.variableName || currentCenter != targetCast.currentCenter
    131         || currentSpread != targetCast.currentSpread || max != targetCast.max
    132         || min != targetCast.min) { return false; }
     132      if (variableName != targetCast.variableName || currentCenter.IsAlmost(targetCast.currentCenter)
     133        || currentSpread.IsAlmost(targetCast.currentSpread) || max.IsAlmost(targetCast.max)
     134        || min.IsAlmost(targetCast.min)) { return false; }
    133135
    134136      return true;
     
    149151    }
    150152
    151     public new DoubleVariable CrossParentsAtPosition(IVariable parent2, int pos) {
    152       var parent2Cast = parent2 as DoubleVariable;
     153    public override IVariable CrossParentsAtPosition(IVariable parent2, int pos) {
     154      DoubleVariable parent2Cast = parent2 as DoubleVariable;
    153155      if (parent2Cast == null) { throw new ArgumentException("Argument is not of the correct type."); }
    154156      if (pos > 1 || pos < 0) { throw new ArgumentOutOfRangeException(); }
    155157      DoubleVariable crossed = (DoubleVariable)this.GetSetCopy();
    156       if (pos == 0) {
     158      if (pos == 1) {
    157159        crossed.CurrentSpread = parent2Cast.CurrentSpread;
    158160      }
     
    180182
    181183    public override void Cover(IRandom random, string stringValue, double changeSymbolProbability) {
    182       Cover(random, stringValue, 50);
     184      CoverWithSpreadPercentage(random, stringValue, changeSymbolProbability);
    183185    }
    184186
     
    186188      currentCenter = double.Parse(stringValue);
    187189      double delta = max - min;
    188       currentSpread = random.NextDouble() * (delta * (spreadPercentage / 100));
     190      currentSpread = random.NextDouble() * (delta * spreadPercentage);
    189191    }
    190192  }
  • branches/LearningClassifierSystems/HeuristicLab.Encodings.VariableVector/3.3/Variable/IVariable.cs

    r9226 r9242  
    3030
    3131    IVariable GetEmptyCopy();
     32    //GetSetCopy is used instead of Clone, so that data doesn't have to be duplicated
    3233    IVariable GetSetCopy();
    3334
  • branches/LearningClassifierSystems/HeuristicLab.Encodings.VariableVector/3.3/Variable/IntVariable.cs

    r9226 r9242  
    149149    }
    150150
    151     public new IntVariable CrossParentsAtPosition(IVariable parent2, int pos) {
     151    public override IVariable CrossParentsAtPosition(IVariable parent2, int pos) {
    152152      var parent2Cast = parent2 as IntVariable;
    153153      if (parent2Cast == null) { throw new ArgumentException("Argument is not of the correct type."); }
    154154      if (pos != 0) { throw new ArgumentOutOfRangeException(); }
    155       return (IntVariable)this.GetSetCopy();
     155      return (IntVariable)parent2.GetSetCopy();
    156156    }
    157157
  • branches/LearningClassifierSystems/HeuristicLab.Encodings.VariableVector/3.3/Variable/StringVariable.cs

    r9226 r9242  
    198198    }
    199199
    200     public new StringVariable CrossParentsAtPosition(IVariable parent2, int pos) {
     200    public override IVariable CrossParentsAtPosition(IVariable parent2, int pos) {
    201201      var parent2Cast = parent2 as StringVariable;
    202202      if (parent2Cast == null) { throw new ArgumentException("Argument is not of the correct type."); }
    203203      if (pos != 0) { throw new ArgumentOutOfRangeException(); }
    204       return (StringVariable)this.GetSetCopy();
     204      return (StringVariable)parent2.GetSetCopy();
    205205    }
    206206
  • branches/LearningClassifierSystems/HeuristicLab.Encodings.VariableVector/3.3/Variable/Variable.cs

    r9226 r9242  
    6868    public abstract bool IsGreaterThanOrEquallyGeneral(IVariable target);
    6969
    70     public virtual IVariable CrossParentsAtPosition(IVariable parent2, int pos) { throw new NotSupportedException("This method is not supported."); }
     70    public abstract IVariable CrossParentsAtPosition(IVariable parent2, int pos);
    7171
    7272    public abstract void Manipulate(IRandom random, string stringValue, int pos);
  • branches/LearningClassifierSystems/HeuristicLab.Encodings.VariableVector/3.3/VariableVector.cs

    r9226 r9242  
    4343
    4444    public int Count {
    45       get { return condition.Count + action.Count; }
     45      get { return condition.VariableDictionary.Count + action.VariableDictionary.Count; }
    4646    }
    4747
    4848    public int VirtualLength {
    49       get { return condition.Values.Sum(x => x.VirtualLength) + action.Values.Sum(x => x.VirtualLength); }
     49      get { return condition.VariableDictionary.Values.Sum(x => x.VirtualLength) + action.VariableDictionary.Values.Sum(x => x.VirtualLength); }
    5050    }
    5151
     
    7373
    7474    public VariableVector GetEmptyCopy() {
    75       return new VariableVector(Condition.Values.Select(x => x.GetEmptyCopy()), Action.Values.Select(x => x.GetEmptyCopy()));
     75      return new VariableVector(Condition.VariableDictionary.Values.Select(x => x.GetEmptyCopy()), Action.VariableDictionary.Values.Select(x => x.GetEmptyCopy()));
    7676    }
    7777
     
    112112
    113113    public bool IsMoreGeneral(ICondition target) {
    114       var targetCast = target as VariableVector;
     114      var targetCast = target as VariableVectorCondition;
    115115      if (targetCast == null) { return false; }
    116       if (Condition.Keys.Except(targetCast.Condition.Keys).Count() != 0
    117         || targetCast.Condition.Keys.Except(Condition.Keys).Count() != 0) { return false; }
     116      if (Condition.VariableDictionary.Keys.Except(targetCast.VariableDictionary.Keys).Count() != 0
     117        || targetCast.VariableDictionary.Keys.Except(Condition.VariableDictionary.Keys).Count() != 0) { return false; }
    118118
    119       double thisGenerality = Condition.Values.Sum(x => x.GetGenerality());
    120       double targetGenerality = Condition.Values.Sum(x => x.GetGenerality());
     119      double thisGenerality = Condition.VariableDictionary.Values.Sum(x => x.GetGenerality());
     120      double targetGenerality = targetCast.VariableDictionary.Values.Sum(x => x.GetGenerality());
    121121      if (thisGenerality <= targetGenerality) { return false; }
    122122
    123       foreach (var variables in targetCast.Condition) {
    124         if (!Condition[variables.Key].IsGreaterThanOrEquallyGeneral(variables.Value)) {
     123      foreach (var variables in targetCast.VariableDictionary) {
     124        if (!Condition.VariableDictionary[variables.Key].IsGreaterThanOrEquallyGeneral(variables.Value)) {
    125125          return false;
    126126        }
  • branches/LearningClassifierSystems/HeuristicLab.Encodings.VariableVector/3.3/VariableVectorAction.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("VariableVectorAction", "")]
    35   public class VariableVectorAction : Dictionary<string, IActionVariable>, IAction {
     33  public class VariableVectorAction : Item, IAction {
    3634
    37     public IOrderedEnumerable<string> Order { get { return this.Keys.OrderBy(x => x); } }
     35    [Storable]
     36    private Dictionary<string, IActionVariable> variableDictionary;
     37    public Dictionary<string, IActionVariable> 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 VariableVectorAction(bool deserializing) { }
    4348    protected VariableVectorAction(VariableVectorAction original, Cloner cloner) {
    44       foreach (var item in original) {
    45         Add((string)item.Key.Clone(), (IActionVariable)item.Value.Clone());
     49      VariableDictionary = new Dictionary<string, IActionVariable>(original.VariableDictionary.Count);
     50      foreach (var item in original.VariableDictionary) {
     51        VariableDictionary.Add(item.Key, cloner.Clone(item.Value));
    4652      }
    4753    }
    48     public VariableVectorAction() : base() { }
    49     public VariableVectorAction(int capacity) : base(capacity) { }
    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     //}
     54    public VariableVectorAction()
     55      : base() {
     56      VariableDictionary = new Dictionary<string, IActionVariable>();
     57    }
     58    public VariableVectorAction(int capacity)
     59      : base() {
     60      VariableDictionary = new Dictionary<string, IActionVariable>(capacity);
     61    }
     62    public VariableVectorAction(IDictionary<string, IActionVariable> dictionary)
     63      : base() {
     64      VariableDictionary = new Dictionary<string, IActionVariable>(dictionary);
     65    }
     66    public override IDeepCloneable Clone(Cloner cloner) {
     67      return new VariableVectorAction(this, cloner);
     68    }
    5969
    6070    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       }
     71      VariableVectorAction emptyCopy = new VariableVectorAction(VariableDictionary.Count);
     72      emptyCopy.Add(VariableDictionary.Values.Select(x => x.GetEmptyCopy()));
    6573      return emptyCopy;
    6674    }
    6775
    6876    public VariableVectorAction GetSetCopy() {
    69       VariableVectorAction setCopy = new VariableVectorAction(this.Count);
    70       foreach (var keyValuePair in this) {
    71         setCopy.Add(keyValuePair.Key, keyValuePair.Value.GetSetCopy());
    72       }
     77      VariableVectorAction setCopy = new VariableVectorAction(VariableDictionary.Count);
     78      setCopy.Add(VariableDictionary.Values.Select(x => x.GetSetCopy()));
    7379      return setCopy;
    7480    }
     
    7884      if (targetCast == null) { return false; }
    7985      if (!this.Order.SequenceEqual(targetCast.Order)) { return false; }
    80       foreach (var keyValuePair in targetCast) {
    81         if (!this[keyValuePair.Key].MatchVariable(keyValuePair.Value)) {
     86      foreach (var keyValuePair in targetCast.VariableDictionary) {
     87        if (!VariableDictionary[keyValuePair.Key].MatchVariable(keyValuePair.Value)) {
    8288          return false;
    8389        }
     
    8894    public void Add(IEnumerable<IActionVariable> action) {
    8995      foreach (var variable in action) {
    90         this.Add(variable.VariableName, variable);
     96        VariableDictionary.Add(variable.VariableName, variable);
    9197      }
    9298    }
     
    95101      StringBuilder sb = new StringBuilder();
    96102      bool first = true;
    97       foreach (var variable in this.Values) {
     103      foreach (var variable in VariableDictionary.Values) {
    98104        if (first) {
    99105          first = false;
     
    107113
    108114    public void Randomize(IRandom random) {
    109       foreach (var variable in this.Values) {
     115      foreach (var variable in VariableDictionary.Values) {
    110116        variable.Randomize(random);
    111117      }
     
    113119
    114120    public bool Identical(VariableVectorAction target) {
    115       if (this.Order.SequenceEqual(target.Order)) { return false; }
    116       foreach (var keyValuePair in target) {
    117         if (!this[keyValuePair.Key].Identical(keyValuePair.Value)) {
     121      if (!this.Order.SequenceEqual(target.Order)) { return false; }
     122      foreach (var keyValuePair in target.VariableDictionary) {
     123        if (!VariableDictionary[keyValuePair.Key].Identical(keyValuePair.Value)) {
    118124          return false;
    119125        }
     
    121127      return true;
    122128    }
    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     }
    158129  }
    159130}
  • branches/LearningClassifierSystems/HeuristicLab.Encodings.VariableVector/3.3/VariableVectorActionComparer.cs

    r9226 r9242  
    4444    public bool Equals(VariableVectorAction x, VariableVectorAction y) {
    4545      if (!x.Order.SequenceEqual(y.Order)) return false;
    46       foreach (var key in x.Keys) {
    47         if (!x[key].Identical(y[key])) {
     46      foreach (var key in x.VariableDictionary.Keys) {
     47        if (!x.VariableDictionary[key].Identical(y.VariableDictionary[key])) {
    4848          return false;
    4949        }
     
    5454    public int GetHashCode(VariableVectorAction obj) {
    5555      int result = 1;
    56       foreach (var key in obj.Keys) {
     56      foreach (var key in obj.VariableDictionary.Keys) {
    5757        result = 37 * result + key.GetHashCode();
    5858      }
    5959
    60       foreach (var val in obj.Values) {
     60      foreach (var val in obj.VariableDictionary.Values) {
    6161        result = 37 * result + val.GetHashCode();
    6262      }
  • 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}
  • branches/LearningClassifierSystems/HeuristicLab.Encodings.VariableVector/3.3/VariableVectorCreator.cs

    r9194 r9242  
    2222using HeuristicLab.Common;
    2323using HeuristicLab.Core;
    24 using HeuristicLab.Data;
    2524using HeuristicLab.Operators;
    2625using HeuristicLab.Optimization;
     
    3433
    3534    #region Parameter Properties
    36     public IValueLookupParameter<PercentValue> SpreadPercentageParameter {
    37       get { return (IValueLookupParameter<PercentValue>)Parameters["SpreadPercentage"]; }
    38     }
    39     public IValueLookupParameter<VariableVector> SampleVariableVectorParameter {
    40       get { return (IValueLookupParameter<VariableVector>)Parameters["SampleVariableVector"]; }
     35    public IValueLookupParameter<IVariableVectorClassificationProblemData> ProblemDataParameter {
     36      get { return (IValueLookupParameter<IVariableVectorClassificationProblemData>)Parameters["ProblemData"]; }
    4137    }
    4238    public ILookupParameter<VariableVector> VariableVectorParameter {
     
    4844    #endregion
    4945
     46    protected IVariableVectorClassificationProblemData ProblemData {
     47      get { return ProblemDataParameter.ActualValue; }
     48    }
     49
    5050    [StorableConstructor]
    5151    protected VariableVectorCreator(bool deserializing) : base(deserializing) { }
     
    5555    public VariableVectorCreator()
    5656      : base() {
    57       Parameters.Add(new ValueLookupParameter<PercentValue>("SpreadPercentage", ""));
    58       Parameters.Add(new ValueLookupParameter<VariableVector>("SampleVariableVector", ""));
     57      Parameters.Add(new ValueLookupParameter<IVariableVectorClassificationProblemData>("ProblemData", ""));
    5958      Parameters.Add(new LookupParameter<VariableVector>("VariableVector", ""));
    6059      Parameters.Add(new LookupParameter<IRandom>("Random", "The pseudo random number generator which should be used for stochastic manipulation operators."));
     
    6261
    6362    public override IOperation Apply() {
    64       VariableVectorParameter.ActualValue = Create(RandomParameter.ActualValue, SampleVariableVectorParameter.ActualValue, SpreadPercentageParameter.ActualValue.Value);
     63      VariableVectorParameter.ActualValue = Create(RandomParameter.ActualValue, ProblemData.SampleVariableVectorParameter.Value, ProblemData.SpreadPercentageParameter.Value.Value);
    6564      return base.Apply();
    6665    }
  • branches/LearningClassifierSystems/HeuristicLab.Encodings.VariableVector/3.3/VariableVectorInput.cs

    r9226 r9242  
    2222using System;
    2323using System.Collections.Generic;
    24 using System.Drawing;
    2524using System.Linq;
    2625using System.Text;
     
    3332  [StorableClass]
    3433  [Item("VariableVectorInput", "")]
    35   public class VariableVectorInput : Dictionary<string, string>, IInput {
     34  public class VariableVectorInput : Item, IInput {
    3635
    37     public IOrderedEnumerable<string> Order { get { return this.Keys.OrderBy(x => x); } }
     36    [Storable]
     37    private Dictionary<string, string> inputDictionary;
     38    public Dictionary<string, string> InputDictionary {
     39      get { return inputDictionary; }
     40      protected set {
     41        inputDictionary = value;
     42      }
     43    }
     44
     45    public IOrderedEnumerable<string> Order { get { return InputDictionary.Keys.OrderBy(x => x); } }
    3846
    3947    [StorableConstructor]
    4048    protected VariableVectorInput(bool deserializing) { }
    4149    protected VariableVectorInput(VariableVectorInput original, Cloner cloner) {
    42       foreach (var item in original) {
    43         Add((string)item.Key.Clone(), (string)item.Value.Clone());
     50      InputDictionary = new Dictionary<string, string>(original.InputDictionary.Count);
     51      foreach (var item in original.InputDictionary) {
     52        InputDictionary.Add(item.Key, item.Value);
    4453      }
    4554    }
    46     public VariableVectorInput() : base() { }
    47     public VariableVectorInput(int capacity) : base(capacity) { }
    48     public VariableVectorInput(IDictionary<string, string> dictionary) : base(dictionary) { }
     55    public VariableVectorInput()
     56      : base() {
     57      InputDictionary = new Dictionary<string, string>();
     58    }
     59    public VariableVectorInput(int capacity)
     60      : base() {
     61      InputDictionary = new Dictionary<string, string>(capacity);
     62    }
     63    public VariableVectorInput(IDictionary<string, string> dictionary)
     64      : base() {
     65      InputDictionary = new Dictionary<string, string>(dictionary);
     66    }
     67    public override IDeepCloneable Clone(Cloner cloner) {
     68      return new VariableVectorInput(this, cloner);
     69    }
    4970
    5071    public override string ToString() {
    5172      StringBuilder sb = new StringBuilder();
    5273      bool first = true;
    53       foreach (var item in this) {
     74      foreach (var item in InputDictionary) {
    5475        if (first) {
    5576          first = false;
     
    6182      return sb.ToString();
    6283    }
    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) {
    81       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);
    97     }
    9884  }
    9985}
  • branches/LearningClassifierSystems/HeuristicLab.Problems.CombinedIntegerVectorClassification/3.3/CombinedIntegerVectorClassificationProblem.cs

    r9226 r9242  
    3737  public class CombinedIntegerVectorClassificationProblem : ConditionActionClassificationProblem<UniformRandomCombinedIntegerVectorCreator,
    3838                                                            CombinedIntegerVectorComparer,
    39                                                             CombinedIntegerVectorClassificationProblemData> {
     39                                                            CombinedIntegerVectorClassificationProblemData>, ICombinedIntegerVectorClassificationProblem {
    4040    public override string ChildName {
    4141      get { return "CombinedIntegerVector"; }
     
    5757        ProblemDataParameter.Value = value;
    5858        if (value != null) {
    59           SetProblemDataSpecificParameters();
     59          SetProblemDataSettings();
    6060        }
    6161      }
     
    9191      Parameters.Add(new FixedValueParameter<ItemSet<CombinedIntegerVector>>("PossibleActionsConcreteClass", new ItemSet<CombinedIntegerVector>(ClassifierComparer)));
    9292
    93       SetProblemDataSpecificParameters();
     93      SetProblemDataSettings();
    9494
    9595      InitializeOperators();
    96 
    97       problemData.Changed += new System.EventHandler(problemData_Changed);
    9896    }
    9997
    100     private void problemData_Changed(object sender, System.EventArgs e) {
    101       SetProblemDataSpecificParameters();
    102     }
    103 
    104     private void SetProblemDataSpecificParameters() {
    105       SolutionCreator.ActionPartLengthParameter.Value = ProblemData.ActionLengthParameter.Value;
    106       SolutionCreator.LengthParameter.Value = ProblemData.LengthParameter.Value;
    107       SolutionCreator.BoundsParameter.Value = ProblemData.BoundsParameter.Value;
     98    protected override void SetProblemDataSettings() {
     99      SolutionCreator.ProblemDataParameter.ActualName = ProblemDataParameter.Name;
    108100
    109101      SetPossibleActions();
  • branches/LearningClassifierSystems/HeuristicLab.Problems.CombinedIntegerVectorClassification/3.3/CombinedIntegerVectorClassificationProblemData.cs

    r9226 r9242  
    3636  [StorableClass]
    3737  [Item("CombinedIntegerVectorClassificationProblemData", "A problem data for LCS.")]
    38   public class CombinedIntegerVectorClassificationProblemData : ConditionActionClassificationProblemData {
     38  public class CombinedIntegerVectorClassificationProblemData : ConditionActionClassificationProblemData, ICombinedIntegerVectorClassificationProblemData {
    3939
    4040    #region parameter properites
  • branches/LearningClassifierSystems/HeuristicLab.Problems.ConditionActionClassification/3.3/ConditionActionClassificationProblem.cs

    r9226 r9242  
    2020#endregion
    2121
     22using System;
    2223using System.Linq;
    2324using HeuristicLab.Common;
     
    184185      InitializeOperators();
    185186
    186       problemData.Changed += new System.EventHandler(problemData_Changed);
    187     }
    188 
    189     private void problemData_Changed(object sender, System.EventArgs e) {
    190       SetPossibleActions();
    191     }
     187      //test event handlers after deserialization
     188      RegisterEventHandlers();
     189    }
     190
     191    private void RegisterEventHandlers() {
     192      ProblemDataParameter.ValueChanged += new EventHandler(ProblemDataParameter_ValueChanged);
     193      if (ProblemDataParameter.Value != null) ProblemDataParameter.Value.Changed += new EventHandler(ProblemData_Changed);
     194    }
     195
     196    private void ProblemDataParameter_ValueChanged(object sender, EventArgs e) {
     197      ProblemDataParameter.Value.Changed += new EventHandler(ProblemData_Changed);
     198      SetProblemDataSettings();
     199      OnReset();
     200    }
     201
     202    private void ProblemData_Changed(object sender, EventArgs e) {
     203      SetProblemDataSettings();
     204    }
     205
     206    protected abstract void SetProblemDataSettings();
    192207
    193208    private void InitializeOperators() {
  • branches/LearningClassifierSystems/HeuristicLab.Problems.Instances.ConditionActionClassification/3.3/HeuristicLab.Problems.Instances.ConditionActionClassification-3.3.csproj

    r9228 r9242  
    7979      <Private>False</Private>
    8080    </ProjectReference>
     81    <ProjectReference Include="..\..\HeuristicLab.Encodings.CombinedIntegerVectorEncoding\3.3\HeuristicLab.Encodings.CombinedIntegerVectorEncoding-3.3.csproj">
     82      <Project>{CE7163C5-BFFE-45F0-9BD0-E10EF24E8BD2}</Project>
     83      <Name>HeuristicLab.Encodings.CombinedIntegerVectorEncoding-3.3</Name>
     84    </ProjectReference>
    8185    <ProjectReference Include="..\..\HeuristicLab.Encodings.ConditionActionEncoding\3.3\HeuristicLab.Encodings.ConditionActionEncoding-3.3.csproj">
    8286      <Project>{422FB262-0845-4969-8D16-12F057AA90B1}</Project>
    8387      <Name>HeuristicLab.Encodings.ConditionActionEncoding-3.3</Name>
    8488      <Private>False</Private>
     89    </ProjectReference>
     90    <ProjectReference Include="..\..\HeuristicLab.Encodings.VariableVector\3.3\HeuristicLab.Encodings.VariableVector-3.3.csproj">
     91      <Project>{7C116F48-7218-4105-BD6E-EE868E2D4823}</Project>
     92      <Name>HeuristicLab.Encodings.VariableVector-3.3</Name>
    8593    </ProjectReference>
    8694    <ProjectReference Include="..\..\HeuristicLab.Problems.CombinedIntegerVectorClassification\3.3\HeuristicLab.Problems.CombinedIntegerVectorClassification-3.3.csproj">
  • branches/LearningClassifierSystems/HeuristicLab.Problems.Instances.ConditionActionClassification/3.3/VariableVectorCVSInstanceProvider.cs

    r9228 r9242  
    2222using System.Collections.Generic;
    2323using System.Linq;
    24 using HeuristicLab.Problems.CombinedIntegerVectorClassification;
    2524using HeuristicLab.Problems.DataAnalysis;
    2625using HeuristicLab.Problems.Instances.DataAnalysis;
     26using HeuristicLab.Problems.VariableVectorClassification;
    2727
    2828namespace HeuristicLab.Problems.Instances.ConditionActionClassification {
  • branches/LearningClassifierSystems/HeuristicLab.Problems.VariableVectorClassification/3.3/VariableVectorClassificationProblem.cs

    r9228 r9242  
    3333using HeuristicLab.Problems.DataAnalysis;
    3434
    35 namespace HeuristicLab.Problems.CombinedIntegerVectorClassification {
     35namespace HeuristicLab.Problems.VariableVectorClassification {
    3636  [StorableClass]
    3737  public class VariableVectorClassificationProblem : ConditionActionClassificationProblem<UniformRandomVariableVectorCreator,
    3838                                                            VariableVectorActionComparer,
    39                                                             VariableVectorClassificationProblemData> {
     39                                                            VariableVectorClassificationProblemData>, IVariableVectorClassificationProblem {
    4040    public override string ChildName {
    4141      get { return "VariableVector"; }
     
    4949      get { return (IFixedValueParameter<VariableVectorActionComparer>)Parameters["ClassifierComparer"]; }
    5050    }
     51    public IVariableVectorCoveringCreator VariableVectorCoveringCreator {
     52      get { return (IVariableVectorCoveringCreator)CoveringSolutionCreator; }
     53    }
    5154    #endregion
    5255
     
    5760        ProblemDataParameter.Value = value;
    5861        if (value != null) {
    59           SetProblemDataSpecificParameters();
     62          SetProblemDataSettings();
    6063        }
    6164      }
     
    9194      Parameters.Add(new FixedValueParameter<ItemSet<VariableVectorAction>>("PossibleActionsConcreteClass", new ItemSet<VariableVectorAction>(ClassifierComparer)));
    9295
    93       coveringSolutionCreator.SampleVariableVectorParameter.ActualName = problemData.SampleVariableVectorParameter.Name;
     96      SolutionCreator.VariableVectorParameter.ActualName = ChildName;
    9497
    95       SetProblemDataSpecificParameters();
     98      SetProblemDataSettings();
    9699
    97100      InitializeOperators();
    98 
    99       problemData.Changed += new System.EventHandler(problemData_Changed);
    100101    }
    101102
    102     private void problemData_Changed(object sender, System.EventArgs e) {
    103       SetProblemDataSpecificParameters();
    104     }
     103    protected override void SetProblemDataSettings() {
     104      SolutionCreator.ProblemDataParameter.ActualName = ProblemDataParameter.Name;
    105105
    106     private void SetProblemDataSpecificParameters() {
    107       SolutionCreator.SampleVariableVectorParameter.Value = ProblemData.SampleVariableVectorParameter.Value;
    108       SolutionCreator.VariableVectorParameter.ActualName = ChildName;
    109       SolutionCreator.SpreadPercentageParameter.Value = ProblemData.SpreadPercentageParameter.Value;
     106      VariableVectorCoveringCreator.ProblemDataParameter.ActualName = ProblemDataParameter.Name;
    110107
    111108      SetPossibleActions();
     
    130127      var sampleAction = ProblemData.SampleVariableVector.Action;
    131128      var actionKeys = sampleAction.Order;
    132       var actionsEnumeratorList = sampleAction.ToDictionary(x => x.Key, y => y.Value.GetAllPossibleActions().ToList());
     129      var actionsEnumeratorList = sampleAction.VariableDictionary.ToDictionary(x => x.Key, y => y.Value.GetAllPossibleActions().ToList());
    133130      int[] curPos = new int[actionsEnumeratorList.Count];
    134131      //initialize curPos
     
    145142        cur = 0;
    146143        foreach (var key in actionKeys) {
    147           curAction[key].SetTo(actionsEnumeratorList[key][curPos[cur]]);
     144          curAction.VariableDictionary[key].SetTo(actionsEnumeratorList[key][curPos[cur]]);
    148145          cur++;
    149146        }
  • branches/LearningClassifierSystems/HeuristicLab.Problems.VariableVectorClassification/3.3/VariableVectorClassificationProblemData.cs

    r9228 r9242  
    3333using HeuristicLab.Problems.DataAnalysis;
    3434
    35 namespace HeuristicLab.Problems.CombinedIntegerVectorClassification {
     35namespace HeuristicLab.Problems.VariableVectorClassification {
    3636  [StorableClass]
    3737  [Item("CombinedIntegerVectorClassificationProblemData", "A problem data for LCS.")]
    38   public class VariableVectorClassificationProblemData : ConditionActionClassificationProblemData {
     38  public class VariableVectorClassificationProblemData : ConditionActionClassificationProblemData, IVariableVectorClassificationProblemData {
    3939
    4040    #region parameter properites
     
    9090          var doubleValues = (variableValues as List<double>).Distinct();
    9191          if (doubleValues.All(x => x % 1 == 0)) {
    92             variable = new IntVariable(variableName, doubleValues.Select(x => Convert.ToInt32(x)));
     92            // ToList call is necessary, because otherwise it wouldn't be possible to serialize it
     93            variable = new IntVariable(variableName, doubleValues.Select(x => Convert.ToInt32(x)).ToList());
    9394          } else {
    9495            variable = new DoubleVariable(variableName, doubleValues);
     
    105106      if (!fetchInputCache.ContainsKey(rowNumber)) {
    106107        VariableVectorInput input = new VariableVectorInput();
    107         IEnumerable<string> variableNames = SampleVariableVector.Condition.Keys.Union(SampleVariableVector.Action.Keys);
     108        IEnumerable<string> variableNames = SampleVariableVector.Condition.VariableDictionary.Keys.Union(SampleVariableVector.Action.VariableDictionary.Keys);
    108109        foreach (var variableName in variableNames) {
    109           input.Add(variableName, Dataset.GetValue(rowNumber, variableName));
     110          input.InputDictionary.Add(variableName, Dataset.GetValue(rowNumber, variableName));
    110111        }
    111112        fetchInputCache.Add(rowNumber, input);
     
    118119      if (!fetchActionCache.ContainsKey(rowNumber)) {
    119120        var action = SampleVariableVector.Action.GetEmptyCopy();
    120         foreach (var variableName in action.Keys) {
    121           action[variableName].SetTo(Dataset.GetValue(rowNumber, variableName));
     121        foreach (var variableName in action.VariableDictionary.Keys) {
     122          action.VariableDictionary[variableName].SetTo(Dataset.GetValue(rowNumber, variableName));
    122123        }
    123124        fetchActionCache.Add(rowNumber, action);
Note: See TracChangeset for help on using the changeset viewer.