Free cookie consent management tool by TermsFeed Policy Generator

Changeset 12422 for trunk


Ignore:
Timestamp:
06/10/15 11:29:34 (9 years ago)
Author:
mkommend
Message:

#2320: Merged the encoding class and all accompanying changes in the trunk.

Location:
trunk/sources
Files:
57 edited
3 copied

Legend:

Unmodified
Added
Removed
  • trunk/sources/HeuristicLab.Encodings.SymbolicExpressionTreeEncoding

  • trunk/sources/HeuristicLab.Encodings.SymbolicExpressionTreeEncoding/3.4/Analyzers/SymbolicExpressionTreeLengthAnalyzer.cs

    r12012 r12422  
    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;
  • trunk/sources/HeuristicLab.Encodings.SymbolicExpressionTreeEncoding/3.4/ArchitectureManipulators/ArgumentCreater.cs

    r12012 r12422  
    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();
  • trunk/sources/HeuristicLab.Encodings.SymbolicExpressionTreeEncoding/3.4/ArchitectureManipulators/ArgumentDeleter.cs

    r12012 r12422  
    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      }
  • trunk/sources/HeuristicLab.Encodings.SymbolicExpressionTreeEncoding/3.4/ArchitectureManipulators/ArgumentDuplicater.cs

    r12012 r12422  
    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();
  • trunk/sources/HeuristicLab.Encodings.SymbolicExpressionTreeEncoding/3.4/ArchitectureManipulators/SubroutineCreater.cs

    r12012 r12422  
    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);
  • trunk/sources/HeuristicLab.Encodings.SymbolicExpressionTreeEncoding/3.4/ArchitectureManipulators/SubroutineDeleter.cs

    r12012 r12422  
    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);
  • trunk/sources/HeuristicLab.Encodings.SymbolicExpressionTreeEncoding/3.4/ArchitectureManipulators/SubroutineDuplicater.cs

    r12012 r12422  
    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();
  • trunk/sources/HeuristicLab.Encodings.SymbolicExpressionTreeEncoding/3.4/Creators/FullTreeCreator.cs

    r12012 r12422  
    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  }
  • trunk/sources/HeuristicLab.Encodings.SymbolicExpressionTreeEncoding/3.4/Creators/GrowTreeCreator.cs

    r12012 r12422  
    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
  • trunk/sources/HeuristicLab.Encodings.SymbolicExpressionTreeEncoding/3.4/Creators/ProbabilisticTreeCreator.cs

    r12012 r12422  
    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);
  • trunk/sources/HeuristicLab.Encodings.SymbolicExpressionTreeEncoding/3.4/Creators/RampedHalfAndHalfTreeCreator.cs

    r12012 r12422  
    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
  • trunk/sources/HeuristicLab.Encodings.SymbolicExpressionTreeEncoding/3.4/Creators/SymbolicExpressionTreeCreator.cs

    r12012 r12422  
    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    }
  • trunk/sources/HeuristicLab.Encodings.SymbolicExpressionTreeEncoding/3.4/Crossovers/SubtreeCrossover.cs

    r12012 r12422  
    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      }
  • trunk/sources/HeuristicLab.Encodings.SymbolicExpressionTreeEncoding/3.4/Crossovers/SymbolicExpressionTreeCrossover.cs

    r12012 r12422  
    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;
  • trunk/sources/HeuristicLab.Encodings.SymbolicExpressionTreeEncoding/3.4/EnumerableExtensions.cs

    r12012 r12422  
    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>;
  • trunk/sources/HeuristicLab.Encodings.SymbolicExpressionTreeEncoding/3.4/Grammars/EmptySymbolicExpressionTreeGrammar.cs

    r12012 r12422  
    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  }
  • trunk/sources/HeuristicLab.Encodings.SymbolicExpressionTreeEncoding/3.4/Grammars/SymbolicExpressionGrammar.cs

    r12012 r12422  
    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
  • trunk/sources/HeuristicLab.Encodings.SymbolicExpressionTreeEncoding/3.4/Grammars/SymbolicExpressionGrammarBase.cs

    r12012 r12422  
    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  }
  • trunk/sources/HeuristicLab.Encodings.SymbolicExpressionTreeEncoding/3.4/Grammars/SymbolicExpressionTreeGrammar.cs

    r12012 r12422  
    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}
  • trunk/sources/HeuristicLab.Encodings.SymbolicExpressionTreeEncoding/3.4/HeuristicLab.Encodings.SymbolicExpressionTreeEncoding-3.4.csproj

    r11623 r12422  
    176176    <Compile Include="Grammars\SymbolicExpressionGrammar.cs" />
    177177    <Compile Include="Grammars\SymbolicExpressionTreeGrammar.cs" />
     178    <Compile Include="SymbolicExpressionTreeEncoding.cs" />
    178179    <Compile Include="SymbolicExpressionTreeTopLevelNode.cs" />
    179180    <Compile Include="Crossovers\SubtreeCrossover.cs">
  • trunk/sources/HeuristicLab.Encodings.SymbolicExpressionTreeEncoding/3.4/Interfaces/ISymbolicExpressionGrammar.cs

    r12012 r12422  
    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();
  • trunk/sources/HeuristicLab.Encodings.SymbolicExpressionTreeEncoding/3.4/Interfaces/ISymbolicExpressionGrammarBase.cs

    r12012 r12422  
    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);
  • trunk/sources/HeuristicLab.Encodings.SymbolicExpressionTreeEncoding/3.4/Interfaces/ISymbolicExpressionTreeGrammar.cs

    r12012 r12422  
    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}
  • trunk/sources/HeuristicLab.Encodings.SymbolicExpressionTreeEncoding/3.4/Interfaces/Operators/ISymbolicExpressionTreeCreator.cs

    r12012 r12422  
    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  }
  • trunk/sources/HeuristicLab.Encodings.SymbolicExpressionTreeEncoding/3.4/Interfaces/Operators/ISymbolicExpressionTreeCrossover.cs

    r12012 r12422  
    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  }
  • trunk/sources/HeuristicLab.Encodings.SymbolicExpressionTreeEncoding/3.4/Interfaces/Operators/ISymbolicExpressionTreeManipulator.cs

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

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

    r12012 r12422  
    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
  • trunk/sources/HeuristicLab.Encodings.SymbolicExpressionTreeEncoding/3.4/Manipulators/OnePointShaker.cs

    r12012 r12422  
    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      }
  • trunk/sources/HeuristicLab.Encodings.SymbolicExpressionTreeEncoding/3.4/Manipulators/RemoveBranchManipulation.cs

    r12012 r12422  
    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);
  • trunk/sources/HeuristicLab.Encodings.SymbolicExpressionTreeEncoding/3.4/Manipulators/ReplaceBranchManipulation.cs

    r12012 r12422  
    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();
  • trunk/sources/HeuristicLab.Encodings.SymbolicExpressionTreeEncoding/3.4/Manipulators/SymbolicExpressionTreeManipulator.cs

    r12012 r12422  
    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
  • trunk/sources/HeuristicLab.Encodings.SymbolicExpressionTreeEncoding/3.4/SymbolicExpressionTreeOperator.cs

    r12012 r12422  
    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  }
  • trunk/sources/HeuristicLab.Problems.ArtificialAnt

    • Property svn:mergeinfo set to (toggle deleted branches)
      /branches/HLScript/HeuristicLab.Problems.ArtificialAntmergedeligible
      /branches/SymbolicExpressionTreeEncoding/HeuristicLab.Problems.ArtificialAntmergedeligible
      /stable/HeuristicLab.Problems.ArtificialAntmergedeligible
      /branches/1721-RandomForestPersistence/HeuristicLab.Problems.ArtificialAnt10321-10322
      /branches/Algorithms.GradientDescent/HeuristicLab.Problems.ArtificialAnt5516-5520
      /branches/Benchmarking/sources/HeuristicLab.Problems.ArtificialAnt6917-7005
      /branches/CloningRefactoring/HeuristicLab.Problems.ArtificialAnt4656-4721
      /branches/CodeEditor/HeuristicLab.Problems.ArtificialAnt11700-11806
      /branches/DataAnalysis Refactoring/HeuristicLab.Problems.ArtificialAnt5471-5808
      /branches/DataAnalysis SolutionEnsembles/HeuristicLab.Problems.ArtificialAnt5815-6180
      /branches/DataAnalysis/HeuristicLab.Problems.ArtificialAnt4458-4459,​4462,​4464
      /branches/DataPreprocessing/HeuristicLab.Problems.ArtificialAnt10085-11101
      /branches/GP.Grammar.Editor/HeuristicLab.Problems.ArtificialAnt6284-6795
      /branches/GP.Symbols (TimeLag, Diff, Integral)/HeuristicLab.Problems.ArtificialAnt5060
      /branches/HeuristicLab.Problems.DataAnalysis.Trading/HeuristicLab.Problems.ArtificialAnt6123-9799
      /branches/LogResidualEvaluator/HeuristicLab.Problems.ArtificialAnt10202-10483
      /branches/NET40/sources/HeuristicLab.Problems.ArtificialAnt5138-5162
      /branches/NSGA-II Changes/HeuristicLab.Problems.ArtificialAnt12033-12122
      /branches/ParallelEngine/HeuristicLab.Problems.ArtificialAnt5175-5192
      /branches/ProblemInstancesRegressionAndClassification/HeuristicLab.Problems.ArtificialAnt7568-7810
      /branches/QAPAlgorithms/HeuristicLab.Problems.ArtificialAnt6350-6627
      /branches/Restructure trunk solution/HeuristicLab.Problems.ArtificialAnt6828
      /branches/RuntimeOptimizer/HeuristicLab.Problems.ArtificialAnt8943-9078
      /branches/ScatterSearch (trunk integration)/HeuristicLab.Problems.ArtificialAnt7787-8333
      /branches/SlaveShutdown/HeuristicLab.Problems.ArtificialAnt8944-8956
      /branches/SpectralKernelForGaussianProcesses/HeuristicLab.Problems.ArtificialAnt10204-10479
      /branches/SuccessProgressAnalysis/HeuristicLab.Problems.ArtificialAnt5370-5682
      /branches/Trunk/HeuristicLab.Problems.ArtificialAnt6829-6865
      /branches/UnloadJobs/HeuristicLab.Problems.ArtificialAnt9168-9215
      /branches/VNS/HeuristicLab.Problems.ArtificialAnt5594-5752
      /branches/histogram/HeuristicLab.Problems.ArtificialAnt5959-6341
  • trunk/sources/HeuristicLab.Problems.ArtificialAnt/3.4/ArtificialAntProblem.cs

    r12012 r12422  
    274274      foreach (ISymbolicExpressionTreeCrossover op in operators.OfType<ISymbolicExpressionTreeCrossover>()) {
    275275        op.ParentsParameter.ActualName = SolutionCreator.SymbolicExpressionTreeParameter.ActualName;
    276         op.ChildParameter.ActualName = SolutionCreator.SymbolicExpressionTreeParameter.ActualName;
     276        op.SymbolicExpressionTreeParameter.ActualName = SolutionCreator.SymbolicExpressionTreeParameter.ActualName;
    277277      }
    278278      foreach (ISymbolicExpressionTreeManipulator op in operators.OfType<ISymbolicExpressionTreeManipulator>()) {
  • trunk/sources/HeuristicLab.Problems.DataAnalysis.Symbolic

  • trunk/sources/HeuristicLab.Problems.DataAnalysis.Symbolic.Classification

  • trunk/sources/HeuristicLab.Problems.DataAnalysis.Symbolic.Classification/3.4/SymbolicClassificationPhenotypicDiversityAnalyzer.cs

    r12103 r12422  
    3535  [StorableClass]
    3636  public class SymbolicClassificationPhenotypicDiversityAnalyzer : PopulationSimilarityAnalyzer,
    37     ISymbolicDataAnalysisBoundedOperator, ISymbolicDataAnalysisInterpreterOperator, ISymbolicExpressionTreeOperator {
     37    ISymbolicDataAnalysisBoundedOperator, ISymbolicDataAnalysisInterpreterOperator, ISymbolicExpressionTreeAnalyzer {
    3838    #region parameter names
    3939    private const string SymbolicExpressionTreeParameterName = "SymbolicExpressionTree";
  • trunk/sources/HeuristicLab.Problems.DataAnalysis.Symbolic.Regression

  • trunk/sources/HeuristicLab.Problems.DataAnalysis.Symbolic.Regression/3.4/SymbolicRegressionPhenotypicDiversityAnalyzer.cs

    r12103 r12422  
    3535  [StorableClass]
    3636  public class SymbolicRegressionPhenotypicDiversityAnalyzer : PopulationSimilarityAnalyzer,
    37     ISymbolicDataAnalysisBoundedOperator, ISymbolicDataAnalysisInterpreterOperator, ISymbolicExpressionTreeOperator {
     37    ISymbolicDataAnalysisBoundedOperator, ISymbolicDataAnalysisInterpreterOperator, ISymbolicExpressionTreeAnalyzer {
    3838    #region parameter names
    3939    private const string SymbolicExpressionTreeParameterName = "SymbolicExpressionTree";
  • trunk/sources/HeuristicLab.Problems.DataAnalysis.Symbolic.TimeSeriesPrognosis

    • Property svn:mergeinfo set to (toggle deleted branches)
      /branches/HLScript/HeuristicLab.Problems.DataAnalysis.Symbolic.TimeSeriesPrognosismergedeligible
      /branches/SymbolicExpressionTreeEncoding/HeuristicLab.Problems.DataAnalysis.Symbolic.TimeSeriesPrognosismergedeligible
      /stable/HeuristicLab.Problems.DataAnalysis.Symbolic.TimeSeriesPrognosismergedeligible
      /branches/1721-RandomForestPersistence/HeuristicLab.Problems.DataAnalysis.Symbolic.TimeSeriesPrognosis10321-10322
      /branches/Algorithms.GradientDescent/HeuristicLab.Problems.DataAnalysis.Symbolic.TimeSeriesPrognosis5516-5520
      /branches/Benchmarking/sources/HeuristicLab.Problems.DataAnalysis.Symbolic.TimeSeriesPrognosis6917-7005
      /branches/CloningRefactoring/HeuristicLab.Problems.DataAnalysis.Symbolic.TimeSeriesPrognosis4656-4721
      /branches/CodeEditor/HeuristicLab.Problems.DataAnalysis.Symbolic.TimeSeriesPrognosis11700-11806
      /branches/DataAnalysis Refactoring/HeuristicLab.Problems.DataAnalysis.Symbolic.TimeSeriesPrognosis5471-5808
      /branches/DataAnalysis SolutionEnsembles/HeuristicLab.Problems.DataAnalysis.Symbolic.TimeSeriesPrognosis5815-6180
      /branches/DataAnalysis/HeuristicLab.Problems.DataAnalysis.Symbolic.TimeSeriesPrognosis4458-4459,​4462,​4464
      /branches/DataPreprocessing/HeuristicLab.Problems.DataAnalysis.Symbolic.TimeSeriesPrognosis10085-11101
      /branches/GP.Grammar.Editor/HeuristicLab.Problems.DataAnalysis.Symbolic.TimeSeriesPrognosis6284-6795
      /branches/GP.Symbols (TimeLag, Diff, Integral)/HeuristicLab.Problems.DataAnalysis.Symbolic.TimeSeriesPrognosis5060
      /branches/HeuristicLab.Problems.DataAnalysis.Trading/HeuristicLab.Problems.DataAnalysis.Symbolic.TimeSeriesPrognosis6123-9799
      /branches/LogResidualEvaluator/HeuristicLab.Problems.DataAnalysis.Symbolic.TimeSeriesPrognosis10202-10483
      /branches/NET40/sources/HeuristicLab.Problems.DataAnalysis.Symbolic.TimeSeriesPrognosis5138-5162
      /branches/NSGA-II Changes/HeuristicLab.Problems.DataAnalysis.Symbolic.TimeSeriesPrognosis12033-12122
      /branches/ParallelEngine/HeuristicLab.Problems.DataAnalysis.Symbolic.TimeSeriesPrognosis5175-5192
      /branches/ProblemInstancesRegressionAndClassification/HeuristicLab.Problems.DataAnalysis.Symbolic.TimeSeriesPrognosis7568-7810
      /branches/QAPAlgorithms/HeuristicLab.Problems.DataAnalysis.Symbolic.TimeSeriesPrognosis6350-6627
      /branches/Restructure trunk solution/HeuristicLab.Problems.DataAnalysis.Symbolic.TimeSeriesPrognosis6828
      /branches/RuntimeOptimizer/HeuristicLab.Problems.DataAnalysis.Symbolic.TimeSeriesPrognosis8943-9078
      /branches/ScatterSearch (trunk integration)/HeuristicLab.Problems.DataAnalysis.Symbolic.TimeSeriesPrognosis7787-8333
      /branches/SlaveShutdown/HeuristicLab.Problems.DataAnalysis.Symbolic.TimeSeriesPrognosis8944-8956
      /branches/SpectralKernelForGaussianProcesses/HeuristicLab.Problems.DataAnalysis.Symbolic.TimeSeriesPrognosis10204-10479
      /branches/SuccessProgressAnalysis/HeuristicLab.Problems.DataAnalysis.Symbolic.TimeSeriesPrognosis5370-5682
      /branches/Trunk/HeuristicLab.Problems.DataAnalysis.Symbolic.TimeSeriesPrognosis6829-6865
      /branches/UnloadJobs/HeuristicLab.Problems.DataAnalysis.Symbolic.TimeSeriesPrognosis9168-9215
      /branches/VNS/HeuristicLab.Problems.DataAnalysis.Symbolic.TimeSeriesPrognosis5594-5752
      /branches/histogram/HeuristicLab.Problems.DataAnalysis.Symbolic.TimeSeriesPrognosis5959-6341
  • trunk/sources/HeuristicLab.Problems.DataAnalysis.Symbolic/3.4/Crossovers/MultiSymbolicDataAnalysisExpressionCrossover.cs

    r12012 r12422  
    3535namespace HeuristicLab.Problems.DataAnalysis.Symbolic {
    3636  [Item("MultiSymbolicDataAnalysisExpressionCrossover", "Randomly selects and applies one of its crossovers every time it is called.")]
     37  [StorableClass]
    3738  public class MultiSymbolicDataAnalysisExpressionCrossover<T> : StochasticMultiBranch<ISymbolicExpressionTreeCrossover>,
    3839    ISymbolicDataAnalysisExpressionCrossover<T> where T : class, IDataAnalysisProblemData {
    3940    private const string ParentsParameterName = "Parents";
    40     private const string ChildParameterName = "Child";
     41    private const string SymbolicExpressionTreeParameterName = "SymbolicExpressionTree";
    4142    private const string MaximumSymbolicExpressionTreeLengthParameterName = "MaximumSymbolicExpressionTreeLength";
    4243    private const string MaximumSymbolicExpressionTreeDepthParameterName = "MaximumSymbolicExpressionTreeDepth";
     
    6263      get { return (ScopeTreeLookupParameter<ISymbolicExpressionTree>)Parameters[ParentsParameterName]; }
    6364    }
    64     public ILookupParameter<ISymbolicExpressionTree> ChildParameter {
    65       get { return (ILookupParameter<ISymbolicExpressionTree>)Parameters[ChildParameterName]; }
     65    public ILookupParameter<ISymbolicExpressionTree> SymbolicExpressionTreeParameter {
     66      get { return (ILookupParameter<ISymbolicExpressionTree>)Parameters[SymbolicExpressionTreeParameterName]; }
    6667    }
    6768    public IValueLookupParameter<IntValue> MaximumSymbolicExpressionTreeLengthParameter {
     
    99100      Parameters.Add(new ValueLookupParameter<IntRange>(SymbolicDataAnalysisEvaluationPartitionParameterName, "The start index of the dataset partition on which the symbolic data analysis solution should be evaluated."));
    100101      Parameters.Add(new ScopeTreeLookupParameter<ISymbolicExpressionTree>(ParentsParameterName, "The parent symbolic expression trees which should be crossed."));
    101       Parameters.Add(new LookupParameter<ISymbolicExpressionTree>(ChildParameterName, "The child symbolic expression tree resulting from the crossover."));
     102      Parameters.Add(new LookupParameter<ISymbolicExpressionTree>(SymbolicExpressionTreeParameterName, "The child symbolic expression tree resulting from the crossover."));
    102103
    103104      EvaluatorParameter.Hidden = true;
     
    111112
    112113      SelectedOperatorParameter.ActualName = "SelectedCrossoverOperator";
     114    }
     115
     116    [StorableHook(HookType.AfterDeserialization)]
     117    private void AfterDeserialization() {
     118      // BackwardsCompatibility3.3
     119      #region Backwards compatible code, remove with 3.4
     120      if (!Parameters.ContainsKey(SymbolicExpressionTreeParameterName))
     121        Parameters.Add(new LookupParameter<ISymbolicExpressionTree>(SymbolicExpressionTreeParameterName, "The symbolic expression tree on which the operator should be applied."));
     122      #endregion
    113123    }
    114124
     
    155165    private void ParameterizeCrossovers() {
    156166      foreach (ISymbolicExpressionTreeCrossover op in Operators) {
    157         op.ChildParameter.ActualName = ChildParameter.Name;
     167        op.SymbolicExpressionTreeParameter.ActualName = SymbolicExpressionTreeParameter.Name;
    158168        op.ParentsParameter.ActualName = ParentsParameter.Name;
    159169      }
  • trunk/sources/HeuristicLab.Problems.DataAnalysis.Symbolic/3.4/Crossovers/SymbolicDataAnalysisExpressionContextAwareCrossover.cs

    r12012 r12422  
    2727using HeuristicLab.Encodings.SymbolicExpressionTreeEncoding;
    2828using HeuristicLab.Persistence.Default.CompositeSerializers.Storable;
     29using HeuristicLab.Random;
    2930
    3031namespace HeuristicLab.Problems.DataAnalysis.Symbolic {
     
    6869          possibleChildren.Add(n);
    6970      });
    70       var selectedChild = possibleChildren.SelectRandom(random);
     71
     72      var selectedChild = possibleChildren.SampleRandom(random);
    7173      var crossoverPoints = new List<CutPoint>();
    7274      var qualities = new List<Tuple<CutPoint, double>>();
  • trunk/sources/HeuristicLab.Problems.DataAnalysis.Symbolic/3.4/Crossovers/SymbolicDataAnalysisExpressionDepthConstrainedCrossover.cs

    r12012 r12422  
    2929using HeuristicLab.Parameters;
    3030using HeuristicLab.Persistence.Default.CompositeSerializers.Storable;
     31using HeuristicLab.Random;
    3132
    3233namespace HeuristicLab.Problems.DataAnalysis.Symbolic {
     
    115116        throw new Exception("No crossover points available in the first parent");
    116117
    117       var crossoverPoint0 = crossoverPoints0.SelectRandom(random);
    118 
     118      var crossoverPoint0 = crossoverPoints0.SampleRandom(random);
    119119      int level = parent0.Root.GetBranchLevel(crossoverPoint0.Child);
    120120      int length = parent0.Root.GetLength() - crossoverPoint0.Child.GetLength();
     
    126126                             select s).ToList();
    127127      if (allowedBranches.Count == 0) return parent0;
    128       var selectedBranch = allowedBranches.SelectRandom(random);
     128
     129      var selectedBranch = allowedBranches.SampleRandom(random);
    129130      Swap(crossoverPoint0, selectedBranch);
    130131      return parent0;
  • trunk/sources/HeuristicLab.Problems.DataAnalysis.Symbolic/3.4/Crossovers/SymbolicDataAnalysisExpressionDeterministicBestCrossover.cs

    r12012 r12422  
    2727using HeuristicLab.Encodings.SymbolicExpressionTreeEncoding;
    2828using HeuristicLab.Persistence.Default.CompositeSerializers.Storable;
     29using HeuristicLab.Random;
    2930
    3031namespace HeuristicLab.Problems.DataAnalysis.Symbolic {
     
    6768          crossoverPoints0.Add(new CutPoint(n.Parent, n));
    6869      });
    69       CutPoint crossoverPoint0 = crossoverPoints0.SelectRandom(random);
     70
     71      CutPoint crossoverPoint0 = crossoverPoints0.SampleRandom(random);
    7072      int level = parent0.Root.GetBranchLevel(crossoverPoint0.Child);
    7173      int length = parent0.Root.GetLength() - crossoverPoint0.Child.GetLength();
  • trunk/sources/HeuristicLab.Problems.DataAnalysis.Symbolic/3.4/Crossovers/SymbolicDataAnalysisExpressionProbabilisticFunctionalCrossover.cs

    r12012 r12422  
    2727using HeuristicLab.Encodings.SymbolicExpressionTreeEncoding;
    2828using HeuristicLab.Persistence.Default.CompositeSerializers.Storable;
     29using HeuristicLab.Random;
    2930
    3031namespace HeuristicLab.Problems.DataAnalysis.Symbolic {
     
    6970        }
    7071      });
    71       var crossoverPoint0 = crossoverPoints0.SelectRandom(random);
     72
     73      var crossoverPoint0 = crossoverPoints0.SampleRandom(random);
    7274      int level = parent0.Root.GetBranchLevel(crossoverPoint0.Child);
    7375      int length = parent0.Root.GetLength() - crossoverPoint0.Child.GetLength();
     
    137139          weights[i] /= sum;
    138140
     141#pragma warning disable 612, 618
    139142        selectedBranch = allowedBranches.SelectRandom(weights, random);
     143#pragma warning restore 612, 618
    140144      }
    141145      Swap(crossoverPoint0, selectedBranch);
  • trunk/sources/HeuristicLab.Problems.DataAnalysis.Symbolic/3.4/Crossovers/SymbolicDataAnalysisExpressionSemanticSimilarityCrossover.cs

    r12012 r12422  
    2828using HeuristicLab.Parameters;
    2929using HeuristicLab.Persistence.Default.CompositeSerializers.Storable;
     30using HeuristicLab.Random;
    3031
    3132namespace HeuristicLab.Problems.DataAnalysis.Symbolic {
     
    8182          crossoverPoints0.Add(new CutPoint(n.Parent, n));
    8283      });
    83       var crossoverPoint0 = crossoverPoints0.SelectRandom(random);
     84
     85      var crossoverPoint0 = crossoverPoints0.SampleRandom(random);
    8486      int level = parent0.Root.GetBranchLevel(crossoverPoint0.Child);
    8587      int length = parent0.Root.GetLength() - crossoverPoint0.Child.GetLength();
  • trunk/sources/HeuristicLab.Problems.DataAnalysis.Symbolic/3.4/SymbolicDataAnalysisProblem.cs

    r12103 r12422  
    321321      foreach (var op in operators.OfType<ISymbolicExpressionTreeCrossover>()) {
    322322        op.ParentsParameter.ActualName = SolutionCreator.SymbolicExpressionTreeParameter.ActualName;
    323         op.ChildParameter.ActualName = SolutionCreator.SymbolicExpressionTreeParameter.ActualName;
     323        op.SymbolicExpressionTreeParameter.ActualName = SolutionCreator.SymbolicExpressionTreeParameter.ActualName;
    324324      }
    325325      foreach (var op in operators.OfType<ISymbolicExpressionTreeManipulator>()) {
  • trunk/sources/HeuristicLab.Problems.DataAnalysis.Symbolic/3.4/Symbols/VariableConditionTreeNode.cs

    r12012 r12422  
    7474      base.ResetLocalParameters(random);
    7575      threshold = NormalDistributedRandom.NextDouble(random, Symbol.ThresholdInitializerMu, Symbol.ThresholdInitializerSigma);
     76
     77#pragma warning disable 612, 618
    7678      variableName = Symbol.VariableNames.SelectRandom(random);
     79#pragma warning restore 612, 618
     80
    7781      slope = NormalDistributedRandom.NextDouble(random, Symbol.SlopeInitializerMu, Symbol.SlopeInitializerSigma);
    7882    }
     
    8286      double x = NormalDistributedRandom.NextDouble(random, Symbol.ThresholdManipulatorMu, Symbol.ThresholdManipulatorSigma);
    8387      threshold = threshold + x * shakingFactor;
     88
     89#pragma warning disable 612, 618
    8490      variableName = Symbol.VariableNames.SelectRandom(random);
     91#pragma warning restore 612, 618
     92
    8593      x = NormalDistributedRandom.NextDouble(random, Symbol.SlopeManipulatorMu, Symbol.SlopeManipulatorSigma);
    8694      slope = slope + x * shakingFactor;
  • trunk/sources/HeuristicLab.Problems.DataAnalysis.Symbolic/3.4/Symbols/VariableTreeNode.cs

    r12012 r12422  
    6161      base.ResetLocalParameters(random);
    6262      weight = NormalDistributedRandom.NextDouble(random, Symbol.WeightMu, Symbol.WeightSigma);
     63
     64#pragma warning disable 612, 618
    6365      variableName = Symbol.VariableNames.SelectRandom(random);
     66#pragma warning restore 612, 618
    6467    }
    6568
     
    7073        double x = NormalDistributedRandom.NextDouble(random, Symbol.WeightManipulatorMu, Symbol.WeightManipulatorSigma);
    7174        weight = weight + x * shakingFactor;
    72       } else {       
     75      } else {
    7376        double x = NormalDistributedRandom.NextDouble(random, 1.0, Symbol.MultiplicativeWeightManipulatorSigma);
    7477        weight = weight * x;
    7578      }
     79#pragma warning disable 612, 618
    7680      variableName = Symbol.VariableNames.SelectRandom(random);
     81#pragma warning restore 612, 618
    7782    }
    7883
  • trunk/sources/HeuristicLab.Problems.GrammaticalEvolution

    • Property svn:mergeinfo set to (toggle deleted branches)
      /branches/SymbolicExpressionTreeEncoding/HeuristicLab.Problems.GrammaticalEvolutionmergedeligible
      /stable/HeuristicLab.Problems.GrammaticalEvolutionmergedeligible
      /branches/1721-RandomForestPersistence/HeuristicLab.Problems.GrammaticalEvolution10321-10322
      /branches/Algorithms.GradientDescent/HeuristicLab.Problems.GrammaticalEvolution5516-5520
      /branches/Benchmarking/sources/HeuristicLab.Problems.GrammaticalEvolution6917-7005
      /branches/CloningRefactoring/HeuristicLab.Problems.GrammaticalEvolution4656-4721
      /branches/CodeEditor/HeuristicLab.Problems.GrammaticalEvolution11700-11806
      /branches/DataAnalysis Refactoring/HeuristicLab.Problems.GrammaticalEvolution5471-5808
      /branches/DataAnalysis SolutionEnsembles/HeuristicLab.Problems.GrammaticalEvolution5815-6180
      /branches/DataAnalysis/HeuristicLab.Problems.GrammaticalEvolution4458-4459,​4462,​4464
      /branches/DataPreprocessing/HeuristicLab.Problems.GrammaticalEvolution10085-11101
      /branches/GP.Grammar.Editor/HeuristicLab.Problems.GrammaticalEvolution6284-6795
      /branches/GP.Symbols (TimeLag, Diff, Integral)/HeuristicLab.Problems.GrammaticalEvolution5060
      /branches/HLScript/HeuristicLab.Problems.GrammaticalEvolution10331-10358
      /branches/HeuristicLab.Problems.DataAnalysis.Trading/HeuristicLab.Problems.GrammaticalEvolution6123-9799
      /branches/LogResidualEvaluator/HeuristicLab.Problems.GrammaticalEvolution10202-10483
      /branches/NET40/sources/HeuristicLab.Problems.GrammaticalEvolution5138-5162
      /branches/NSGA-II Changes/HeuristicLab.Problems.GrammaticalEvolution12033-12122
      /branches/ParallelEngine/HeuristicLab.Problems.GrammaticalEvolution5175-5192
      /branches/ProblemInstancesRegressionAndClassification/HeuristicLab.Problems.GrammaticalEvolution7568-7810
      /branches/QAPAlgorithms/HeuristicLab.Problems.GrammaticalEvolution6350-6627
      /branches/Restructure trunk solution/HeuristicLab.Problems.GrammaticalEvolution6828
      /branches/RuntimeOptimizer/HeuristicLab.Problems.GrammaticalEvolution8943-9078
      /branches/ScatterSearch (trunk integration)/HeuristicLab.Problems.GrammaticalEvolution7787-8333
      /branches/SlaveShutdown/HeuristicLab.Problems.GrammaticalEvolution8944-8956
      /branches/SpectralKernelForGaussianProcesses/HeuristicLab.Problems.GrammaticalEvolution10204-10479
      /branches/SuccessProgressAnalysis/HeuristicLab.Problems.GrammaticalEvolution5370-5682
      /branches/Trunk/HeuristicLab.Problems.GrammaticalEvolution6829-6865
      /branches/UnloadJobs/HeuristicLab.Problems.GrammaticalEvolution9168-9215
      /branches/VNS/HeuristicLab.Problems.GrammaticalEvolution5594-5752
      /branches/histogram/HeuristicLab.Problems.GrammaticalEvolution5959-6341
  • trunk/sources/HeuristicLab.Problems.GrammaticalEvolution/3.3/ArtificialAnt/GEArtificialAntEvaluator.cs

    r12012 r12422  
    4949    }
    5050    // phenotype:
    51     public ILookupParameter<SymbolicExpressionTree> SymbolicExpressionTreeParameter {
    52       get { return (ILookupParameter<SymbolicExpressionTree>)Parameters["SymbolicExpressionTree"]; }
     51    public ILookupParameter<ISymbolicExpressionTree> SymbolicExpressionTreeParameter {
     52      get { return (ILookupParameter<ISymbolicExpressionTree>)Parameters["SymbolicExpressionTree"]; }
    5353    }
    5454    public ILookupParameter<BoolMatrix> WorldParameter {
     
    8484      Parameters.Add(new LookupParameter<DoubleValue>("Quality", "The quality of the evaluated artificial ant solution."));
    8585      Parameters.Add(new LookupParameter<IntegerVector>("IntegerVector", "The artificial ant solution encoded as an integer vector genome."));
    86       Parameters.Add(new LookupParameter<SymbolicExpressionTree>("SymbolicExpressionTree", "The artificial ant solution encoded as a symbolic expression tree that should be evaluated"));
     86      Parameters.Add(new LookupParameter<ISymbolicExpressionTree>("SymbolicExpressionTree", "The artificial ant solution encoded as a symbolic expression tree that should be evaluated"));
    8787      Parameters.Add(new LookupParameter<BoolMatrix>("World", "The world for the artificial ant with scattered food items."));
    8888      Parameters.Add(new LookupParameter<IntValue>("MaxTimeSteps", "The maximal number of time steps that the artificial ant should be simulated."));
     
    9393      Parameters.Add(new LookupParameter<IntMatrix>("Bounds", "The integer number range in which the single genomes of a genotype are created."));
    9494      Parameters.Add(new LookupParameter<IntValue>("MaximumExpressionLength", "Maximal length of the expression to control the artificial ant (genotype length)."));
     95    }
     96
     97    [StorableHook(HookType.AfterDeserialization)]
     98    private void AfterDeserialization() {
     99      // BackwardsCompatibility3.3
     100      #region Backwards compatible code, remove with 3.4
     101
     102      if (Parameters.ContainsKey("SymbolicExpressionTree") &&
     103          Parameters["SymbolicExpressionTree"] is ILookupParameter<SymbolicExpressionTree>) {
     104        Parameters.Remove("SymbolicExpressionTree");
     105        Parameters.Add(new LookupParameter<ISymbolicExpressionTree>("SymbolicExpressionTree", "The artificial ant solution encoded as a symbolic expression tree that should be evaluated"));
     106      }
     107
     108      #endregion
     109
    95110    }
    96111
  • trunk/sources/HeuristicLab.Problems.GrammaticalEvolution/3.3/Mappers/GenotypeToPhenotypeMapper.cs

    r12012 r12422  
    3131using HeuristicLab.Persistence.Default.CompositeSerializers.Storable;
    3232using HeuristicLab.Problems.GrammaticalEvolution.Mappers;
     33using HeuristicLab.Random;
    3334
    3435namespace HeuristicLab.Problems.GrammaticalEvolution {
     
    6869      if (!possibleSymbolsList.Any()) return null;
    6970
    70       var newNode = possibleSymbolsList.SelectRandom(random).CreateTreeNode();
     71      var newNode = possibleSymbolsList.SampleRandom(random).CreateTreeNode();
    7172      if (newNode.HasLocalParameters) newNode.ResetLocalParameters(random);
    7273      return newNode;
  • trunk/sources/HeuristicLab.Problems.GrammaticalEvolution/3.3/Mappers/RandomMapper.cs

    r12012 r12422  
    2929using HeuristicLab.Encodings.SymbolicExpressionTreeEncoding;
    3030using HeuristicLab.Persistence.Default.CompositeSerializers.Storable;
     31using HeuristicLab.Random;
    3132
    3233namespace HeuristicLab.Problems.GrammaticalEvolution {
     
    102103        } else {
    103104          // similar to PIGEMapper, but here the current node is determined randomly ...
    104           ISymbolicExpressionTreeNode current = nonTerminals.SelectRandom(random);
     105          ISymbolicExpressionTreeNode current = nonTerminals.SampleRandom(random);
    105106          nonTerminals.Remove(current);
    106107
  • trunk/sources/HeuristicLab.Problems.LawnMower

    • Property svn:mergeinfo set to (toggle deleted branches)
      /branches/HLScript/HeuristicLab.Problems.LawnMowermergedeligible
      /branches/SymbolicExpressionTreeEncoding/HeuristicLab.Problems.LawnMowermergedeligible
      /stable/HeuristicLab.Problems.LawnMowermergedeligible
      /branches/1721-RandomForestPersistence/HeuristicLab.Problems.LawnMower10321-10322
      /branches/Algorithms.GradientDescent/HeuristicLab.Problems.LawnMower5516-5520
      /branches/Benchmarking/sources/HeuristicLab.Problems.LawnMower6917-7005
      /branches/CloningRefactoring/HeuristicLab.Problems.LawnMower4656-4721
      /branches/CodeEditor/HeuristicLab.Problems.LawnMower11700-11806
      /branches/DataAnalysis Refactoring/HeuristicLab.Problems.LawnMower5471-5808
      /branches/DataAnalysis SolutionEnsembles/HeuristicLab.Problems.LawnMower5815-6180
      /branches/DataAnalysis/HeuristicLab.Problems.LawnMower4458-4459,​4462,​4464
      /branches/DataPreprocessing/HeuristicLab.Problems.LawnMower10085-11101
      /branches/GP.Grammar.Editor/HeuristicLab.Problems.LawnMower6284-6795
      /branches/GP.Symbols (TimeLag, Diff, Integral)/HeuristicLab.Problems.LawnMower5060
      /branches/HeuristicLab.Problems.DataAnalysis.Trading/HeuristicLab.Problems.LawnMower6123-9799
      /branches/LogResidualEvaluator/HeuristicLab.Problems.LawnMower10202-10483
      /branches/NET40/sources/HeuristicLab.Problems.LawnMower5138-5162
      /branches/NSGA-II Changes/HeuristicLab.Problems.LawnMower12033-12122
      /branches/ParallelEngine/HeuristicLab.Problems.LawnMower5175-5192
      /branches/ProblemInstancesRegressionAndClassification/HeuristicLab.Problems.LawnMower7568-7810
      /branches/QAPAlgorithms/HeuristicLab.Problems.LawnMower6350-6627
      /branches/Restructure trunk solution/HeuristicLab.Problems.LawnMower6828
      /branches/RuntimeOptimizer/HeuristicLab.Problems.LawnMower8943-9078
      /branches/ScatterSearch (trunk integration)/HeuristicLab.Problems.LawnMower7787-8333
      /branches/SlaveShutdown/HeuristicLab.Problems.LawnMower8944-8956
      /branches/SpectralKernelForGaussianProcesses/HeuristicLab.Problems.LawnMower10204-10479
      /branches/SuccessProgressAnalysis/HeuristicLab.Problems.LawnMower5370-5682
      /branches/Trunk/HeuristicLab.Problems.LawnMower6829-6865
      /branches/UnloadJobs/HeuristicLab.Problems.LawnMower9168-9215
      /branches/VNS/HeuristicLab.Problems.LawnMower5594-5752
      /branches/histogram/HeuristicLab.Problems.LawnMower5959-6341
  • trunk/sources/HeuristicLab.Problems.LawnMower/3.3/Problem.cs

    r12012 r12422  
    185185      foreach (var op in operators.OfType<ISymbolicExpressionTreeCrossover>()) {
    186186        op.ParentsParameter.ActualName = SolutionCreator.SymbolicExpressionTreeParameter.ActualName;
    187         op.ChildParameter.ActualName = SolutionCreator.SymbolicExpressionTreeParameter.ActualName;
     187        op.SymbolicExpressionTreeParameter.ActualName = SolutionCreator.SymbolicExpressionTreeParameter.ActualName;
    188188      }
    189189      foreach (var op in operators.OfType<ISymbolicExpressionTreeManipulator>()) {
Note: See TracChangeset for help on using the changeset viewer.