Free cookie consent management tool by TermsFeed Policy Generator

Ignore:
Timestamp:
02/03/15 14:29:06 (9 years ago)
Author:
mkommend
Message:

#2268: Merged r11494, r11495, r11496, r11497, r11498, r11504, r11532, r11536 into stable.

Location:
stable
Files:
3 edited

Legend:

Unmodified
Added
Removed
  • stable

  • stable/HeuristicLab.Encodings.SymbolicExpressionTreeEncoding

  • stable/HeuristicLab.Encodings.SymbolicExpressionTreeEncoding/3.4/Creators/SymbolicExpressionTreeCreator.cs

    r11170 r11874  
    3333  public abstract class SymbolicExpressionTreeCreator : SymbolicExpressionTreeOperator, ISymbolicExpressionTreeCreator {
    3434    private const string SymbolicExpressionTreeParameterName = "SymbolicExpressionTree";
     35    private const string SymbolicExpressionTreeGrammarParameterName = "SymbolicExpressionTreeGrammar";
     36    private const string ClonedSymbolicExpressionTreeGrammarParameterName = "ClonedSymbolicExpressionTreeGrammar";
     37
    3538    #region Parameter Properties
    3639    public ILookupParameter<ISymbolicExpressionTree> SymbolicExpressionTreeParameter {
    3740      get { return (ILookupParameter<ISymbolicExpressionTree>)Parameters[SymbolicExpressionTreeParameterName]; }
    3841    }
     42
     43    public IValueLookupParameter<ISymbolicExpressionGrammar> SymbolicExpressionTreeGrammarParameter {
     44      get { return (IValueLookupParameter<ISymbolicExpressionGrammar>)Parameters[SymbolicExpressionTreeGrammarParameterName]; }
     45    }
     46
     47    public ILookupParameter<ISymbolicExpressionGrammar> ClonedSymbolicExpressionTreeGrammarParameter {
     48      get { return (ILookupParameter<ISymbolicExpressionGrammar>)Parameters[ClonedSymbolicExpressionTreeGrammarParameterName]; }
     49    }
    3950    #endregion
    4051
    41     #region Properties
    42     public ISymbolicExpressionTree SymbolicExpressionTree {
    43       get { return SymbolicExpressionTreeParameter.ActualValue; }
    44       set { SymbolicExpressionTreeParameter.ActualValue = value; }
    45     }
    46 
    47     #endregion
    4852    [StorableConstructor]
    4953    protected SymbolicExpressionTreeCreator(bool deserializing) : base(deserializing) { }
     
    5256      : base() {
    5357      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    }
     63
     64    [StorableHook(HookType.AfterDeserialization)]
     65    private void AfterDeserialization() {
     66      if (!Parameters.ContainsKey(ClonedSymbolicExpressionTreeGrammarParameterName))
     67        Parameters.Add(new LookupParameter<ISymbolicExpressionGrammar>(ClonedSymbolicExpressionTreeGrammarParameterName, "An immutable clone of the concrete grammar that is actually used to create and manipulate trees."));
    5468    }
    5569
    5670    public override IOperation InstrumentedApply() {
    57       SymbolicExpressionTree = Create(Random);
     71      if (ClonedSymbolicExpressionTreeGrammarParameter.ActualValue == null) {
     72        SymbolicExpressionTreeGrammarParameter.ActualValue.ReadOnly = true;
     73        IScope globalScope = ExecutionContext.Scope;
     74        while (globalScope.Parent != null)
     75          globalScope = globalScope.Parent;
     76
     77        globalScope.Variables.Add(new Variable(ClonedSymbolicExpressionTreeGrammarParameterName,
     78          (ISymbolicExpressionGrammar)SymbolicExpressionTreeGrammarParameter.ActualValue.Clone()));
     79      }
     80      SymbolicExpressionTreeParameter.ActualValue = Create(Random);
    5881      return base.InstrumentedApply();
    5982    }
Note: See TracChangeset for help on using the changeset viewer.