Free cookie consent management tool by TermsFeed Policy Generator

Ignore:
Timestamp:
06/12/15 15:35:16 (9 years ago)
Author:
mkommend
Message:

#2276: Merged trunk changes into dataset refactoring branch.

Location:
branches/HeuristicLab.DatasetRefactor/sources
Files:
36 edited
3 copied

Legend:

Unmodified
Added
Removed
  • branches/HeuristicLab.DatasetRefactor/sources

  • branches/HeuristicLab.DatasetRefactor/sources/HeuristicLab.Encodings.SymbolicExpressionTreeEncoding

  • branches/HeuristicLab.DatasetRefactor/sources/HeuristicLab.Encodings.SymbolicExpressionTreeEncoding/3.4/Analyzers/SymbolicExpressionTreeLengthAnalyzer.cs

    r12031 r12438  
    5151      get { return (IScopeTreeLookupParameter<ISymbolicExpressionTree>)Parameters[SymbolicExpressionTreeParameterName]; }
    5252    }
     53
     54    public ILookupParameter<IntValue> MaximumSymbolicExpressionTreeLengthParameter {
     55      get { return (ILookupParameter<IntValue>)Parameters[MaximumSymbolicExpressionTreeLengthParameterName]; }
     56    }
    5357    public ValueLookupParameter<DataTable> SymbolicExpressionTreeLengthsParameter {
    5458      get { return (ValueLookupParameter<DataTable>)Parameters[SymbolicExpressionTreeLengthsParameterName]; }
     
    178182        }
    179183
    180         double maximumAllowedTreeLength = ((LookupParameter<IntValue>)Parameters[MaximumSymbolicExpressionTreeLengthParameterName]).ActualValue.Value;
     184        double maximumAllowedTreeLength = MaximumSymbolicExpressionTreeLengthParameter.ActualValue.Value;
    181185
    182186        treeLengthsTableRow.VisualProperties.ChartType = DataRowVisualProperties.DataRowChartType.Histogram;
  • branches/HeuristicLab.DatasetRefactor/sources/HeuristicLab.Encodings.SymbolicExpressionTreeEncoding/3.4/ArchitectureManipulators/ArgumentCreater.cs

    r12031 r12438  
    2828using HeuristicLab.Parameters;
    2929using HeuristicLab.Persistence.Default.CompositeSerializers.Storable;
     30using HeuristicLab.Random;
    3031
    3132namespace HeuristicLab.Encodings.SymbolicExpressionTreeEncoding {
     
    8485      ISymbolicExpressionTree clonedTree = (ISymbolicExpressionTree)symbolicExpressionTree.Clone();
    8586
    86       var functionDefiningBranches = clonedTree.IterateNodesPrefix().OfType<DefunTreeNode>();
    87       if (functionDefiningBranches.Count() == 0)
     87      var functionDefiningBranches = clonedTree.IterateNodesPrefix().OfType<DefunTreeNode>().ToList();
     88      if (!functionDefiningBranches.Any())
    8889        // no function defining branch found => abort
    8990        return false;
    9091
    9192      // select a random function defining branch
    92       var selectedDefunBranch = functionDefiningBranches.SelectRandom(random);
     93      var selectedDefunBranch = functionDefiningBranches.SampleRandom(random);
     94
    9395      var definedArguments = (from symbol in selectedDefunBranch.Grammar.Symbols.OfType<Argument>()
    9496                              select symbol.ArgumentIndex).Distinct();
  • branches/HeuristicLab.DatasetRefactor/sources/HeuristicLab.Encodings.SymbolicExpressionTreeEncoding/3.4/ArchitectureManipulators/ArgumentDeleter.cs

    r12031 r12438  
    2525using HeuristicLab.Data;
    2626using HeuristicLab.Persistence.Default.CompositeSerializers.Storable;
     27using HeuristicLab.Random;
    2728
    2829namespace HeuristicLab.Encodings.SymbolicExpressionTreeEncoding {
     
    5455      int maxFunctionDefinitions, int maxFunctionArguments) {
    5556
    56       var functionDefiningBranches = symbolicExpressionTree.IterateNodesPrefix().OfType<DefunTreeNode>();
    57       if (functionDefiningBranches.Count() == 0)
     57      var functionDefiningBranches = symbolicExpressionTree.IterateNodesPrefix().OfType<DefunTreeNode>().ToList();
     58      if (!functionDefiningBranches.Any())
    5859        // no function defining branch => abort
    5960        return false;
    60       var selectedDefunBranch = functionDefiningBranches.SelectRandom(random);
     61
     62      var selectedDefunBranch = functionDefiningBranches.SampleRandom(random);
    6163      if (selectedDefunBranch.NumberOfArguments <= 1)
    6264        // argument deletion by consolidation is not possible => abort
     
    7779
    7880      // delete the dynamic argument symbol that matches the argument to be removed
    79       var matchingSymbol = selectedDefunBranch.Grammar.Symbols.OfType<Argument>().Where(s => s.ArgumentIndex == removedArgument).Single();
     81      var matchingSymbol = selectedDefunBranch.Grammar.Symbols.OfType<Argument>().Single(s => s.ArgumentIndex == removedArgument);
    8082      selectedDefunBranch.Grammar.RemoveSymbol(matchingSymbol);
    8183      selectedDefunBranch.NumberOfArguments--;
    8284      // reduce arity in known functions of all root branches
    8385      foreach (var subtree in symbolicExpressionTree.Root.Subtrees) {
    84         var matchingInvokeSymbol = subtree.Grammar.Symbols.OfType<InvokeFunction>().Where(s => s.FunctionName == selectedDefunBranch.FunctionName).SingleOrDefault();
     86        var matchingInvokeSymbol = subtree.Grammar.Symbols.OfType<InvokeFunction>().SingleOrDefault(s => s.FunctionName == selectedDefunBranch.FunctionName);
    8587        if (matchingInvokeSymbol != null) {
    8688          subtree.Grammar.SetSubtreeCount(matchingInvokeSymbol, selectedDefunBranch.NumberOfArguments, selectedDefunBranch.NumberOfArguments);
     
    99101                     select node;
    100102      foreach (var argNode in argNodes) {
    101         var replacementSymbol = possibleArgumentSymbols.SelectRandom(random);
     103        var replacementSymbol = possibleArgumentSymbols.SampleRandom(random);
    102104        argNode.Symbol = replacementSymbol;
    103105      }
  • branches/HeuristicLab.DatasetRefactor/sources/HeuristicLab.Encodings.SymbolicExpressionTreeEncoding/3.4/ArchitectureManipulators/ArgumentDuplicater.cs

    r12031 r12438  
    2727using HeuristicLab.Data;
    2828using HeuristicLab.Persistence.Default.CompositeSerializers.Storable;
     29using HeuristicLab.Random;
    2930
    3031namespace HeuristicLab.Encodings.SymbolicExpressionTreeEncoding {
     
    5657      ISymbolicExpressionTree symbolicExpressionTree,
    5758      int maxFunctionDefinitions, int maxFunctionArguments) {
    58       var functionDefiningBranches = symbolicExpressionTree.IterateNodesPrefix().OfType<DefunTreeNode>();
     59      var functionDefiningBranches = symbolicExpressionTree.IterateNodesPrefix().OfType<DefunTreeNode>().ToList();
    5960
    6061      var allowedArgumentIndexes = Enumerable.Range(0, maxFunctionArguments);
    61       if (functionDefiningBranches.Count() == 0)
     62      if (!functionDefiningBranches.Any())
    6263        // no function defining branches => abort
    6364        return false;
    6465
    65       var selectedDefunBranch = functionDefiningBranches.SelectRandom(random);
    66       var argumentSymbols = selectedDefunBranch.Grammar.Symbols.OfType<Argument>();
    67       if (argumentSymbols.Count() == 0 || argumentSymbols.Count() >= maxFunctionArguments)
     66      var selectedDefunBranch = functionDefiningBranches.SampleRandom(random);
     67
     68      var argumentSymbols = selectedDefunBranch.Grammar.Symbols.OfType<Argument>().ToList();
     69      if (!argumentSymbols.Any() || argumentSymbols.Count() >= maxFunctionArguments)
    6870        // when no argument or number of arguments is already at max allowed value => abort
    6971        return false;
    70       var selectedArgumentSymbol = argumentSymbols.SelectRandom(random);
     72
     73      var selectedArgumentSymbol = argumentSymbols.SampleRandom(random);
    7174      var takenIndexes = argumentSymbols.Select(s => s.ArgumentIndex);
    7275      var newArgumentIndex = allowedArgumentIndexes.Except(takenIndexes).First();
  • branches/HeuristicLab.DatasetRefactor/sources/HeuristicLab.Encodings.SymbolicExpressionTreeEncoding/3.4/ArchitectureManipulators/SubroutineCreater.cs

    r12031 r12438  
    2929using HeuristicLab.Parameters;
    3030using HeuristicLab.Persistence.Default.CompositeSerializers.Storable;
     31using HeuristicLab.Random;
    3132
    3233namespace HeuristicLab.Encodings.SymbolicExpressionTreeEncoding {
     
    113114                          from subtree in parent.Subtrees
    114115                          select new CutPoint(parent, subtree)).ToList();
    115       if (allCutPoints.Count() == 0)
     116      if (!allCutPoints.Any())
    116117        // no cut points => abort
    117118        return false;
    118119      string newFunctionName = allowedFunctionNames.Except(functionDefiningBranches.Select(x => x.FunctionName)).First();
    119       var selectedCutPoint = allCutPoints.SelectRandom(random);
     120      var selectedCutPoint = allCutPoints.SampleRandom(random);
     121
    120122      // select random branches as argument cut-off points (replaced by argument terminal nodes in the function)
    121123      List<CutPoint> argumentCutPoints = SelectRandomArgumentBranches(selectedCutPoint.Child, random, ARGUMENT_CUTOFF_PROBABILITY, maxFunctionArguments);
  • branches/HeuristicLab.DatasetRefactor/sources/HeuristicLab.Encodings.SymbolicExpressionTreeEncoding/3.4/ArchitectureManipulators/SubroutineDeleter.cs

    r12031 r12438  
    2626using HeuristicLab.Data;
    2727using HeuristicLab.Persistence.Default.CompositeSerializers.Storable;
     28using HeuristicLab.Random;
    2829
    2930namespace HeuristicLab.Encodings.SymbolicExpressionTreeEncoding {
     
    5556      ISymbolicExpressionTree symbolicExpressionTree,
    5657      int maxFunctionDefinitions, int maxFunctionArguments) {
    57       var functionDefiningBranches = symbolicExpressionTree.IterateNodesPrefix().OfType<DefunTreeNode>();
     58      var functionDefiningBranches = symbolicExpressionTree.IterateNodesPrefix().OfType<DefunTreeNode>().ToList();
    5859
    59       if (functionDefiningBranches.Count() == 0)
     60      if (!functionDefiningBranches.Any())
    6061        // no ADF to delete => abort
    6162        return false;
    62       var selectedDefunBranch = functionDefiningBranches.SelectRandom(random);
     63
     64      var selectedDefunBranch = functionDefiningBranches.SampleRandom(random);
    6365      // remove the selected defun
    6466      int defunSubtreeIndex = symbolicExpressionTree.Root.IndexOfSubtree(selectedDefunBranch);
     
    9294        var allowedSymbolsList = invocationCutPoint.Parent.Grammar.GetAllowedChildSymbols(invocationCutPoint.Parent.Symbol, invocationCutPoint.ChildIndex).ToList();
    9395        var weights = allowedSymbolsList.Select(s => s.InitialFrequency);
     96
     97#pragma warning disable 612, 618
    9498        var selectedSymbol = allowedSymbolsList.SelectRandom(weights, random);
     99#pragma warning restore 612, 618
     100
    95101
    96102        int minPossibleLength = invocationCutPoint.Parent.Grammar.GetMinimumExpressionLength(selectedSymbol);
  • branches/HeuristicLab.DatasetRefactor/sources/HeuristicLab.Encodings.SymbolicExpressionTreeEncoding/3.4/ArchitectureManipulators/SubroutineDuplicater.cs

    r12031 r12438  
    2828using HeuristicLab.Data;
    2929using HeuristicLab.Persistence.Default.CompositeSerializers.Storable;
     30using HeuristicLab.Random;
    3031
    3132namespace HeuristicLab.Encodings.SymbolicExpressionTreeEncoding {
     
    5960      ISymbolicExpressionTree symbolicExpressionTree,
    6061      int maxFunctionDefinitions, int maxFunctionArguments) {
    61       var functionDefiningBranches = symbolicExpressionTree.IterateNodesPrefix().OfType<DefunTreeNode>();
    62       if (functionDefiningBranches.Count() == 0 || functionDefiningBranches.Count() == maxFunctionDefinitions)
     62      var functionDefiningBranches = symbolicExpressionTree.IterateNodesPrefix().OfType<DefunTreeNode>().ToList();
     63      if (!functionDefiningBranches.Any() || functionDefiningBranches.Count() == maxFunctionDefinitions)
    6364        // no function defining branches to duplicate or already reached the max number of ADFs
    6465        return false;
     
    6768      var allowedFunctionNames = from index in Enumerable.Range(0, maxFunctionDefinitions)
    6869                                 select "ADF" + index.ToString(formatString);
    69       var selectedBranch = functionDefiningBranches.SelectRandom(random);
     70
     71      var selectedBranch = functionDefiningBranches.SampleRandom(random);
    7072      var duplicatedDefunBranch = (DefunTreeNode)selectedBranch.Clone();
    7173      string newFunctionName = allowedFunctionNames.Except(UsedFunctionNames(symbolicExpressionTree)).First();
  • branches/HeuristicLab.DatasetRefactor/sources/HeuristicLab.Encodings.SymbolicExpressionTreeEncoding/3.4/Creators/FullTreeCreator.cs

    r12031 r12438  
    2424using HeuristicLab.Common;
    2525using HeuristicLab.Core;
    26 using HeuristicLab.Data;
    27 using HeuristicLab.Parameters;
    2826using HeuristicLab.Persistence.Default.CompositeSerializers.Storable;
    2927using HeuristicLab.PluginInfrastructure;
     
    3634                                 ISymbolicExpressionTreeSizeConstraintOperator,
    3735                                 ISymbolicExpressionTreeGrammarBasedOperator {
    38     private const string MaximumSymbolicExpressionTreeLengthParameterName = "MaximumSymbolicExpressionTreeLength";
    39     private const string MaximumSymbolicExpressionTreeDepthParameterName = "MaximumSymbolicExpressionTreeDepth";
    40 
    41     #region Parameter Properties
    42     public IValueLookupParameter<IntValue> MaximumSymbolicExpressionTreeLengthParameter {
    43       get { return (IValueLookupParameter<IntValue>)Parameters[MaximumSymbolicExpressionTreeLengthParameterName]; }
    44     }
    45 
    46     public IValueLookupParameter<IntValue> MaximumSymbolicExpressionTreeDepthParameter {
    47       get { return (IValueLookupParameter<IntValue>)Parameters[MaximumSymbolicExpressionTreeDepthParameterName]; }
    48     }
    49     #endregion
    50     #region Properties
    51     public IntValue MaximumSymbolicExpressionTreeDepth {
    52       get { return MaximumSymbolicExpressionTreeDepthParameter.ActualValue; }
    53     }
    54 
    55     public IntValue MaximumSymbolicExpressionTreeLength {
    56       get { return MaximumSymbolicExpressionTreeLengthParameter.ActualValue; }
    57     }
    58 
    59     #endregion
    6036
    6137    [StorableConstructor]
     
    6339    protected FullTreeCreator(FullTreeCreator original, Cloner cloner) : base(original, cloner) { }
    6440
    65     public FullTreeCreator()
    66       : base() {
    67       Parameters.Add(new ValueLookupParameter<IntValue>(MaximumSymbolicExpressionTreeLengthParameterName,
    68         "The maximal length (number of nodes) of the symbolic expression tree (this parameter is ignored)."));
    69       Parameters.Add(new ValueLookupParameter<IntValue>(MaximumSymbolicExpressionTreeDepthParameterName,
    70         "The maximal depth of the symbolic expression tree (a tree with one node has depth = 0)."));
    71     }
     41    public FullTreeCreator() : base() { }
    7242
    7343    public override IDeepCloneable Clone(Cloner cloner) {
     
    7747
    7848    protected override ISymbolicExpressionTree Create(IRandom random) {
    79       return Create(random, ClonedSymbolicExpressionTreeGrammarParameter.ActualValue, MaximumSymbolicExpressionTreeLength.Value, MaximumSymbolicExpressionTreeDepth.Value);
     49      return Create(random, ClonedSymbolicExpressionTreeGrammarParameter.ActualValue,
     50          MaximumSymbolicExpressionTreeLengthParameter.ActualValue.Value, MaximumSymbolicExpressionTreeDepthParameter.ActualValue.Value);
    8051    }
    8152
     
    131102          .ToList();
    132103        var weights = possibleSymbols.Select(s => s.InitialFrequency).ToList();
     104
     105#pragma warning disable 612, 618
    133106        var selectedSymbol = possibleSymbols.SelectRandom(weights, random);
     107#pragma warning restore 612, 618
     108
    134109        var tree = selectedSymbol.CreateTreeNode();
    135110        if (tree.HasLocalParameters) tree.ResetLocalParameters(random);
     
    163138          throw new InvalidOperationException("No symbols are available for the tree.");
    164139        var weights = possibleSymbols.Select(s => s.InitialFrequency).ToList();
     140
     141#pragma warning disable 612, 618
    165142        var selectedSymbol = possibleSymbols.SelectRandom(weights, random);
     143#pragma warning restore 612, 618
     144       
    166145        var tree = selectedSymbol.CreateTreeNode();
    167146        if (tree.HasLocalParameters) tree.ResetLocalParameters(random);
     
    169148      }
    170149
    171       foreach (var subTree in root.Subtrees)
    172         if (subTree.Grammar.GetMaximumSubtreeCount(subTree.Symbol) > 0)
    173           RecursiveCreate(random, subTree, currentDepth + 1, maxDepth);
     150      //additional levels should only be added if the maximum depth is not reached yet
     151      if (maxDepth > currentDepth) {
     152        foreach (var subTree in root.Subtrees)
     153          if (subTree.Grammar.GetMaximumSubtreeCount(subTree.Symbol) > 0)
     154            RecursiveCreate(random, subTree, currentDepth + 1, maxDepth);
     155      }
    174156    }
    175157  }
  • branches/HeuristicLab.DatasetRefactor/sources/HeuristicLab.Encodings.SymbolicExpressionTreeEncoding/3.4/Creators/GrowTreeCreator.cs

    r12031 r12438  
    2424using HeuristicLab.Common;
    2525using HeuristicLab.Core;
    26 using HeuristicLab.Data;
    27 using HeuristicLab.Parameters;
    2826using HeuristicLab.Persistence.Default.CompositeSerializers.Storable;
    2927using HeuristicLab.PluginInfrastructure;
     
    3331  [StorableClass]
    3432  [Item("GrowTreeCreator", "An operator that creates new symbolic expression trees using the 'Grow' method")]
    35   public class GrowTreeCreator : SymbolicExpressionTreeCreator,
    36                                  ISymbolicExpressionTreeSizeConstraintOperator,
    37                                  ISymbolicExpressionTreeGrammarBasedOperator {
    38     private const string MaximumSymbolicExpressionTreeLengthParameterName = "MaximumSymbolicExpressionTreeLength";
    39     private const string MaximumSymbolicExpressionTreeDepthParameterName = "MaximumSymbolicExpressionTreeDepth";
    40 
    41     #region Parameter Properties
    42     public IValueLookupParameter<IntValue> MaximumSymbolicExpressionTreeLengthParameter {
    43       get { return (IValueLookupParameter<IntValue>)Parameters[MaximumSymbolicExpressionTreeLengthParameterName]; }
    44     }
    45 
    46     public IValueLookupParameter<IntValue> MaximumSymbolicExpressionTreeDepthParameter {
    47       get { return (IValueLookupParameter<IntValue>)Parameters[MaximumSymbolicExpressionTreeDepthParameterName]; }
    48     }
    49 
    50     #endregion
    51     #region Properties
    52     public IntValue MaximumSymbolicExpressionTreeDepth {
    53       get { return MaximumSymbolicExpressionTreeDepthParameter.ActualValue; }
    54     }
    55 
    56     public IntValue MaximumSymbolicExpressionTreeLength {
    57       get { return MaximumSymbolicExpressionTreeLengthParameter.ActualValue; }
    58     }
    59     #endregion
    60 
     33  public class GrowTreeCreator : SymbolicExpressionTreeCreator {
    6134    [StorableConstructor]
    6235    protected GrowTreeCreator(bool deserializing) : base(deserializing) { }
    6336    protected GrowTreeCreator(GrowTreeCreator original, Cloner cloner) : base(original, cloner) { }
    6437
    65     public GrowTreeCreator()
    66       : base() {
    67       Parameters.Add(new ValueLookupParameter<IntValue>(MaximumSymbolicExpressionTreeLengthParameterName,
    68         "The maximal length (number of nodes) of the symbolic expression tree (this parameter is ignored)."));
    69       Parameters.Add(new ValueLookupParameter<IntValue>(MaximumSymbolicExpressionTreeDepthParameterName,
    70         "The maximal depth of the symbolic expression tree (a tree with one node has depth = 0)."));
    71     }
     38    public GrowTreeCreator() : base() { }
    7239
    7340    public override IDeepCloneable Clone(Cloner cloner) {
     
    7845    protected override ISymbolicExpressionTree Create(IRandom random) {
    7946      return Create(random, ClonedSymbolicExpressionTreeGrammarParameter.ActualValue,
    80         MaximumSymbolicExpressionTreeLength.Value, MaximumSymbolicExpressionTreeDepth.Value);
     47        MaximumSymbolicExpressionTreeLengthParameter.ActualValue.Value, MaximumSymbolicExpressionTreeDepthParameter.ActualValue.Value);
    8148    }
    8249
     
    12289        throw new ArgumentException("Cannot grow tree. Seed node shouldn't have arity zero.");
    12390
    124       var allowedSymbols = seedNode.Grammar.AllowedSymbols
    125         .Where(s => s.InitialFrequency > 0.0)
    126         .ToList();
     91      var allowedSymbols = seedNode.Grammar.AllowedSymbols.Where(s => s.InitialFrequency > 0.0).ToList();
    12792
    12893      for (var i = 0; i < arity; i++) {
    129         var possibleSymbols = allowedSymbols
    130           .Where(s => seedNode.Grammar.IsAllowedChildSymbol(seedNode.Symbol, s, i))
    131           .ToList();
     94        var possibleSymbols = allowedSymbols.Where(s => seedNode.Grammar.IsAllowedChildSymbol(seedNode.Symbol, s, i)).ToList();
    13295        var weights = possibleSymbols.Select(s => s.InitialFrequency).ToList();
     96
     97#pragma warning disable 612, 618
    13398        var selectedSymbol = possibleSymbols.SelectRandom(weights, random);
     99#pragma warning restore 612, 618
     100
    134101        var tree = selectedSymbol.CreateTreeNode();
    135102        if (tree.HasLocalParameters) tree.ResetLocalParameters(random);
     
    146113    private static void RecursiveCreate(IRandom random, ISymbolicExpressionTreeNode root, int currentDepth, int maxDepth) {
    147114      var arity = SampleArity(random, root);
    148       if (arity <= 0)
    149         throw new ArgumentException("Cannot grow node of arity zero. Expected a function node.");
     115      if (arity == 0)
     116        return;
    150117
    151118      var allowedSymbols = root.Grammar.AllowedSymbols.Where(s => s.InitialFrequency > 0.0).ToList();
    152119
    153120      for (var i = 0; i < arity; i++) {
    154         var possibleSymbols = allowedSymbols
    155           .Where(s => root.Grammar.IsAllowedChildSymbol(root.Symbol, s, i) &&
    156             root.Grammar.GetMinimumExpressionDepth(s) - 1 <= maxDepth - currentDepth)
    157           .ToList();
     121        var possibleSymbols = allowedSymbols.Where(s => root.Grammar.IsAllowedChildSymbol(root.Symbol, s, i) &&
     122                                                        root.Grammar.GetMinimumExpressionDepth(s) - 1 <= maxDepth - currentDepth).ToList();
    158123
    159124        if (!possibleSymbols.Any())
    160125          throw new InvalidOperationException("No symbols are available for the tree.");
     126
    161127        var weights = possibleSymbols.Select(s => s.InitialFrequency).ToList();
     128#pragma warning disable 612, 618
    162129        var selectedSymbol = possibleSymbols.SelectRandom(weights, random);
     130#pragma warning restore 612, 618
     131
    163132        var tree = selectedSymbol.CreateTreeNode();
    164133        if (tree.HasLocalParameters) tree.ResetLocalParameters(random);
     
    166135      }
    167136
    168       foreach (var subTree in root.Subtrees)
    169         if (subTree.Grammar.GetMaximumSubtreeCount(subTree.Symbol) != 0)
    170           RecursiveCreate(random, subTree, currentDepth + 1, maxDepth);
     137      if (maxDepth > currentDepth)
     138        foreach (var subTree in root.Subtrees)
     139          if (subTree.Grammar.GetMaximumSubtreeCount(subTree.Symbol) != 0)
     140            RecursiveCreate(random, subTree, currentDepth + 1, maxDepth);
    171141    }
    172142
  • branches/HeuristicLab.DatasetRefactor/sources/HeuristicLab.Encodings.SymbolicExpressionTreeEncoding/3.4/Creators/ProbabilisticTreeCreator.cs

    r12031 r12438  
    2525using HeuristicLab.Common;
    2626using HeuristicLab.Core;
    27 using HeuristicLab.Data;
    28 using HeuristicLab.Parameters;
    2927using HeuristicLab.Persistence.Default.CompositeSerializers.Storable;
    3028using HeuristicLab.PluginInfrastructure;
     
    3735    ISymbolicExpressionTreeSizeConstraintOperator, ISymbolicExpressionTreeGrammarBasedOperator {
    3836    private const int MAX_TRIES = 100;
    39     private const string MaximumSymbolicExpressionTreeLengthParameterName = "MaximumSymbolicExpressionTreeLength";
    40     private const string MaximumSymbolicExpressionTreeDepthParameterName = "MaximumSymbolicExpressionTreeDepth";
    41     #region Parameter Properties
    42     public IValueLookupParameter<IntValue> MaximumSymbolicExpressionTreeLengthParameter {
    43       get { return (IValueLookupParameter<IntValue>)Parameters[MaximumSymbolicExpressionTreeLengthParameterName]; }
    44     }
    45     public IValueLookupParameter<IntValue> MaximumSymbolicExpressionTreeDepthParameter {
    46       get { return (IValueLookupParameter<IntValue>)Parameters[MaximumSymbolicExpressionTreeDepthParameterName]; }
    47     }
    48     #endregion
    49     #region Properties
    50     public IntValue MaximumSymbolicExpressionTreeLength {
    51       get { return MaximumSymbolicExpressionTreeLengthParameter.ActualValue; }
    52     }
    53     public IntValue MaximumSymbolicExpressionTreeDepth {
    54       get { return MaximumSymbolicExpressionTreeDepthParameter.ActualValue; }
    55     }
    56     #endregion
    5737
    5838    [StorableConstructor]
     
    6141    public ProbabilisticTreeCreator()
    6242      : base() {
    63       Parameters.Add(new ValueLookupParameter<IntValue>(MaximumSymbolicExpressionTreeLengthParameterName, "The maximal length (number of nodes) of the symbolic expression tree."));
    64       Parameters.Add(new ValueLookupParameter<IntValue>(MaximumSymbolicExpressionTreeDepthParameterName, "The maximal depth of the symbolic expression tree (a tree with one node has depth = 0)."));
     43
    6544    }
    6645
     
    7150
    7251    protected override ISymbolicExpressionTree Create(IRandom random) {
    73       return Create(random, ClonedSymbolicExpressionTreeGrammarParameter.ActualValue, MaximumSymbolicExpressionTreeLength.Value, MaximumSymbolicExpressionTreeDepth.Value);
     52      return Create(random, ClonedSymbolicExpressionTreeGrammarParameter.ActualValue,
     53        MaximumSymbolicExpressionTreeLengthParameter.ActualValue.Value, MaximumSymbolicExpressionTreeDepthParameter.ActualValue.Value);
    7454    }
    7555
     
    186166          if (allowedSymbols.Count == 0) return false;
    187167          var weights = allowedSymbols.Select(x => x.InitialFrequency).ToList();
     168
     169#pragma warning disable 612, 618
    188170          var selectedSymbol = allowedSymbols.SelectRandom(weights, random);
     171#pragma warning restore 612, 618
     172
    189173          ISymbolicExpressionTreeNode newTree = selectedSymbol.CreateTreeNode();
    190174          if (newTree.HasLocalParameters) newTree.ResetLocalParameters(random);
     
    232216                             select g).First().ToList();
    233217      var weights = possibleSymbols.Select(x => x.InitialFrequency).ToList();
     218
     219#pragma warning disable 612, 618
    234220      var selectedSymbol = possibleSymbols.SelectRandom(weights, random);
     221#pragma warning restore 612, 618
     222
    235223      var tree = selectedSymbol.CreateTreeNode();
    236224      if (tree.HasLocalParameters) tree.ResetLocalParameters(random);
  • branches/HeuristicLab.DatasetRefactor/sources/HeuristicLab.Encodings.SymbolicExpressionTreeEncoding/3.4/Creators/RampedHalfAndHalfTreeCreator.cs

    r12031 r12438  
    2222using HeuristicLab.Common;
    2323using HeuristicLab.Core;
    24 using HeuristicLab.Data;
    25 using HeuristicLab.Parameters;
    2624using HeuristicLab.Persistence.Default.CompositeSerializers.Storable;
    2725using HeuristicLab.PluginInfrastructure;
     
    3129  [StorableClass]
    3230  [Item("RampedHalfAndHalfTreeCreator", "An operator that creates new symbolic expression trees in an alternate way: half the trees are created usign the 'Grow' method while the other half are created using the 'Full' method")]
    33   public class RampedHalfAndHalfTreeCreator : SymbolicExpressionTreeCreator,
    34                                  ISymbolicExpressionTreeSizeConstraintOperator,
    35                                  ISymbolicExpressionTreeGrammarBasedOperator {
    36     private const string MaximumSymbolicExpressionTreeLengthParameterName = "MaximumSymbolicExpressionTreeLength";
    37     private const string MaximumSymbolicExpressionTreeDepthParameterName = "MaximumSymbolicExpressionTreeDepth";
    38 
    39     #region Parameter Properties
    40     public IValueLookupParameter<IntValue> MaximumSymbolicExpressionTreeLengthParameter {
    41       get { return (IValueLookupParameter<IntValue>)Parameters[MaximumSymbolicExpressionTreeLengthParameterName]; }
    42     }
    43 
    44     public IValueLookupParameter<IntValue> MaximumSymbolicExpressionTreeDepthParameter {
    45       get { return (IValueLookupParameter<IntValue>)Parameters[MaximumSymbolicExpressionTreeDepthParameterName]; }
    46     }
    47 
    48     #endregion
    49     #region Properties
    50     public IntValue MaximumSymbolicExpressionTreeDepth {
    51       get { return MaximumSymbolicExpressionTreeDepthParameter.ActualValue; }
    52     }
    53 
    54     public IntValue MaximumSymbolicExpressionTreeLength {
    55       get { return MaximumSymbolicExpressionTreeLengthParameter.ActualValue; }
    56     }
    57     #endregion
    58 
     31  public class RampedHalfAndHalfTreeCreator : SymbolicExpressionTreeCreator {
    5932    [StorableConstructor]
    6033    protected RampedHalfAndHalfTreeCreator(bool deserializing) : base(deserializing) { }
    6134    protected RampedHalfAndHalfTreeCreator(RampedHalfAndHalfTreeCreator original, Cloner cloner) : base(original, cloner) { }
    6235
    63     public RampedHalfAndHalfTreeCreator()
    64       : base() {
    65       Parameters.Add(new ValueLookupParameter<IntValue>(MaximumSymbolicExpressionTreeLengthParameterName,
    66         "The maximal length (number of nodes) of the symbolic expression tree (this parameter is ignored)."));
    67       Parameters.Add(new ValueLookupParameter<IntValue>(MaximumSymbolicExpressionTreeDepthParameterName,
    68         "The maximal depth of the symbolic expression tree (a tree with one node has depth = 0)."));
    69     }
     36    public RampedHalfAndHalfTreeCreator() : base() { }
    7037
    7138    public override IDeepCloneable Clone(Cloner cloner) {
     
    7441
    7542    protected override ISymbolicExpressionTree Create(IRandom random) {
    76       return Create(random, ClonedSymbolicExpressionTreeGrammarParameter.ActualValue, MaximumSymbolicExpressionTreeLength.Value, MaximumSymbolicExpressionTreeDepth.Value);
     43      return Create(random, ClonedSymbolicExpressionTreeGrammarParameter.ActualValue,
     44        MaximumSymbolicExpressionTreeLengthParameter.ActualValue.Value, MaximumSymbolicExpressionTreeDepthParameter.ActualValue.Value);
    7745    }
    7846
  • branches/HeuristicLab.DatasetRefactor/sources/HeuristicLab.Encodings.SymbolicExpressionTreeEncoding/3.4/Creators/SymbolicExpressionTreeCreator.cs

    r12031 r12438  
    2222using HeuristicLab.Common;
    2323using HeuristicLab.Core;
     24using HeuristicLab.Data;
    2425using HeuristicLab.Parameters;
    2526using HeuristicLab.Persistence.Default.CompositeSerializers.Storable;
     
    3233  [StorableClass]
    3334  public abstract class SymbolicExpressionTreeCreator : SymbolicExpressionTreeOperator, ISymbolicExpressionTreeCreator {
    34     private const string SymbolicExpressionTreeParameterName = "SymbolicExpressionTree";
     35    private const string MaximumSymbolicExpressionTreeLengthParameterName = "MaximumSymbolicExpressionTreeLength";
     36    private const string MaximumSymbolicExpressionTreeDepthParameterName = "MaximumSymbolicExpressionTreeDepth";
     37
    3538    private const string SymbolicExpressionTreeGrammarParameterName = "SymbolicExpressionTreeGrammar";
    3639    private const string ClonedSymbolicExpressionTreeGrammarParameterName = "ClonedSymbolicExpressionTreeGrammar";
    3740
    3841    #region Parameter Properties
    39     public ILookupParameter<ISymbolicExpressionTree> SymbolicExpressionTreeParameter {
    40       get { return (ILookupParameter<ISymbolicExpressionTree>)Parameters[SymbolicExpressionTreeParameterName]; }
     42    public IValueLookupParameter<IntValue> MaximumSymbolicExpressionTreeLengthParameter {
     43      get { return (IValueLookupParameter<IntValue>)Parameters[MaximumSymbolicExpressionTreeLengthParameterName]; }
    4144    }
    42 
     45    public IValueLookupParameter<IntValue> MaximumSymbolicExpressionTreeDepthParameter {
     46      get { return (IValueLookupParameter<IntValue>)Parameters[MaximumSymbolicExpressionTreeDepthParameterName]; }
     47    }
    4348    public IValueLookupParameter<ISymbolicExpressionGrammar> SymbolicExpressionTreeGrammarParameter {
    4449      get { return (IValueLookupParameter<ISymbolicExpressionGrammar>)Parameters[SymbolicExpressionTreeGrammarParameterName]; }
     
    5560    protected SymbolicExpressionTreeCreator()
    5661      : base() {
    57       Parameters.Add(new LookupParameter<ISymbolicExpressionTree>(SymbolicExpressionTreeParameterName, "The symbolic expression tree that should be created."));
    58       Parameters.Add(new ValueLookupParameter<ISymbolicExpressionGrammar>(SymbolicExpressionTreeGrammarParameterName,
    59         "The tree grammar that defines the correct syntax of symbolic expression trees that should be created."));
    60       Parameters.Add(new LookupParameter<ISymbolicExpressionGrammar>(ClonedSymbolicExpressionTreeGrammarParameterName,
    61         "An immutable clone of the concrete grammar that is actually used to create and manipulate trees."));
     62      Parameters.Add(new ValueLookupParameter<IntValue>(MaximumSymbolicExpressionTreeLengthParameterName, "The maximal length (number of nodes) of the symbolic expression tree."));
     63      Parameters.Add(new ValueLookupParameter<IntValue>(MaximumSymbolicExpressionTreeDepthParameterName, "The maximal depth of the symbolic expression tree (a tree with one node has depth = 0)."));
     64      Parameters.Add(new ValueLookupParameter<ISymbolicExpressionGrammar>(SymbolicExpressionTreeGrammarParameterName, "The tree grammar that defines the correct syntax of symbolic expression trees that should be created."));
     65      Parameters.Add(new LookupParameter<ISymbolicExpressionGrammar>(ClonedSymbolicExpressionTreeGrammarParameterName, "An immutable clone of the concrete grammar that is actually used to create and manipulate trees."));
    6266    }
    6367
     
    7882          (ISymbolicExpressionGrammar)SymbolicExpressionTreeGrammarParameter.ActualValue.Clone()));
    7983      }
    80       SymbolicExpressionTreeParameter.ActualValue = Create(Random);
     84      SymbolicExpressionTreeParameter.ActualValue = Create(RandomParameter.ActualValue);
    8185      return base.InstrumentedApply();
    8286    }
  • branches/HeuristicLab.DatasetRefactor/sources/HeuristicLab.Encodings.SymbolicExpressionTreeEncoding/3.4/Crossovers/SubtreeCrossover.cs

    r12031 r12438  
    2828using HeuristicLab.Parameters;
    2929using HeuristicLab.Persistence.Default.CompositeSerializers.Storable;
     30using HeuristicLab.Random;
    3031
    3132namespace HeuristicLab.Encodings.SymbolicExpressionTreeEncoding {
     
    181182                                   select branch).ToList();
    182183        if (allowedInternalBranches.Count > 0) {
    183           return allowedInternalBranches.SelectRandom(random);
     184          return allowedInternalBranches.SampleRandom(random);
     185
    184186        } else {
    185187          // no internal nodes allowed => select leaf nodes
     
    187189                                 where branch == null || branch.SubtreeCount == 0
    188190                                 select branch).ToList();
    189           return allowedLeafBranches.SelectRandom(random);
     191          return allowedLeafBranches.SampleRandom(random);
    190192        }
    191193      } else {
     
    195197                               select branch).ToList();
    196198        if (allowedLeafBranches.Count > 0) {
    197           return allowedLeafBranches.SelectRandom(random);
     199          return allowedLeafBranches.SampleRandom(random);
    198200        } else {
    199201          allowedInternalBranches = (from branch in branches
    200202                                     where branch != null && branch.SubtreeCount > 0
    201203                                     select branch).ToList();
    202           return allowedInternalBranches.SelectRandom(random);
     204          return allowedInternalBranches.SampleRandom(random);
     205
    203206        }
    204207      }
  • branches/HeuristicLab.DatasetRefactor/sources/HeuristicLab.Encodings.SymbolicExpressionTreeEncoding/3.4/Crossovers/SymbolicExpressionTreeCrossover.cs

    r12031 r12438  
    3434  public abstract class SymbolicExpressionTreeCrossover : SymbolicExpressionTreeOperator, ISymbolicExpressionTreeCrossover {
    3535    private const string ParentsParameterName = "Parents";
    36     private const string ChildParameterName = "Child";
    3736    #region Parameter Properties
    3837    public ILookupParameter<ItemArray<ISymbolicExpressionTree>> ParentsParameter {
    3938      get { return (ScopeTreeLookupParameter<ISymbolicExpressionTree>)Parameters[ParentsParameterName]; }
    4039    }
    41     public ILookupParameter<ISymbolicExpressionTree> ChildParameter {
    42       get { return (ILookupParameter<ISymbolicExpressionTree>)Parameters[ChildParameterName]; }
    43     }
    4440    #endregion
    4541    #region Properties
    46     public ItemArray<ISymbolicExpressionTree> Parents {
     42    private ItemArray<ISymbolicExpressionTree> Parents {
    4743      get { return ParentsParameter.ActualValue; }
    4844    }
    49     public ISymbolicExpressionTree Child {
    50       get { return ChildParameter.ActualValue; }
    51       set { ChildParameter.ActualValue = value; }
     45    private ISymbolicExpressionTree Child {
     46      get { return SymbolicExpressionTreeParameter.ActualValue; }
     47      set { SymbolicExpressionTreeParameter.ActualValue = value; }
    5248    }
    5349    #endregion
     
    5854      : base() {
    5955      Parameters.Add(new ScopeTreeLookupParameter<ISymbolicExpressionTree>(ParentsParameterName, "The parent symbolic expression trees which should be crossed."));
    60       Parameters.Add(new LookupParameter<ISymbolicExpressionTree>(ChildParameterName, "The child symbolic expression tree resulting from the crossover."));
    6156      ParentsParameter.ActualName = "SymbolicExpressionTree";
    62       ChildParameter.ActualName = "SymbolicExpressionTree";
    6357    }
    6458
     
    6761        throw new ArgumentException("Number of parents must be exactly two for symbolic expression tree crossover operators.");
    6862
    69       ISymbolicExpressionTree result = Crossover(Random, Parents[0], Parents[1]);
     63      ISymbolicExpressionTree result = Crossover(RandomParameter.ActualValue, Parents[0], Parents[1]);
    7064
    7165      Child = result;
  • branches/HeuristicLab.DatasetRefactor/sources/HeuristicLab.Encodings.SymbolicExpressionTreeEncoding/3.4/EnumerableExtensions.cs

    r12031 r12438  
    2020#endregion
    2121
     22using System;
    2223using System.Collections.Generic;
    2324using System.Linq;
    2425using HeuristicLab.Core;
    25 using System;
    2626
    2727namespace HeuristicLab.Encodings.SymbolicExpressionTreeEncoding {
     28
     29  //This class should not be used anymore. Use HeuristicLab.Random.RandomEnumberable instead
     30  //This could not be fixed right now, because the algorithm behavior would be modified => version increment
     31  [Obsolete("This class will be removed in the future, because the functionality is provided in HeuristicLab.Random.RandomEnumerable.")]
    2832  public static class EnumerableExtensions {
     33    [Obsolete("This method should not be used anymore. Use the extensions provided by HeuristicLab.Random.RandomEnumberable instead.")]
    2934    public static T SelectRandom<T>(this IEnumerable<T> xs, IRandom random) {
    3035      var list = xs as IList<T>;
     
    3641      }
    3742    }
     43    [Obsolete("This method should not be used anymore. Use the extensions provided by HeuristicLab.Random.RandomEnumberable instead.")]
    3844    public static T SelectRandom<T>(this IEnumerable<T> xs, IEnumerable<double> weights, IRandom random) {
    3945      var list = xs as IList<T>;
  • branches/HeuristicLab.DatasetRefactor/sources/HeuristicLab.Encodings.SymbolicExpressionTreeEncoding/3.4/Grammars/EmptySymbolicExpressionTreeGrammar.cs

    r12031 r12438  
    3737
    3838    [StorableConstructor]
    39     private EmptySymbolicExpressionTreeGrammar(bool deserializing) : base(deserializing) {}
     39    private EmptySymbolicExpressionTreeGrammar(bool deserializing) : base(deserializing) { }
    4040    internal EmptySymbolicExpressionTreeGrammar(ISymbolicExpressionGrammar grammar)
    4141      : base() {
     
    7070    }
    7171
    72     IEnumerable<ISymbol> ISymbolicExpressionGrammarBase.GetAllowedChildSymbols(ISymbol parent) {
     72    public IEnumerable<ISymbol> GetAllowedChildSymbols(ISymbol parent) {
    7373      return grammar.GetAllowedChildSymbols(parent);
    7474    }
    7575
    76     IEnumerable<ISymbol> ISymbolicExpressionGrammarBase.GetAllowedChildSymbols(ISymbol parent, int argumentIndex) {
     76    public IEnumerable<ISymbol> GetAllowedChildSymbols(ISymbol parent, int argumentIndex) {
    7777      return grammar.GetAllowedChildSymbols(parent, argumentIndex);
    7878    }
     
    8585    }
    8686
    87     int ISymbolicExpressionGrammarBase.GetMinimumExpressionDepth(ISymbol symbol) {
     87    public int GetMinimumExpressionDepth(ISymbol symbol) {
    8888      return grammar.GetMinimumExpressionDepth(symbol);
    8989    }
    90     int ISymbolicExpressionGrammarBase.GetMaximumExpressionDepth(ISymbol symbol) {
     90    public int GetMaximumExpressionDepth(ISymbol symbol) {
    9191      return grammar.GetMaximumExpressionDepth(symbol);
    9292    }
    93     int ISymbolicExpressionGrammarBase.GetMinimumExpressionLength(ISymbol symbol) {
     93    public int GetMinimumExpressionLength(ISymbol symbol) {
    9494      return grammar.GetMinimumExpressionLength(symbol);
    9595    }
    96     int ISymbolicExpressionGrammarBase.GetMaximumExpressionLength(ISymbol symbol, int maxDepth) {
     96    public int GetMaximumExpressionLength(ISymbol symbol, int maxDepth) {
    9797      return grammar.GetMaximumExpressionLength(symbol, maxDepth);
    9898    }
    9999
     100    public void AddSymbol(ISymbol symbol) { throw new NotSupportedException(); }
     101    public void RemoveSymbol(ISymbol symbol) { throw new NotSupportedException(); }
     102    public void AddAllowedChildSymbol(ISymbol parent, ISymbol child) { throw new NotSupportedException(); }
     103    public void AddAllowedChildSymbol(ISymbol parent, ISymbol child, int argumentIndex) { throw new NotSupportedException(); }
     104    public void RemoveAllowedChildSymbol(ISymbol parent, ISymbol child) { throw new NotSupportedException(); }
     105    public void RemoveAllowedChildSymbol(ISymbol parent, ISymbol child, int argumentIndex) { throw new NotSupportedException(); }
     106    public void SetSubtreeCount(ISymbol symbol, int minimumSubtreeCount, int maximumSubtreeCount) { throw new NotSupportedException(); }
     107
    100108
    101109    #region ISymbolicExpressionTreeGrammar Members
    102     IEnumerable<ISymbol> ISymbolicExpressionTreeGrammar.ModifyableSymbols {
     110    public IEnumerable<ISymbol> ModifyableSymbols {
    103111      get { return Enumerable.Empty<ISymbol>(); }
    104112    }
    105113
    106     bool ISymbolicExpressionTreeGrammar.IsModifyableSymbol(ISymbol symbol) {
     114    public bool IsModifyableSymbol(ISymbol symbol) {
    107115      return false;
    108116    }
    109117
    110     void ISymbolicExpressionTreeGrammar.AddSymbol(ISymbol symbol) {
    111       throw new NotSupportedException();
    112     }
    113 
    114     void ISymbolicExpressionTreeGrammar.RemoveSymbol(ISymbol symbol) {
    115       throw new NotSupportedException();
    116     }
    117 
    118     void ISymbolicExpressionTreeGrammar.AddAllowedChildSymbol(ISymbol parent, ISymbol child) {
    119       throw new NotSupportedException();
    120     }
    121 
    122     void ISymbolicExpressionTreeGrammar.AddAllowedChildSymbol(ISymbol parent, ISymbol child, int argumentIndex) {
    123       throw new NotSupportedException();
    124     }
    125 
    126     void ISymbolicExpressionTreeGrammar.RemoveAllowedChildSymbol(ISymbol parent, ISymbol child) {
    127       throw new NotSupportedException();
    128     }
    129 
    130     void ISymbolicExpressionTreeGrammar.RemoveAllowedChildSymbol(ISymbol parent, ISymbol child, int argumentIndex) {
    131       throw new NotSupportedException();
    132     }
    133 
    134     void ISymbolicExpressionTreeGrammar.SetSubtreeCount(ISymbol symbol, int minimumSubtreeCount, int maximumSubtreeCount) {
    135       throw new NotSupportedException();
    136     }
    137    
    138     #pragma warning disable 0067 //disable usage warning
     118#pragma warning disable 0067 //disable usage warning
    139119    public event EventHandler Changed;
    140     #pragma warning restore 0067
     120#pragma warning restore 0067
    141121    #endregion
    142122  }
  • branches/HeuristicLab.DatasetRefactor/sources/HeuristicLab.Encodings.SymbolicExpressionTreeEncoding/3.4/Grammars/SymbolicExpressionGrammar.cs

    r12031 r12438  
    177177    }
    178178
    179     protected override sealed void AddSymbol(ISymbol symbol) {
     179    public override sealed void AddSymbol(ISymbol symbol) {
     180      if (ReadOnly) throw new InvalidOperationException();
    180181      base.AddSymbol(symbol);
    181182      RegisterSymbolEvents(symbol);
    182183      OnChanged();
    183184    }
    184     protected override sealed void RemoveSymbol(ISymbol symbol) {
     185    public override sealed void RemoveSymbol(ISymbol symbol) {
     186      if (ReadOnly) throw new InvalidOperationException();
    185187      DeregisterSymbolEvents(symbol);
    186188      base.RemoveSymbol(symbol);
     
    204206    #endregion
    205207
    206     #region ISymbolicExpressionGrammar methods
    207     void ISymbolicExpressionGrammar.AddSymbol(ISymbol symbol) {
    208       if (ReadOnly) throw new InvalidOperationException();
    209       AddSymbol(symbol);
    210     }
    211     void ISymbolicExpressionGrammar.RemoveSymbol(ISymbol symbol) {
    212       if (ReadOnly) throw new InvalidOperationException();
    213       RemoveSymbol(symbol);
    214     }
    215 
    216     void ISymbolicExpressionGrammar.AddAllowedChildSymbol(ISymbol parent, ISymbol child) {
     208    public sealed override void AddAllowedChildSymbol(ISymbol parent, ISymbol child) {
    217209      if (ReadOnly) throw new InvalidOperationException();
    218210      base.AddAllowedChildSymbol(parent, child);
    219211    }
    220     void ISymbolicExpressionGrammar.AddAllowedChildSymbol(ISymbol parent, ISymbol child, int argumentIndex) {
     212    public sealed override void AddAllowedChildSymbol(ISymbol parent, ISymbol child, int argumentIndex) {
    221213      if (ReadOnly) throw new InvalidOperationException();
    222214      base.AddAllowedChildSymbol(parent, child, argumentIndex);
    223215    }
    224     void ISymbolicExpressionGrammar.RemoveAllowedChildSymbol(ISymbol parent, ISymbol child) {
     216    public sealed override void RemoveAllowedChildSymbol(ISymbol parent, ISymbol child) {
    225217      if (ReadOnly) throw new InvalidOperationException();
    226218      base.RemoveAllowedChildSymbol(parent, child);
    227219    }
    228     void ISymbolicExpressionGrammar.RemoveAllowedChildSymbol(ISymbol parent, ISymbol child, int argumentIndex) {
     220    public sealed override void RemoveAllowedChildSymbol(ISymbol parent, ISymbol child, int argumentIndex) {
    229221      if (ReadOnly) throw new InvalidOperationException();
    230222      base.RemoveAllowedChildSymbol(parent, child, argumentIndex);
    231223    }
    232224
    233     void ISymbolicExpressionGrammar.SetSubtreeCount(ISymbol symbol, int minimumSubtreeCount, int maximumSubtreeCount) {
     225    public sealed override void SetSubtreeCount(ISymbol symbol, int minimumSubtreeCount, int maximumSubtreeCount) {
    234226      if (ReadOnly) throw new InvalidOperationException();
    235227      base.SetSubtreeCount(symbol, minimumSubtreeCount, maximumSubtreeCount);
     
    237229
    238230    private bool suppressEvents = false;
    239     void ISymbolicExpressionGrammar.StartGrammarManipulation() {
     231    public void StartGrammarManipulation() {
    240232      suppressEvents = true;
    241233    }
    242     void ISymbolicExpressionGrammar.FinishedGrammarManipulation() {
     234    public void FinishedGrammarManipulation() {
    243235      suppressEvents = false;
    244236      OnChanged();
    245237    }
    246238
    247     protected override void OnChanged() {
     239    protected sealed override void OnChanged() {
    248240      if (suppressEvents) return;
    249241      base.OnChanged();
    250242    }
    251     #endregion
    252243
    253244    #region symbol events
     
    305296    private void Symbol_NameChanged(object sender, EventArgs e) {
    306297      ISymbol symbol = (ISymbol)sender;
    307       string oldName = symbols.Where(x => x.Value == symbol).First().Key;
     298      string oldName = symbols.First(x => x.Value == symbol).Key;
    308299      string newName = symbol.Name;
    309300
  • branches/HeuristicLab.DatasetRefactor/sources/HeuristicLab.Encodings.SymbolicExpressionTreeEncoding/3.4/Grammars/SymbolicExpressionGrammarBase.cs

    r12031 r12438  
    4141    private IEnumerable<ISymbol> StorableSymbols {
    4242      get { return symbols.Values.ToArray(); }
    43       set { symbols = value.ToDictionary(sym => sym.Name); }
     43      set { foreach (var s in value) symbols.Add(s.Name, s); }
    4444    }
    4545
     
    4747    private IEnumerable<KeyValuePair<ISymbol, Tuple<int, int>>> StorableSymbolSubtreeCount {
    4848      get { return symbolSubtreeCount.Select(x => new KeyValuePair<ISymbol, Tuple<int, int>>(GetSymbol(x.Key), x.Value)).ToArray(); }
    49       set { symbolSubtreeCount = value.ToDictionary(x => x.Key.Name, x => x.Value); }
     49      set { foreach (var pair in value) symbolSubtreeCount.Add(pair.Key.Name, pair.Value); }
    5050    }
    5151
     
    5353    private IEnumerable<KeyValuePair<ISymbol, IEnumerable<ISymbol>>> StorableAllowedChildSymbols {
    5454      get { return allowedChildSymbols.Select(x => new KeyValuePair<ISymbol, IEnumerable<ISymbol>>(GetSymbol(x.Key), x.Value.Select(GetSymbol).ToArray())).ToArray(); }
    55       set { allowedChildSymbols = value.ToDictionary(x => x.Key.Name, x => x.Value.Select(y => y.Name).ToList()); }
     55      set { foreach (var pair in value) allowedChildSymbols.Add(pair.Key.Name, pair.Value.Select(y => y.Name).ToList()); }
    5656    }
    5757
    5858    [Storable(Name = "AllowedChildSymbolsPerIndex")]
    5959    private IEnumerable<KeyValuePair<Tuple<ISymbol, int>, IEnumerable<ISymbol>>> StorableAllowedChildSymbolsPerIndex {
    60       get { return allowedChildSymbolsPerIndex.Select(x => new KeyValuePair<Tuple<ISymbol, int>, IEnumerable<ISymbol>>(Tuple.Create<ISymbol, int>(GetSymbol(x.Key.Item1), x.Key.Item2), x.Value.Select(y => GetSymbol(y)).ToArray())).ToArray(); }
    61       set { allowedChildSymbolsPerIndex = value.ToDictionary(x => Tuple.Create(x.Key.Item1.Name, x.Key.Item2), x => x.Value.Select(y => y.Name).ToList()); }
     60      get { return allowedChildSymbolsPerIndex.Select(x => new KeyValuePair<Tuple<ISymbol, int>, IEnumerable<ISymbol>>(Tuple.Create(GetSymbol(x.Key.Item1), x.Key.Item2), x.Value.Select(GetSymbol).ToArray())).ToArray(); }
     61      set {
     62        foreach (var pair in value)
     63          allowedChildSymbolsPerIndex.Add(Tuple.Create(pair.Key.Item1.Name, pair.Key.Item2), pair.Value.Select(y => y.Name).ToList());
     64      }
    6265    }
    6366    #endregion
    6467
    6568    private bool suppressEvents;
    66     protected Dictionary<string, ISymbol> symbols;
    67     protected Dictionary<string, Tuple<int, int>> symbolSubtreeCount;
    68     protected Dictionary<string, List<string>> allowedChildSymbols;
    69     protected Dictionary<Tuple<string, int>, List<string>> allowedChildSymbolsPerIndex;
     69    protected readonly Dictionary<string, ISymbol> symbols;
     70    protected readonly Dictionary<string, Tuple<int, int>> symbolSubtreeCount;
     71    protected readonly Dictionary<string, List<string>> allowedChildSymbols;
     72    protected readonly Dictionary<Tuple<string, int>, List<string>> allowedChildSymbolsPerIndex;
    7073
    7174    public override bool CanChangeName {
     
    8790      cachedIsAllowedChildSymbolIndex = new Dictionary<Tuple<string, string, int>, bool>();
    8891
     92      symbols = new Dictionary<string, ISymbol>();
     93      symbolSubtreeCount = new Dictionary<string, Tuple<int, int>>();
     94      allowedChildSymbols = new Dictionary<string, List<string>>();
     95      allowedChildSymbolsPerIndex = new Dictionary<Tuple<string, int>, List<string>>();
     96
    8997      suppressEvents = false;
    9098    }
     
    133141
    134142    #region protected grammar manipulation methods
    135     protected virtual void AddSymbol(ISymbol symbol) {
     143    public virtual void AddSymbol(ISymbol symbol) {
    136144      if (ContainsSymbol(symbol)) throw new ArgumentException("Symbol " + symbol + " is already defined.");
    137145      foreach (var s in symbol.Flatten()) {
     
    143151    }
    144152
    145     protected virtual void RemoveSymbol(ISymbol symbol) {
     153    public virtual void RemoveSymbol(ISymbol symbol) {
    146154      foreach (var s in symbol.Flatten()) {
    147155        symbols.Remove(s.Name);
     
    175183    }
    176184
    177     protected void AddAllowedChildSymbol(ISymbol parent, ISymbol child) {
     185    public virtual void AddAllowedChildSymbol(ISymbol parent, ISymbol child) {
    178186      bool changed = false;
    179187
     
    204212    }
    205213
    206     protected void AddAllowedChildSymbol(ISymbol parent, ISymbol child, int argumentIndex) {
     214    public virtual void AddAllowedChildSymbol(ISymbol parent, ISymbol child, int argumentIndex) {
    207215      bool changed = false;
    208216
     
    238246    }
    239247
    240     protected void RemoveAllowedChildSymbol(ISymbol parent, ISymbol child) {
     248    public virtual void RemoveAllowedChildSymbol(ISymbol parent, ISymbol child) {
    241249      bool changed = false;
    242250      List<string> childSymbols;
     
    257265    }
    258266
    259     protected void RemoveAllowedChildSymbol(ISymbol parent, ISymbol child, int argumentIndex) {
     267    public virtual void RemoveAllowedChildSymbol(ISymbol parent, ISymbol child, int argumentIndex) {
    260268      bool changed = false;
    261269
     
    282290    }
    283291
    284     protected void SetSubtreeCount(ISymbol symbol, int minimumSubtreeCount, int maximumSubtreeCount) {
     292    public virtual void SetSubtreeCount(ISymbol symbol, int minimumSubtreeCount, int maximumSubtreeCount) {
    285293      var symbols = symbol.Flatten().Where(s => !(s is GroupSymbol));
    286294      if (symbols.Any(s => s.MinimumArity > minimumSubtreeCount)) throw new ArgumentException("Invalid minimum subtree count " + minimumSubtreeCount + " for " + symbol);
     
    308316    }
    309317    public virtual IEnumerable<ISymbol> AllowedSymbols {
    310       get { foreach (var s in Symbols) if (s.Enabled) yield return s; }
     318      get { return Symbols.Where(s => s.Enabled); }
    311319    }
    312320    public virtual bool ContainsSymbol(ISymbol symbol) {
     
    510518      if (suppressEvents) return;
    511519      var handler = Changed;
    512       if (handler != null) Changed(this, EventArgs.Empty);
     520      if (handler != null) handler(this, EventArgs.Empty);
    513521    }
    514522  }
  • branches/HeuristicLab.DatasetRefactor/sources/HeuristicLab.Encodings.SymbolicExpressionTreeEncoding/3.4/Grammars/SymbolicExpressionTreeGrammar.cs

    r12031 r12438  
    5555      }
    5656    }
    57     public override IEnumerable<ISymbol> AllowedSymbols {
    58       get { return base.AllowedSymbols; }
    59     }
    6057    public IEnumerable<ISymbol> ModifyableSymbols {
    6158      get { return base.symbols.Values; }
     
    7673    }
    7774
    78     public override bool IsAllowedChildSymbol(ISymbol parent, ISymbol child) {
    79       return grammar.IsAllowedChildSymbol(parent, child) || base.IsAllowedChildSymbol(parent, child);
    80     }
    81     public override bool IsAllowedChildSymbol(ISymbol parent, ISymbol child, int argumentIndex) {
    82       return grammar.IsAllowedChildSymbol(parent, child, argumentIndex) || base.IsAllowedChildSymbol(parent, child, argumentIndex);
     75    public override void RemoveSymbol(ISymbol symbol) {
     76      if (!IsModifyableSymbol(symbol)) throw new InvalidOperationException();
     77      base.RemoveSymbol(symbol);
    8378    }
    8479
     
    9186      return base.GetMaximumSubtreeCount(symbol);
    9287    }
    93 
    94     void ISymbolicExpressionTreeGrammar.AddSymbol(ISymbol symbol) {
    95       base.AddSymbol(symbol);
    96     }
    97     void ISymbolicExpressionTreeGrammar.RemoveSymbol(ISymbol symbol) {
    98       if (!IsModifyableSymbol(symbol)) throw new InvalidOperationException();
    99       base.RemoveSymbol(symbol);
    100     }
    101     void ISymbolicExpressionTreeGrammar.AddAllowedChildSymbol(ISymbol parent, ISymbol child) {
    102       base.AddAllowedChildSymbol(parent, child);
    103     }
    104     void ISymbolicExpressionTreeGrammar.AddAllowedChildSymbol(ISymbol parent, ISymbol child, int argumentIndex) {
    105       base.AddAllowedChildSymbol(parent, child, argumentIndex);
    106     }
    107     void ISymbolicExpressionTreeGrammar.RemoveAllowedChildSymbol(ISymbol parent, ISymbol child) {
    108       base.RemoveAllowedChildSymbol(parent, child);
    109     }
    110     void ISymbolicExpressionTreeGrammar.RemoveAllowedChildSymbol(ISymbol parent, ISymbol child, int argumentIndex) {
    111       base.RemoveAllowedChildSymbol(parent, child, argumentIndex);
    112     }
    113 
    114     void ISymbolicExpressionTreeGrammar.SetSubtreeCount(ISymbol symbol, int minimumSubtreeCount, int maximumSubtreeCount) {
     88    public override void SetSubtreeCount(ISymbol symbol, int minimumSubtreeCount, int maximumSubtreeCount) {
    11589      if (!IsModifyableSymbol(symbol)) throw new InvalidOperationException();
    11690      base.SetSubtreeCount(symbol, minimumSubtreeCount, maximumSubtreeCount);
    11791    }
    11892
    119     int ISymbolicExpressionGrammarBase.GetMinimumExpressionDepth(ISymbol symbol) {
    120       if (symbols.Count == 0) return grammar.GetMinimumExpressionDepth(symbol);
    121       else return base.GetMinimumExpressionDepth(symbol);
     93    public override bool IsAllowedChildSymbol(ISymbol parent, ISymbol child) {
     94      return grammar.IsAllowedChildSymbol(parent, child) || base.IsAllowedChildSymbol(parent, child);
    12295    }
    123     int ISymbolicExpressionGrammarBase.GetMaximumExpressionDepth(ISymbol symbol) {
    124       if (symbols.Count == 0) return grammar.GetMaximumExpressionDepth(symbol);
    125       else return base.GetMaximumExpressionDepth(symbol);
     96    public override bool IsAllowedChildSymbol(ISymbol parent, ISymbol child, int argumentIndex) {
     97      return grammar.IsAllowedChildSymbol(parent, child, argumentIndex) || base.IsAllowedChildSymbol(parent, child, argumentIndex);
    12698    }
    127     int ISymbolicExpressionGrammarBase.GetMinimumExpressionLength(ISymbol symbol) {
    128       if (symbols.Count == 0) return grammar.GetMinimumExpressionLength(symbol);
    129       else return base.GetMinimumExpressionLength(symbol);
    130     }
    131     int ISymbolicExpressionGrammarBase.GetMaximumExpressionLength(ISymbol symbol, int maxDepth) {
    132       if (symbols.Count == 0) return grammar.GetMaximumExpressionLength(symbol, maxDepth);
    133       else return base.GetMaximumExpressionLength(symbol, maxDepth);
    134     }
    135 
    13699  }
    137100}
  • branches/HeuristicLab.DatasetRefactor/sources/HeuristicLab.Encodings.SymbolicExpressionTreeEncoding/3.4/HeuristicLab.Encodings.SymbolicExpressionTreeEncoding-3.4.csproj

    r12031 r12438  
    143143    <Compile Include="Formatters\SymbolicExpressionTreeHierarchicalFormatter.cs" />
    144144    <Compile Include="Grammars\EmptySymbolicExpressionTreeGrammar.cs" />
     145    <Compile Include="Grammars\SimpleSymbolicExpressionGrammar.cs" />
    145146    <Compile Include="Interfaces\IReadOnlySymbol.cs" />
    146147    <Compile Include="Interfaces\ISymbolicExpressionGrammar.cs" />
     
    176177    <Compile Include="Grammars\SymbolicExpressionGrammar.cs" />
    177178    <Compile Include="Grammars\SymbolicExpressionTreeGrammar.cs" />
     179    <Compile Include="SymbolicExpressionTreeEncoding.cs" />
    178180    <Compile Include="SymbolicExpressionTreeTopLevelNode.cs" />
    179181    <Compile Include="Crossovers\SubtreeCrossover.cs">
     
    191193    <Compile Include="Symbols\ArgumentTreeNode.cs" />
    192194    <Compile Include="Symbols\GroupSymbol.cs" />
     195    <Compile Include="Symbols\SimpleSymbol.cs" />
    193196    <Compile Include="Symbols\StartSymbol.cs" />
    194197    <Compile Include="Symbols\InvokeFunction.cs" />
  • branches/HeuristicLab.DatasetRefactor/sources/HeuristicLab.Encodings.SymbolicExpressionTreeEncoding/3.4/Interfaces/ISymbolicExpressionGrammar.cs

    r12031 r12438  
    3636    event EventHandler ReadOnlyChanged;
    3737
    38     void AddSymbol(ISymbol symbol);
    39     void RemoveSymbol(ISymbol symbol);
    40 
    41     void AddAllowedChildSymbol(ISymbol parent, ISymbol child);
    42     void AddAllowedChildSymbol(ISymbol parent, ISymbol child, int argumentIndex);
    43     void RemoveAllowedChildSymbol(ISymbol parent, ISymbol child);
    44     void RemoveAllowedChildSymbol(ISymbol parent, ISymbol child, int argumentIndex);
    45 
    46     void SetSubtreeCount(ISymbol symbol, int minimumSubtreeCount, int maximumSubtreeCount);
    47 
    4838    void StartGrammarManipulation();
    4939    void FinishedGrammarManipulation();
  • branches/HeuristicLab.DatasetRefactor/sources/HeuristicLab.Encodings.SymbolicExpressionTreeEncoding/3.4/Interfaces/ISymbolicExpressionGrammarBase.cs

    r12031 r12438  
    2727  public interface ISymbolicExpressionGrammarBase : INamedItem {
    2828    IEnumerable<ISymbol> Symbols { get; }
     29    IEnumerable<ISymbol> AllowedSymbols { get; }
     30
     31    bool ContainsSymbol(ISymbol symbol);
    2932    ISymbol GetSymbol(string symbolName);
    30     IEnumerable<ISymbol> AllowedSymbols { get; }
    31     bool ContainsSymbol(ISymbol symbol);
     33
     34    void AddSymbol(ISymbol symbol);
     35    void RemoveSymbol(ISymbol symbol);
    3236
    3337    bool IsAllowedChildSymbol(ISymbol parent, ISymbol child);
     
    3640    IEnumerable<ISymbol> GetAllowedChildSymbols(ISymbol parent, int argumentIndex);
    3741
     42    void AddAllowedChildSymbol(ISymbol parent, ISymbol child);
     43    void AddAllowedChildSymbol(ISymbol parent, ISymbol child, int argumentIndex);
     44    void RemoveAllowedChildSymbol(ISymbol parent, ISymbol child);
     45    void RemoveAllowedChildSymbol(ISymbol parent, ISymbol child, int argumentIndex);
     46
     47
    3848    int GetMinimumSubtreeCount(ISymbol symbol);
    3949    int GetMaximumSubtreeCount(ISymbol symbol);
     50    void SetSubtreeCount(ISymbol symbol, int minimumSubtreeCount, int maximumSubtreeCount);
    4051
    4152    int GetMinimumExpressionDepth(ISymbol start);
  • branches/HeuristicLab.DatasetRefactor/sources/HeuristicLab.Encodings.SymbolicExpressionTreeEncoding/3.4/Interfaces/ISymbolicExpressionTreeGrammar.cs

    r12031 r12438  
    2323namespace HeuristicLab.Encodings.SymbolicExpressionTreeEncoding {
    2424  public interface ISymbolicExpressionTreeGrammar : ISymbolicExpressionGrammarBase {
    25 
    2625    IEnumerable<ISymbol> ModifyableSymbols { get; }
    2726    bool IsModifyableSymbol(ISymbol symbol);
    28     void AddSymbol(ISymbol symbol);
    29     void RemoveSymbol(ISymbol symbol);
    30 
    31     void AddAllowedChildSymbol(ISymbol parent, ISymbol child);
    32     void AddAllowedChildSymbol(ISymbol parent, ISymbol child, int argumentIndex);
    33     void RemoveAllowedChildSymbol(ISymbol parent, ISymbol child);
    34     void RemoveAllowedChildSymbol(ISymbol parent, ISymbol child, int argumentIndex);
    35 
    36     void SetSubtreeCount(ISymbol symbol, int minimumSubtreeCount, int maximumSubtreeCount);
    3727  }
    3828}
  • branches/HeuristicLab.DatasetRefactor/sources/HeuristicLab.Encodings.SymbolicExpressionTreeEncoding/3.4/Interfaces/Operators/ISymbolicExpressionTreeCreator.cs

    r12031 r12438  
    2727  /// Interface for operators that create symbolic expression trees.
    2828  /// </summary>
    29   public interface ISymbolicExpressionTreeCreator : ISymbolicExpressionTreeOperator, ISolutionCreator {
    30     ILookupParameter<ISymbolicExpressionTree> SymbolicExpressionTreeParameter { get; }
     29  public interface ISymbolicExpressionTreeCreator : ISolutionCreator, ISymbolicExpressionTreeSizeConstraintOperator, ISymbolicExpressionTreeGrammarBasedOperator {
    3130    ISymbolicExpressionTree CreateTree(IRandom random, ISymbolicExpressionGrammar grammar, int maxTreeLength, int maxTreeDepth);
    3231  }
  • branches/HeuristicLab.DatasetRefactor/sources/HeuristicLab.Encodings.SymbolicExpressionTreeEncoding/3.4/Interfaces/Operators/ISymbolicExpressionTreeCrossover.cs

    r12031 r12438  
    2929  public interface ISymbolicExpressionTreeCrossover : ISymbolicExpressionTreeOperator, ICrossover {
    3030    ILookupParameter<ItemArray<ISymbolicExpressionTree>> ParentsParameter { get; }
    31     ILookupParameter<ISymbolicExpressionTree> ChildParameter { get; }
    3231    ISymbolicExpressionTree Crossover(IRandom random, ISymbolicExpressionTree parent0, ISymbolicExpressionTree parent1);
    3332  }
  • branches/HeuristicLab.DatasetRefactor/sources/HeuristicLab.Encodings.SymbolicExpressionTreeEncoding/3.4/Interfaces/Operators/ISymbolicExpressionTreeManipulator.cs

    r12031 r12438  
    2828  /// </summary>
    2929  public interface ISymbolicExpressionTreeManipulator : ISymbolicExpressionTreeOperator, IManipulator {
    30     ILookupParameter<ISymbolicExpressionTree> SymbolicExpressionTreeParameter { get; }
    3130  }
    3231}
  • branches/HeuristicLab.DatasetRefactor/sources/HeuristicLab.Encodings.SymbolicExpressionTreeEncoding/3.4/Interfaces/Operators/ISymbolicExpressionTreeOperator.cs

    r12031 r12438  
    2727  /// </summary>
    2828  public interface ISymbolicExpressionTreeOperator : IOperator {
     29    ILookupParameter<ISymbolicExpressionTree> SymbolicExpressionTreeParameter { get; }
    2930  }
    3031}
  • branches/HeuristicLab.DatasetRefactor/sources/HeuristicLab.Encodings.SymbolicExpressionTreeEncoding/3.4/Manipulators/ChangeNodeTypeManipulation.cs

    r12031 r12438  
    2020#endregion
    2121
     22using System.Collections.Generic;
    2223using System.Linq;
    2324using HeuristicLab.Common;
    2425using HeuristicLab.Core;
    2526using HeuristicLab.Persistence.Default.CompositeSerializers.Storable;
    26 using System.Collections.Generic;
    2727
    2828namespace HeuristicLab.Encodings.SymbolicExpressionTreeEncoding {
     
    5353      int tries = 0;
    5454      do {
     55
     56#pragma warning disable 612, 618
    5557        parent = symbolicExpressionTree.Root.IterateNodesPrefix().Skip(1).Where(n => n.SubtreeCount > 0).SelectRandom(random);
     58#pragma warning restore 612, 618
     59
    5660        childIndex = random.Next(parent.SubtreeCount);
    5761
     
    8185      if (tries < MAX_TRIES) {
    8286        var weights = allowedSymbols.Select(s => s.InitialFrequency).ToList();
     87#pragma warning disable 612, 618
    8388        var newSymbol = allowedSymbols.SelectRandom(weights, random);
     89#pragma warning restore 612, 618
    8490
    8591        // replace the old node with the new node
  • branches/HeuristicLab.DatasetRefactor/sources/HeuristicLab.Encodings.SymbolicExpressionTreeEncoding/3.4/Manipulators/OnePointShaker.cs

    r12031 r12438  
    2020#endregion
    2121
    22 using System.Linq;
     22using System.Collections.Generic;
    2323using HeuristicLab.Common;
    2424using HeuristicLab.Core;
    2525using HeuristicLab.Data;
     26using HeuristicLab.Parameters;
    2627using HeuristicLab.Persistence.Default.CompositeSerializers.Storable;
    27 using HeuristicLab.Parameters;
    28 using System.Collections.Generic;
     28using HeuristicLab.Random;
    2929
    3030namespace HeuristicLab.Encodings.SymbolicExpressionTreeEncoding {
     
    6666      });
    6767      if (parametricNodes.Count > 0) {
    68         var selectedPoint = parametricNodes.SelectRandom(random);
     68        var selectedPoint = parametricNodes.SampleRandom(random);
    6969        selectedPoint.ShakeLocalParameters(random, shakingFactor);
    7070      }
  • branches/HeuristicLab.DatasetRefactor/sources/HeuristicLab.Encodings.SymbolicExpressionTreeEncoding/3.4/Manipulators/RemoveBranchManipulation.cs

    r12031 r12438  
    2727using HeuristicLab.Parameters;
    2828using HeuristicLab.Persistence.Default.CompositeSerializers.Storable;
     29using HeuristicLab.Random;
    2930
    3031namespace HeuristicLab.Encodings.SymbolicExpressionTreeEncoding {
     
    8081      var nodes = symbolicExpressionTree.Root.IterateNodesPrefix().Skip(1).Where(n => n.SubtreeCount > 0).ToList();
    8182      do {
    82         parent = nodes.SelectRandom(random);
     83        parent = nodes.SampleRandom(random);
     84
    8385        childIndex = random.Next(parent.SubtreeCount);
    8486        var child = parent.GetSubtree(childIndex);
     
    111113                             select g).First().ToList();
    112114      var weights = possibleSymbols.Select(x => x.InitialFrequency).ToList();
     115
     116#pragma warning disable 612, 618
    113117      var selectedSymbol = possibleSymbols.SelectRandom(weights, random);
     118#pragma warning restore 612, 618
     119
    114120      var newTreeNode = selectedSymbol.CreateTreeNode();
    115121      if (newTreeNode.HasLocalParameters) newTreeNode.ResetLocalParameters(random);
  • branches/HeuristicLab.DatasetRefactor/sources/HeuristicLab.Encodings.SymbolicExpressionTreeEncoding/3.4/Manipulators/ReplaceBranchManipulation.cs

    r12031 r12438  
    2020#endregion
    2121
     22using System.Collections.Generic;
    2223using System.Linq;
    2324using HeuristicLab.Common;
     
    2627using HeuristicLab.Parameters;
    2728using HeuristicLab.Persistence.Default.CompositeSerializers.Storable;
    28 using System.Collections.Generic;
    2929
    3030namespace HeuristicLab.Encodings.SymbolicExpressionTreeEncoding {
     
    7878      int tries = 0;
    7979      do {
     80#pragma warning disable 612, 618
    8081        parent = symbolicExpressionTree.Root.IterateNodesPrefix().Skip(1).Where(n => n.SubtreeCount > 0).SelectRandom(random);
     82#pragma warning restore 612, 618
     83
    8184        childIndex = random.Next(parent.SubtreeCount);
    8285        var child = parent.GetSubtree(childIndex);
     
    99102      if (tries < MAX_TRIES) {
    100103        var weights = allowedSymbols.Select(s => s.InitialFrequency).ToList();
     104#pragma warning disable 612, 618
    101105        var seedSymbol = allowedSymbols.SelectRandom(weights, random);
     106#pragma warning restore 612, 618
     107
    102108        // replace the old node with the new node
    103109        var seedNode = seedSymbol.CreateTreeNode();
  • branches/HeuristicLab.DatasetRefactor/sources/HeuristicLab.Encodings.SymbolicExpressionTreeEncoding/3.4/Manipulators/SymbolicExpressionTreeManipulator.cs

    r12031 r12438  
    3232  [StorableClass]
    3333  public abstract class SymbolicExpressionTreeManipulator : SymbolicExpressionTreeOperator, ISymbolicExpressionTreeManipulator {
    34     private const string SymbolicExpressionTreeParameterName = "SymbolicExpressionTree";
    35 
    36     #region Parameter Properties
    37     public ILookupParameter<ISymbolicExpressionTree> SymbolicExpressionTreeParameter {
    38       get { return (ILookupParameter<ISymbolicExpressionTree>)Parameters[SymbolicExpressionTreeParameterName]; }
    39     }
    40     #endregion
    41 
    42     #region Properties
    43     public ISymbolicExpressionTree SymbolicExpressionTree {
    44       get { return SymbolicExpressionTreeParameter.ActualValue; }
    45     }
    46     #endregion
    47 
    4834    [StorableConstructor]
    4935    protected SymbolicExpressionTreeManipulator(bool deserializing) : base(deserializing) { }
     
    5137    public SymbolicExpressionTreeManipulator()
    5238      : base() {
    53       Parameters.Add(new LookupParameter<ISymbolicExpressionTree>(SymbolicExpressionTreeParameterName, "The symbolic expression tree on which the operator should be applied."));
     39     
    5440    }
    5541
  • branches/HeuristicLab.DatasetRefactor/sources/HeuristicLab.Encodings.SymbolicExpressionTreeEncoding/3.4/Plugin.cs.frame

    r12031 r12438  
    3838  [PluginDependency("HeuristicLab.Parameters", "3.3")]
    3939  [PluginDependency("HeuristicLab.Persistence", "3.3")]
     40  [PluginDependency("HeuristicLab.Random", "3.3")]
    4041  public class HeuristicLabEncodingsSymbolicExpressionTreeEncodingPlugin : PluginBase {
    4142  }
  • branches/HeuristicLab.DatasetRefactor/sources/HeuristicLab.Encodings.SymbolicExpressionTreeEncoding/3.4/SymbolicExpressionTreeOperator.cs

    r12031 r12438  
    2222using HeuristicLab.Common;
    2323using HeuristicLab.Core;
    24 using HeuristicLab.Data;
    2524using HeuristicLab.Operators;
    2625using HeuristicLab.Optimization;
     
    3635  public abstract class SymbolicExpressionTreeOperator : InstrumentedOperator, IStochasticOperator, ISymbolicExpressionTreeOperator {
    3736    private const string RandomParameterName = "Random";
     37    private const string SymbolicExpressionTreeParameterName = "SymbolicExpressionTree";
    3838
    3939    public override bool CanChangeName {
     
    4545      get { return (LookupParameter<IRandom>)Parameters[RandomParameterName]; }
    4646    }
    47     #endregion
    48 
    49     #region Properties
    50     public IRandom Random {
    51       get { return RandomParameter.ActualValue; }
     47    public ILookupParameter<ISymbolicExpressionTree> SymbolicExpressionTreeParameter {
     48      get { return (ILookupParameter<ISymbolicExpressionTree>)Parameters[SymbolicExpressionTreeParameterName]; }
    5249    }
    5350    #endregion
     
    5956      : base() {
    6057      Parameters.Add(new LookupParameter<IRandom>(RandomParameterName, "The pseudo random number generator which should be used for symbolic expression tree operators."));
     58      Parameters.Add(new LookupParameter<ISymbolicExpressionTree>(SymbolicExpressionTreeParameterName, "The symbolic expression tree on which the operator should be applied."));
     59    }
     60
     61    [StorableHook(HookType.AfterDeserialization)]
     62    private void AfterDeserialization() {
     63      // BackwardsCompatibility3.3
     64      #region Backwards compatible code, remove with 3.4
     65      if (!Parameters.ContainsKey(SymbolicExpressionTreeParameterName))
     66        Parameters.Add(new LookupParameter<ISymbolicExpressionTree>(SymbolicExpressionTreeParameterName, "The symbolic expression tree on which the operator should be applied."));
     67      #endregion
    6168    }
    6269  }
Note: See TracChangeset for help on using the changeset viewer.