Free cookie consent management tool by TermsFeed Policy Generator

source: branches/HeuristicLab.Problems.GrammaticalOptimization-gkr/HeuristicLab.Algorithms.GeneticProgramming/GenericSymbExprProblem.cs @ 12308

Last change on this file since 12308 was 11857, checked in by gkronber, 10 years ago

#2283: solution reorg

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<IGenericSymbExprEvaluator, 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 GenericSymbExprEvaluator Evaluator {
54      get { return (GenericSymbExprEvaluator)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 GenericSymbExprEvaluator(problem.ConvertTreeToSentence, problem.Evaluate), new ProbabilisticTreeCreator()) {
65      var grammar = new GenericSymbExprGrammar(problem.TreeBasedGPGrammar);
66      Parameters.Add(new ValueParameter<ISymbolicExpressionGrammar>(SymbolicExpressionTreeGrammarParameterName, grammar));
67      Parameters.Add(new FixedValueParameter<IntValue>(MaximumSymbolicExpressionTreeLengthParameterName, new IntValue(50)));
68      Parameters.Add(new FixedValueParameter<IntValue>(MaximumSymbolicExpressionTreeDepthParameterName, new IntValue(15)));
69
70      Maximization = new BoolValue(true);
71      BestKnownQuality = new DoubleValue(1.0);
72
73      Operators.AddRange(ApplicationManager.Manager.GetInstances<ISymbolicExpressionTreeOperator>());
74    }
75
76    public override IDeepCloneable Clone(Cloner cloner) {
77      return new GenericSymbExprProblem(this, cloner);
78    }
79  }
80}
Note: See TracBrowser for help on using the repository browser.