[11846] | 1 | using System;
|
---|
| 2 | using System.Collections.Generic;
|
---|
| 3 | using System.Diagnostics;
|
---|
| 4 | using System.Linq;
|
---|
| 5 | using System.Text;
|
---|
| 6 | using System.Text.RegularExpressions;
|
---|
| 7 | using HeuristicLab.Common;
|
---|
| 8 | using HeuristicLab.Core;
|
---|
| 9 | using HeuristicLab.Data;
|
---|
| 10 | using HeuristicLab.Encodings.SymbolicExpressionTreeEncoding;
|
---|
| 11 | using HeuristicLab.Optimization;
|
---|
| 12 | using HeuristicLab.Parameters;
|
---|
| 13 | using HeuristicLab.Persistence.Default.CompositeSerializers.Storable;
|
---|
| 14 | using HeuristicLab.PluginInfrastructure;
|
---|
| 15 |
|
---|
| 16 | namespace HeuristicLab.Problems.GrammaticalOptimization {
|
---|
| 17 | [NonDiscoverableType]
|
---|
| 18 | [StorableClass]
|
---|
| 19 | [Item("GenericSymbExprProblem", "Represents grammatical optimization problems (using a symbolic expression tree encoding).")]
|
---|
[11857] | 20 | public class GenericSymbExprProblem : SingleObjectiveHeuristicOptimizationProblem<IGenericSymbExprEvaluator, ISymbolicExpressionTreeCreator> {
|
---|
[11846] | 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 | }
|
---|
[11857] | 53 | public new GenericSymbExprEvaluator Evaluator {
|
---|
| 54 | get { return (GenericSymbExprEvaluator)base.Evaluator; }
|
---|
[11846] | 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)
|
---|
[11857] | 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));
|
---|
[11846] | 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 | }
|
---|