Free cookie consent management tool by TermsFeed Policy Generator

Ignore:
Timestamp:
05/19/11 13:52:12 (13 years ago)
Author:
mkommend
Message:

#1532:

  • Enabled renaming of symbols
  • Fixed cloning of grammers
  • Added readonly attribute in grammars to lock grammars during the algorithm run
  • Removed useless clone method in cloner
  • Changed CheckedItemCollectionViews to enable scrolling during the locked state
File:
1 edited

Legend:

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

    r6009 r6233  
    3838    private const string MaximumSymbolicExpressionTreeDepthParameterName = "MaximumSymbolicExpressionTreeDepth";
    3939    private const string SymbolicExpressionTreeGrammarParameterName = "SymbolicExpressionTreeGrammar";
     40    private const string ClonedSymbolicExpressionTreeGrammarParameterName = "ClonedSymbolicExpressionTreeGrammar";
    4041    #region Parameter Properties
    4142    public IValueLookupParameter<IntValue> MaximumSymbolicExpressionTreeLengthParameter {
     
    4748    public IValueLookupParameter<ISymbolicExpressionGrammar> SymbolicExpressionTreeGrammarParameter {
    4849      get { return (IValueLookupParameter<ISymbolicExpressionGrammar>)Parameters[SymbolicExpressionTreeGrammarParameterName]; }
     50    }
     51    public ILookupParameter<ISymbolicExpressionGrammar> ClonedSymbolicExpressionTreeGrammarParameter {
     52      get { return (ILookupParameter<ISymbolicExpressionGrammar>)Parameters[ClonedSymbolicExpressionTreeGrammarParameterName]; }
    4953    }
    5054    #endregion
     
    5761    }
    5862    public ISymbolicExpressionGrammar SymbolicExpressionTreeGrammar {
    59       get { return SymbolicExpressionTreeGrammarParameter.ActualValue; }
     63      get { return ClonedSymbolicExpressionTreeGrammarParameter.ActualValue; }
    6064    }
    6165    #endregion
     
    6973      Parameters.Add(new ValueLookupParameter<IntValue>(MaximumSymbolicExpressionTreeDepthParameterName, "The maximal depth of the symbolic expression tree (a tree with one node has depth = 0)."));
    7074      Parameters.Add(new ValueLookupParameter<ISymbolicExpressionGrammar>(SymbolicExpressionTreeGrammarParameterName, "The tree grammar that defines the correct syntax of symbolic expression trees that should be created."));
     75      Parameters.Add(new LookupParameter<ISymbolicExpressionGrammar>(ClonedSymbolicExpressionTreeGrammarParameterName, "An immutable clone of the concrete grammar that is actually used to create and manipulate trees."));
    7176    }
    7277
     
    7479      return new ProbabilisticTreeCreator(this, cloner);
    7580    }
     81    [StorableHook(HookType.AfterDeserialization)]
     82    private void AfterDeserialization() {
     83      if (!Parameters.ContainsKey(ClonedSymbolicExpressionTreeGrammarParameterName))
     84        Parameters.Add(new LookupParameter<ISymbolicExpressionGrammar>(ClonedSymbolicExpressionTreeGrammarParameterName, "An immutable clone of the concrete grammar that is actually used to create and manipulate trees."));
     85    }
     86
     87    public override IOperation Apply() {
     88      if (ClonedSymbolicExpressionTreeGrammarParameter.ActualValue == null) {
     89        SymbolicExpressionTreeGrammarParameter.ActualValue.ReadOnly = true;
     90        IScope globalScope = ExecutionContext.Scope;
     91        while (globalScope.Parent != null)
     92          globalScope = globalScope.Parent;
     93
     94        globalScope.Variables.Add(new Variable(ClonedSymbolicExpressionTreeGrammarParameterName, (ISymbolicExpressionGrammar)SymbolicExpressionTreeGrammarParameter.ActualValue.Clone()));
     95      }
     96      return base.Apply();
     97    }
    7698
    7799    protected override ISymbolicExpressionTree Create(IRandom random) {
    78100      return Create(random, SymbolicExpressionTreeGrammar, MaximumSymbolicExpressionTreeLength.Value, MaximumSymbolicExpressionTreeDepth.Value);
    79 
    80101    }
    81102
     
    165186                                select s)
    166187                               .ToList();
     188          if (allowedSymbols.Count == 0) return false;
    167189          var weights = allowedSymbols.Select(x => x.InitialFrequency).ToList();
    168190          var selectedSymbol = allowedSymbols.SelectRandom(weights, random);
Note: See TracChangeset for help on using the changeset viewer.