Free cookie consent management tool by TermsFeed Policy Generator

Ignore:
Timestamp:
07/10/15 12:02:20 (9 years ago)
Author:
mkommend
Message:

#2320: Merged r12422, r12423, r12424, r12480, r12481 and r12482 into stable.

Location:
stable
Files:
4 edited

Legend:

Unmodified
Added
Removed
  • stable

  • stable/HeuristicLab.Encodings.SymbolicExpressionTreeEncoding

  • stable/HeuristicLab.Encodings.SymbolicExpressionTreeEncoding/3.4/Crossovers/SubtreeCrossover.cs

    r12702 r12706  
    2828using HeuristicLab.Parameters;
    2929using HeuristicLab.Persistence.Default.CompositeSerializers.Storable;
     30using HeuristicLab.Random;
    3031
    3132namespace HeuristicLab.Encodings.SymbolicExpressionTreeEncoding {
     
    183184                                   select branch).ToList();
    184185        if (allowedInternalBranches.Count > 0) {
    185           return allowedInternalBranches.SelectRandom(random);
     186          return allowedInternalBranches.SampleRandom(random);
     187
    186188        } else {
    187189          // no internal nodes allowed => select leaf nodes
     
    189191                                 where branch == null || branch.SubtreeCount == 0
    190192                                 select branch).ToList();
    191           return allowedLeafBranches.SelectRandom(random);
     193          return allowedLeafBranches.SampleRandom(random);
    192194        }
    193195      } else {
     
    197199                               select branch).ToList();
    198200        if (allowedLeafBranches.Count > 0) {
    199           return allowedLeafBranches.SelectRandom(random);
     201          return allowedLeafBranches.SampleRandom(random);
    200202        } else {
    201203          allowedInternalBranches = (from branch in branches
    202204                                     where branch != null && branch.SubtreeCount > 0
    203205                                     select branch).ToList();
    204           return allowedInternalBranches.SelectRandom(random);
     206          return allowedInternalBranches.SampleRandom(random);
     207
    205208        }
    206209      }
  • stable/HeuristicLab.Encodings.SymbolicExpressionTreeEncoding/3.4/Crossovers/SymbolicExpressionTreeCrossover.cs

    r12009 r12706  
    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.