Free cookie consent management tool by TermsFeed Policy Generator

Ignore:
Timestamp:
08/22/15 14:27:37 (9 years ago)
Author:
bburlacu
Message:

#1772: Merge trunk changes. Remove dead code from the genealogy analyzer.

Location:
branches/HeuristicLab.EvolutionTracking/HeuristicLab.Encodings.SymbolicExpressionTreeEncoding
Files:
3 edited

Legend:

Unmodified
Added
Removed
  • branches/HeuristicLab.EvolutionTracking/HeuristicLab.Encodings.SymbolicExpressionTreeEncoding

  • branches/HeuristicLab.EvolutionTracking/HeuristicLab.Encodings.SymbolicExpressionTreeEncoding/3.4/Crossovers/SubtreeCrossover.cs

    r12155 r12891  
    2828using HeuristicLab.Parameters;
    2929using HeuristicLab.Persistence.Default.CompositeSerializers.Storable;
     30using HeuristicLab.Random;
    3031
    3132namespace HeuristicLab.Encodings.SymbolicExpressionTreeEncoding {
     
    134135      parent0.Root.ForEachNodePostfix((n) => {
    135136        if (n.SubtreeCount > 0 && n != parent0.Root) {
    136           foreach (var child in n.Subtrees) {
     137          //avoid linq to reduce memory pressure
     138          for (int i = 0; i < n.SubtreeCount; i++) {
     139            var child = n.GetSubtree(i);
    137140            if (child.GetLength() <= maxBranchLength &&
    138141                child.GetDepth() <= maxBranchDepth) {
     
    181184                                   select branch).ToList();
    182185        if (allowedInternalBranches.Count > 0) {
    183           return allowedInternalBranches.SelectRandom(random);
     186          return allowedInternalBranches.SampleRandom(random);
     187
    184188        } else {
    185189          // no internal nodes allowed => select leaf nodes
     
    187191                                 where branch == null || branch.SubtreeCount == 0
    188192                                 select branch).ToList();
    189           return allowedLeafBranches.SelectRandom(random);
     193          return allowedLeafBranches.SampleRandom(random);
    190194        }
    191195      } else {
     
    195199                               select branch).ToList();
    196200        if (allowedLeafBranches.Count > 0) {
    197           return allowedLeafBranches.SelectRandom(random);
     201          return allowedLeafBranches.SampleRandom(random);
    198202        } else {
    199203          allowedInternalBranches = (from branch in branches
    200204                                     where branch != null && branch.SubtreeCount > 0
    201205                                     select branch).ToList();
    202           return allowedInternalBranches.SelectRandom(random);
     206          return allowedInternalBranches.SampleRandom(random);
     207
    203208        }
    204209      }
  • branches/HeuristicLab.EvolutionTracking/HeuristicLab.Encodings.SymbolicExpressionTreeEncoding/3.4/Crossovers/SymbolicExpressionTreeCrossover.cs

    r12155 r12891  
    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;
     
    7468
    7569    public abstract ISymbolicExpressionTree Crossover(IRandom random, ISymbolicExpressionTree parent0, ISymbolicExpressionTree parent1);
     70
     71
     72    [StorableHook(HookType.AfterDeserialization)]
     73    private void AfterDeserialization() {
     74      // BackwardsCompatibility3.4
     75      #region Backwards compatible code, remove with 3.5
     76      if (Parameters.ContainsKey("Child")) {
     77        var oldChildParameter = (ILookupParameter<ISymbolicExpressionTree>)Parameters["Child"];
     78        Parameters.Remove("Child");
     79        SymbolicExpressionTreeParameter.ActualName = oldChildParameter.ActualName;
     80      }
     81      #endregion
     82    }
    7683  }
    7784}
Note: See TracChangeset for help on using the changeset viewer.