Free cookie consent management tool by TermsFeed Policy Generator

source: branches/HeuristicLab.MetaOptimization/HeuristicLab.Problems.MetaOptimization/3.3/Encoding/SymbolicExpressionGrammar/SymbolicExpressionGrammarValueConfiguration.cs @ 9596

Last change on this file since 9596 was 6197, checked in by cneumuel, 14 years ago

#1215

  • some fixes
File size: 2.6 KB
RevLine 
[6023]1using System.Linq;
2using HeuristicLab.Common;
3using HeuristicLab.Core;
4using HeuristicLab.Encodings.SymbolicExpressionTreeEncoding;
5using HeuristicLab.Persistence.Default.CompositeSerializers.Storable;
6
7namespace HeuristicLab.Problems.MetaOptimization {
8  [StorableClass]
9  public class SymbolicExpressionGrammarValueConfiguration : ParameterizedValueConfiguration {
10
11    #region Constructors and Cloning
12    [StorableConstructor]
13    protected SymbolicExpressionGrammarValueConfiguration(bool deserializing) : base(deserializing) { }
14    public SymbolicExpressionGrammarValueConfiguration() : base() { }
15    public SymbolicExpressionGrammarValueConfiguration(ISymbolicExpressionGrammar grammar) {
16      this.IsOptimizable = true;
17      this.ActualValue = new ConstrainedValue(grammar, grammar.GetType(), new ItemSet<IItem> { grammar }, false);
18    }
19    protected SymbolicExpressionGrammarValueConfiguration(SymbolicExpressionGrammarValueConfiguration original, Cloner cloner)
20      : base(original, cloner) {
21    }
22    public override IDeepCloneable Clone(Cloner cloner) {
23      return new SymbolicExpressionGrammarValueConfiguration(this, cloner);
24    }
25    #endregion
26
27    protected override void PopulateParameterConfigurations(IItem item, bool discoverValidValues) {
28      var grammar = (ISymbolicExpressionGrammar)item;
29      foreach (Symbol symbol in grammar.Symbols) {
[6197]30        var svc = new SymbolValueConfiguration(symbol);
31        var pc = new SingleValuedParameterConfiguration(symbol.Name, svc);
32        svc.ParentOptimizable = pc;
[6023]33        SetOptimizeIfOnlyOneValueConfiguration(pc);
34        this.parameterConfigurations.Add(pc);
35      }
36    }
37
38    public virtual void Parameterize(ISymbolicExpressionGrammar grammar) {
39      foreach (Symbol symbol in grammar.Symbols) {
[6197]40        var symbolValueConfiguration = (SymbolValueConfiguration)this.parameterConfigurations.Single(pc => pc.Name == symbol.Name).ValueConfigurations.First();
41        symbolValueConfiguration.Parameterize(symbol);
[6023]42      }
43    }
44
45    /// <summary>
46    /// If only 1 parameter exists (usually this is InitialFrequency), then set it to Optimize=true,
47    /// because this is what the user usually wants to do. avoids additional click.
48    /// </summary>
49    private static void SetOptimizeIfOnlyOneValueConfiguration(SingleValuedParameterConfiguration pc) {
50      var vc = pc.ValueConfigurations[0] as ParameterizedValueConfiguration;
51      if (vc != null) {
52        if (vc.ParameterConfigurations.Count == 1) {
53          vc.ParameterConfigurations.Single().Optimize = true;
54        }
55      }
56    }
57  }
58}
Note: See TracBrowser for help on using the repository browser.