Free cookie consent management tool by TermsFeed Policy Generator

Ignore:
Timestamp:
10/06/21 16:13:37 (2 years ago)
Author:
mkommend
Message:

#2997: Simplified tree creator interface and removed cloning of grammars,

File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/HeuristicLab.Encodings.SymbolicExpressionTreeEncoding/3.4/Creators/SymbolicExpressionTreeCreator.cs

    r17180 r18064  
    3737
    3838    private const string SymbolicExpressionTreeGrammarParameterName = "SymbolicExpressionTreeGrammar";
    39     private const string ClonedSymbolicExpressionTreeGrammarParameterName = "ClonedSymbolicExpressionTreeGrammar";
    4039
    4140    #region Parameter Properties
     
    4948      get { return (IValueLookupParameter<ISymbolicExpressionGrammar>)Parameters[SymbolicExpressionTreeGrammarParameterName]; }
    5049    }
    51 
    52     public ILookupParameter<ISymbolicExpressionGrammar> ClonedSymbolicExpressionTreeGrammarParameter {
    53       get { return (ILookupParameter<ISymbolicExpressionGrammar>)Parameters[ClonedSymbolicExpressionTreeGrammarParameterName]; }
    54     }
    5550    #endregion
    5651
     
    6358      Parameters.Add(new ValueLookupParameter<IntValue>(MaximumSymbolicExpressionTreeDepthParameterName, "The maximal depth of the symbolic expression tree (a tree with one node has depth = 0)."));
    6459      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."));
    66     }
    67 
    68     [StorableHook(HookType.AfterDeserialization)]
    69     private void AfterDeserialization() {
    70       if (!Parameters.ContainsKey(ClonedSymbolicExpressionTreeGrammarParameterName))
    71         Parameters.Add(new LookupParameter<ISymbolicExpressionGrammar>(ClonedSymbolicExpressionTreeGrammarParameterName, "An immutable clone of the concrete grammar that is actually used to create and manipulate trees."));
    7260    }
    7361
    7462    public override IOperation InstrumentedApply() {
    75       if (ClonedSymbolicExpressionTreeGrammarParameter.ActualValue == null) {
    76         SymbolicExpressionTreeGrammarParameter.ActualValue.ReadOnly = true;
    77         IScope globalScope = ExecutionContext.Scope;
    78         while (globalScope.Parent != null)
    79           globalScope = globalScope.Parent;
     63      var rand = RandomParameter.ActualValue;
     64      var grammar = SymbolicExpressionTreeGrammarParameter.ActualValue;
     65      var maxTreeLength = MaximumSymbolicExpressionTreeLengthParameter.ActualValue.Value;
     66      var maxTreeDepth = MaximumSymbolicExpressionTreeDepthParameter.ActualValue.Value;
    8067
    81         globalScope.Variables.Add(new Variable(ClonedSymbolicExpressionTreeGrammarParameterName,
    82           (ISymbolicExpressionGrammar)SymbolicExpressionTreeGrammarParameter.ActualValue.Clone()));
    83       }
    84       SymbolicExpressionTreeParameter.ActualValue = Create(RandomParameter.ActualValue);
     68      SymbolicExpressionTreeParameter.ActualValue = CreateTree(rand, grammar, maxTreeLength, maxTreeDepth);
    8569      return base.InstrumentedApply();
    8670    }
    87 
    88     protected abstract ISymbolicExpressionTree Create(IRandom random);
    8971    public abstract ISymbolicExpressionTree CreateTree(IRandom random, ISymbolicExpressionGrammar grammar, int maxTreeLength, int maxTreeDepth);
    9072  }
Note: See TracChangeset for help on using the changeset viewer.