Free cookie consent management tool by TermsFeed Policy Generator

Changeset 12319


Ignore:
Timestamp:
04/16/15 11:05:23 (9 years ago)
Author:
mkommend
Message:

#2320: Added simple symbol and grammar for symbolic expression encoding.

Location:
branches/SymbolicExpressionTreeEncoding/HeuristicLab.Encodings.SymbolicExpressionTreeEncoding/3.4
Files:
2 added
3 edited

Legend:

Unmodified
Added
Removed
  • branches/SymbolicExpressionTreeEncoding/HeuristicLab.Encodings.SymbolicExpressionTreeEncoding/3.4/Grammars/SymbolicExpressionGrammarBase.cs

    r12012 r12319  
    308308    }
    309309    public virtual IEnumerable<ISymbol> AllowedSymbols {
    310       get { foreach (var s in Symbols) if (s.Enabled) yield return s; }
     310      get { return Symbols.Where(s => s.Enabled); }
    311311    }
    312312    public virtual bool ContainsSymbol(ISymbol symbol) {
     
    510510      if (suppressEvents) return;
    511511      var handler = Changed;
    512       if (handler != null) Changed(this, EventArgs.Empty);
     512      if (handler != null) handler(this, EventArgs.Empty);
    513513    }
    514514  }
  • branches/SymbolicExpressionTreeEncoding/HeuristicLab.Encodings.SymbolicExpressionTreeEncoding/3.4/HeuristicLab.Encodings.SymbolicExpressionTreeEncoding-3.4.csproj

    r12196 r12319  
    187187    <Compile Include="Formatters\SymbolicExpressionTreeHierarchicalFormatter.cs" />
    188188    <Compile Include="Grammars\EmptySymbolicExpressionTreeGrammar.cs" />
     189    <Compile Include="Grammars\SimpleSymbolicExpressionGrammar.cs" />
    189190    <Compile Include="Interfaces\IReadOnlySymbol.cs" />
    190191    <Compile Include="Interfaces\ISymbolicExpressionGrammar.cs" />
     
    236237    <Compile Include="Symbols\ArgumentTreeNode.cs" />
    237238    <Compile Include="Symbols\GroupSymbol.cs" />
     239    <Compile Include="Symbols\SimpleSymbol.cs" />
    238240    <Compile Include="Symbols\StartSymbol.cs" />
    239241    <Compile Include="Symbols\InvokeFunction.cs" />
  • branches/SymbolicExpressionTreeEncoding/HeuristicLab.Encodings.SymbolicExpressionTreeEncoding/3.4/SymbolicExpressionTreeEncoding.cs

    r12316 r12319  
    3636  [Item("SymbolicExpressionTreeEncoding", "Describes a symbolic expression tree encoding.")]
    3737  [StorableClass]
    38   public class SymbolicExpressionTreeEncoding : Encoding<ISymbolicExpressionTreeCreator> {
     38  public sealed class SymbolicExpressionTreeEncoding : Encoding<ISymbolicExpressionTreeCreator> {
    3939    #region Encoding Parameters
    4040    [Storable]
     
    159159
    160160    [StorableConstructor]
    161     public SymbolicExpressionTreeEncoding(bool deserializing) : base(deserializing) { }
    162     public SymbolicExpressionTreeEncoding() : this("SymbolicExpressionTree") { }
    163 
    164     public SymbolicExpressionTreeEncoding(string name)
     161    private SymbolicExpressionTreeEncoding(bool deserializing) : base(deserializing) { }
     162    public SymbolicExpressionTreeEncoding(ISymbolicExpressionGrammar grammar) : this("SymbolicExpressionTree", grammar, 50, 50) { }
     163    public SymbolicExpressionTreeEncoding(ISymbolicExpressionGrammar grammar, int maximumLength, int maximumDepth) : this("SymbolicExpressionTree", grammar, maximumLength, maximumDepth) { }
     164    public SymbolicExpressionTreeEncoding(string name, ISymbolicExpressionGrammar grammar, int maximumLength, int maximumDepth)
    165165      : base(name) {
    166       treeLengthParameter = new FixedValueParameter<IntValue>("Maximium Tree Length", "Maximal length of the symbolic expression.", new IntValue(50));
    167       treeDepthParameter = new FixedValueParameter<IntValue>("Maximum Tree Depth", "Maximal depth of the symbolic expression. The minimum depth needed for the algorithm is 3 because two levels are reserved for the ProgramRoot and the Start symbol.", new IntValue(50));
    168       grammarParameter = new ValueParameter<ISymbolicExpressionGrammar>("Grammar", "The grammar that should be used for symbolic expression tree.");
     166      treeLengthParameter = new FixedValueParameter<IntValue>("Maximium Tree Length", "Maximal length of the symbolic expression.", new IntValue(maximumLength));
     167      treeDepthParameter = new FixedValueParameter<IntValue>("Maximum Tree Depth", "Maximal depth of the symbolic expression. The minimum depth needed for the algorithm is 3 because two levels are reserved for the ProgramRoot and the Start symbol.", new IntValue(maximumDepth));
     168      grammarParameter = new ValueParameter<ISymbolicExpressionGrammar>("Grammar", "The grammar that should be used for symbolic expression tree.", grammar);
    169169      functionDefinitionsParameter = new FixedValueParameter<IntValue>("Function Definitions", "Maximal number of automatically defined functions", new IntValue(0));
    170170      functionArgumentsParameter = new FixedValueParameter<IntValue>("Function Arguments", "Maximal number of arguments of automatically defined functions.", new IntValue(0));
    171 
    172       //TODO set default grammar
    173171
    174172      Parameters.Add(treeLengthParameter);
     
    185183    private SymbolicExpressionTreeEncoding(SymbolicExpressionTreeEncoding original, Cloner cloner)
    186184      : base(original, cloner) {
    187       TreeLengthParameter = cloner.Clone(original.TreeLengthParameter);
    188       TreeDepthParameter = cloner.Clone(original.TreeDepthParameter);
    189       GrammarParameter = cloner.Clone(original.GrammarParameter);
    190       FunctionDefinitionsParameter = cloner.Clone(original.FunctionDefinitionsParameter);
    191       FunctionArgumentsParameter = cloner.Clone(original.FunctionArgumentsParameter);
     185      treeLengthParameter = cloner.Clone(original.TreeLengthParameter);
     186      treeDepthParameter = cloner.Clone(original.TreeDepthParameter);
     187      grammarParameter = cloner.Clone(original.GrammarParameter);
     188      functionDefinitionsParameter = cloner.Clone(original.FunctionDefinitionsParameter);
     189      functionArgumentsParameter = cloner.Clone(original.FunctionArgumentsParameter);
    192190      RegisterParameterEvents();
    193191    }
     
    208206    private void OnGrammarParameterChanged() {
    209207      RegisterGrammarParameterEvents();
     208      FunctionArguments = Grammar.MaximumFunctionArguments;
     209      FunctionDefinitions = Grammar.MaximumFunctionDefinitions;
    210210      ConfigureOperators(Operators);
    211211    }
     
    230230
    231231
    232     private void RegisterLengthParameterEvents() {
    233       TreeLengthParameter.Value.ValueChanged += (o, s) => ConfigureOperators(Operators);
    234     }
    235 
    236     private void RegisterDepthParameterEvents() {
    237       TreeDepthParameter.Value.ValueChanged += (o, s) => ConfigureOperators(Operators);
    238     }
     232    private void RegisterLengthParameterEvents() { }
     233    private void RegisterDepthParameterEvents() { }
     234
    239235    private void RegisterGrammarParameterEvents() {
    240       GrammarParameter.ValueChanged += (o, s) => ConfigureOperators(Operators);
    241       GrammarParameter.Value.Changed += (o, s) => ConfigureOperators(Operators);
     236      GrammarParameter.ValueChanged += (o, s) => {
     237        FunctionArguments = Grammar.MaximumFunctionArguments;
     238        FunctionDefinitions = Grammar.MaximumFunctionDefinitions;
     239        ConfigureOperators(Operators);
     240      };
     241      GrammarParameter.Value.Changed += (o, s) => {
     242        FunctionArguments = Grammar.MaximumFunctionArguments;
     243        FunctionDefinitions = Grammar.MaximumFunctionDefinitions;
     244        ConfigureOperators(Operators);
     245      };
    242246    }
    243247
Note: See TracChangeset for help on using the changeset viewer.