source: branches/HeuristicLab.LinqExpressionTreeInterpreter/HeuristicLab.Problems.DataAnalysis.Symbolic/3.4/Symbols/FunctionSymbol.cs @ 13039

Last change on this file since 13039 was 13039, checked in by bburlacu, 5 years ago

#2442: Very minor changes in the naming of things. Removed readonly attributes for the min and max arity variables.

File size: 3.1 KB
Line 
1#region License Information
2/* HeuristicLab
3 * Copyright (C) 2002-2015 Heuristic and Evolutionary Algorithms Laboratory (HEAL)
4 *
5 * This file is part of HeuristicLab.
6 *
7 * HeuristicLab is free software: you can redistribute it and/or modify
8 * it under the terms of the GNU General Public License as published by
9 * the Free Software Foundation, either version 3 of the License, or
10 * (at your option) any later version.
11 *
12 * HeuristicLab is distributed in the hope that it will be useful,
13 * but WITHOUT ANY WARRANTY; without even the implied warranty of
14 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
15 * GNU General Public License for more details.
16 *
17 * You should have received a copy of the GNU General Public License
18 * along with HeuristicLab. If not, see <http://www.gnu.org/licenses/>.
19 */
20#endregion
21
22using System;
23using System.Reflection;
24using HeuristicLab.Common;
25using HeuristicLab.Core;
26using HeuristicLab.Encodings.SymbolicExpressionTreeEncoding;
27using HeuristicLab.Persistence.Default.CompositeSerializers.Storable;
28
29namespace HeuristicLab.Problems.DataAnalysis.Symbolic {
30  [StorableClass]
31  [Item("FunctionSymbol", "Symbol that wraps a user-defined function.")]
32  public sealed class FunctionSymbol : Symbol {
33    private readonly int minimumArity;
34    private readonly int maximumArity;
35
36    public override int MinimumArity {
37      get { return minimumArity; }
38    }
39    public override int MaximumArity {
40      get { return maximumArity; }
41    }
42
43    //[Storable]
44    private MethodInfo methodInfo;
45    public MethodInfo MethodInfo {
46      get { return methodInfo; }
47      private set { methodInfo = value; }
48    }
49
50    [StorableConstructor]
51    private FunctionSymbol(bool deserializing) : base(deserializing) { }
52
53    private FunctionSymbol(FunctionSymbol original, Cloner cloner) : base(original, cloner) {
54      this.MethodInfo = original.MethodInfo; // symbols are cached so we also cache the MethodInfo in order to optimize the performance of the interpreter
55    }
56    public override IDeepCloneable Clone(Cloner cloner) {
57      return new FunctionSymbol(this, cloner);
58    }
59
60    public FunctionSymbol(string name, Func<double, double> f) : base(name, "Symbol that wraps a user-defined unary function.") {
61      MethodInfo = f.GetMethodInfo();
62      minimumArity = maximumArity = 1;
63    }
64
65    public FunctionSymbol(string name, Func<double, double, double> f) : base(name, "Symbol that wraps a user-defined binary function.") {
66      MethodInfo = f.GetMethodInfo();
67      minimumArity = maximumArity = 2;
68    }
69
70    public FunctionSymbol(string name, Func<double, double, double, double> f) : base(name, "Symbol that wraps a user-defined tertiary function.") {
71      MethodInfo = f.GetMethodInfo();
72      minimumArity = maximumArity = 3;
73    }
74
75    public FunctionSymbol(string name, Func<double, double, double, double, double> f) : base(name, "Symbol that wraps a user-defined quaternary function.") {
76      MethodInfo = f.GetMethodInfo();
77      minimumArity = maximumArity = 4;
78    }
79  }
80}
Note: See TracBrowser for help on using the repository browser.