[18063] | 1 | using System;
|
---|
| 2 | using System.Collections.Generic;
|
---|
| 3 | using System.Linq;
|
---|
| 4 | using System.Text;
|
---|
| 5 | using System.Threading.Tasks;
|
---|
| 6 | using HeuristicLab.Core;
|
---|
| 7 | using HEAL.Attic;
|
---|
| 8 | using HeuristicLab.Common;
|
---|
| 9 | using HeuristicLab.Encodings.SymbolicExpressionTreeEncoding;
|
---|
| 10 | using HeuristicLab.Parameters;
|
---|
| 11 | using HeuristicLab.Data;
|
---|
| 12 |
|
---|
| 13 | namespace HeuristicLab.Problems.DataAnalysis.Symbolic {
|
---|
| 14 | [StorableType("598B5DCB-95AC-465A-920B-E1E6DACFFA4B")]
|
---|
| 15 | public class SubFunction : ParameterizedNamedItem {
|
---|
| 16 | #region Constants
|
---|
| 17 | private const string GrammarParameterName = "Grammar";
|
---|
| 18 | private const string MaximumSymbolicExpressionTreeDepthParameterName = "MaximumSymbolicExpressionTreeDepth";
|
---|
| 19 | private const string MaximumSymbolicExpressionTreeLengthParameterName = "MaximumSymbolicExpressionTreeLength";
|
---|
[18065] | 20 | private const string FunctionArgumentsParameterName = "Function Arguments";
|
---|
[18063] | 21 | #endregion
|
---|
| 22 |
|
---|
| 23 | #region Parameters
|
---|
| 24 | public IValueParameter<ISymbolicDataAnalysisGrammar> GrammarParameter => (IValueParameter<ISymbolicDataAnalysisGrammar>)Parameters[GrammarParameterName];
|
---|
| 25 | public IFixedValueParameter<IntValue> MaximumSymbolicExpressionTreeDepthParameter => (IFixedValueParameter<IntValue>)Parameters[MaximumSymbolicExpressionTreeDepthParameterName];
|
---|
| 26 | public IFixedValueParameter<IntValue> MaximumSymbolicExpressionTreeLengthParameter => (IFixedValueParameter<IntValue>)Parameters[MaximumSymbolicExpressionTreeLengthParameterName];
|
---|
[18065] | 27 | public IValueParameter<ReadOnlyItemList<StringValue>> FunctionArgumentsParameter => (IValueParameter<ReadOnlyItemList<StringValue>>)Parameters[FunctionArgumentsParameterName];
|
---|
[18063] | 28 | #endregion
|
---|
| 29 |
|
---|
| 30 | #region Properties
|
---|
| 31 | public ISymbolicDataAnalysisGrammar Grammar {
|
---|
| 32 | get => GrammarParameter.Value;
|
---|
| 33 | set => GrammarParameter.Value = value;
|
---|
| 34 | }
|
---|
| 35 |
|
---|
| 36 | public int MaximumSymbolicExpressionTreeDepth {
|
---|
| 37 | get => MaximumSymbolicExpressionTreeDepthParameter.Value.Value;
|
---|
| 38 | set => MaximumSymbolicExpressionTreeDepthParameter.Value.Value = value;
|
---|
| 39 | }
|
---|
| 40 |
|
---|
| 41 | public int MaximumSymbolicExpressionTreeLength {
|
---|
| 42 | get => MaximumSymbolicExpressionTreeLengthParameter.Value.Value;
|
---|
| 43 | set => MaximumSymbolicExpressionTreeLengthParameter.Value.Value = value;
|
---|
| 44 | }
|
---|
[18065] | 45 |
|
---|
| 46 | public IEnumerable<string> FunctionArguments {
|
---|
| 47 | get => FunctionArgumentsParameter.Value.Select(x => x.Value);
|
---|
| 48 | set {
|
---|
| 49 | var varSym = (Variable)Grammar.GetSymbol("Variable");
|
---|
| 50 | if (varSym == null)
|
---|
| 51 | throw new ArgumentException($"No variable symbol existent.");
|
---|
| 52 |
|
---|
| 53 | FunctionArgumentsParameter.Value = new ItemList<StringValue>(value.Select(x => new StringValue(x))).AsReadOnly();
|
---|
| 54 |
|
---|
| 55 | varSym.AllVariableNames = FunctionArguments;
|
---|
| 56 | varSym.VariableNames = FunctionArguments;
|
---|
| 57 | varSym.Enabled = true;
|
---|
| 58 | }
|
---|
| 59 | }
|
---|
[18063] | 60 | #endregion
|
---|
| 61 |
|
---|
| 62 | #region Constructors
|
---|
| 63 | public SubFunction() {
|
---|
| 64 | Parameters.Add(new ValueParameter<ISymbolicDataAnalysisGrammar>(GrammarParameterName, new LinearScalingGrammar()));
|
---|
| 65 | Parameters.Add(new FixedValueParameter<IntValue>(MaximumSymbolicExpressionTreeDepthParameterName, new IntValue(10)));
|
---|
| 66 | Parameters.Add(new FixedValueParameter<IntValue>(MaximumSymbolicExpressionTreeLengthParameterName, new IntValue(30)));
|
---|
[18065] | 67 | Parameters.Add(new ValueParameter<ReadOnlyItemList<StringValue>>(FunctionArgumentsParameterName, new ReadOnlyItemList<StringValue>()));
|
---|
[18063] | 68 | }
|
---|
| 69 |
|
---|
| 70 | protected SubFunction(SubFunction original, Cloner cloner) { }
|
---|
| 71 |
|
---|
| 72 | [StorableConstructor]
|
---|
| 73 | protected SubFunction(StorableConstructorFlag _) : base(_) {}
|
---|
| 74 | #endregion
|
---|
| 75 |
|
---|
| 76 | #region Cloning
|
---|
| 77 | public override IDeepCloneable Clone(Cloner cloner) =>
|
---|
| 78 | new SubFunction(this, cloner);
|
---|
| 79 | #endregion
|
---|
| 80 | }
|
---|
| 81 | }
|
---|