Free cookie consent management tool by TermsFeed Policy Generator

source: branches/HeuristicLab.Problems.GrammaticalOptimization/HeuristicLab.Problems.GrammaticalOptimization/TreeRepresentation/GenericSymbExprProblem.cs @ 11848

Last change on this file since 11848 was 11848, checked in by gkronber, 9 years ago

#2283 solution reorganization

File size: 3.7 KB
Line 
1using System;
2using System.Collections.Generic;
3using System.Diagnostics;
4using System.Linq;
5using System.Text;
6using System.Text.RegularExpressions;
7using HeuristicLab.Common;
8using HeuristicLab.Core;
9using HeuristicLab.Data;
10using HeuristicLab.Encodings.SymbolicExpressionTreeEncoding;
11using HeuristicLab.Optimization;
12using HeuristicLab.Parameters;
13using HeuristicLab.Persistence.Default.CompositeSerializers.Storable;
14using HeuristicLab.PluginInfrastructure;
15
16namespace HeuristicLab.Problems.GrammaticalOptimization {
17  [NonDiscoverableType]
18  [StorableClass]
19  [Item("GenericSymbExprProblem", "Represents grammatical optimization problems (using a symbolic expression tree encoding).")]
20  public class GenericSymbExprProblem : SingleObjectiveHeuristicOptimizationProblem<IGrammaticalOptimizationEvaluator, ISymbolicExpressionTreeCreator> {
21    #region string consts
22    private const string SymbolicExpressionTreeGrammarParameterName = "SymbolicExpressionTreeGrammar";
23    private const string MaximumSymbolicExpressionTreeDepthParameterName = "MaximumSymbolicExpressionTreeDepth";
24    private const string MaximumSymbolicExpressionTreeLengthParameterName = "MaximumSymbolicExpressionTreeLength";
25
26    #endregion
27
28    #region parameter properties
29    public IValueParameter<ISymbolicExpressionTreeGrammar> SymbolicExpressionTreeGrammarParameter {
30      get { return (IValueParameter<ISymbolicExpressionTreeGrammar>)Parameters[SymbolicExpressionTreeGrammarParameterName]; }
31    }
32    public IFixedValueParameter<IntValue> MaximumSymbolicExpressionTreeDepthParameter {
33      get { return (IFixedValueParameter<IntValue>)Parameters[MaximumSymbolicExpressionTreeDepthParameterName]; }
34    }
35    public IFixedValueParameter<IntValue> MaximumSymbolicExpressionTreeLengthParameter {
36      get { return (IFixedValueParameter<IntValue>)Parameters[MaximumSymbolicExpressionTreeLengthParameterName]; }
37    }
38    #endregion
39
40
41    #region properties
42
43    public ISymbolicExpressionTreeGrammar SymbolicExpressionTreeGrammar {
44      get { return SymbolicExpressionTreeGrammarParameter.Value; }
45      set { SymbolicExpressionTreeGrammarParameter.Value = value; }
46    }
47    public IntValue MaximumSymbolicExpressionTreeDepth {
48      get { return MaximumSymbolicExpressionTreeDepthParameter.Value; }
49    }
50    public IntValue MaximumSymbolicExpressionTreeLength {
51      get { return MaximumSymbolicExpressionTreeLengthParameter.Value; }
52    }
53    public new GrammaticalOptimizationEvaluator Evaluator {
54      get { return (GrammaticalOptimizationEvaluator)base.Evaluator; }
55    }
56
57    #endregion
58    [StorableConstructor]
59    public GenericSymbExprProblem(bool deserializing) : base(deserializing) { }
60
61    public GenericSymbExprProblem(GenericSymbExprProblem original, Cloner cloner) : base(original, cloner) { }
62
63    public GenericSymbExprProblem(ISymbolicExpressionTreeProblem problem)
64      : base(new GrammaticalOptimizationEvaluator(problem.ConvertTreeToSentence, problem.Evaluate), new ProbabilisticTreeCreator()) {
65      Parameters.Add(new ValueParameter<ISymbolicExpressionGrammar>(SymbolicExpressionTreeGrammarParameterName, problem.SymbolicExpressionGrammar));
66      Parameters.Add(new FixedValueParameter<IntValue>(MaximumSymbolicExpressionTreeLengthParameterName, new IntValue(50)));
67      Parameters.Add(new FixedValueParameter<IntValue>(MaximumSymbolicExpressionTreeDepthParameterName, new IntValue(15)));
68
69      Maximization = new BoolValue(true);
70      BestKnownQuality = new DoubleValue(1.0);
71
72      Operators.AddRange(ApplicationManager.Manager.GetInstances<ISymbolicExpressionTreeOperator>());
73    }
74
75    public override IDeepCloneable Clone(Cloner cloner) {
76      return new GenericSymbExprProblem(this, cloner);
77    }
78  }
79}
Note: See TracBrowser for help on using the repository browser.