Free cookie consent management tool by TermsFeed Policy Generator

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, 8 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
RevLine 
[12807]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;
[13039]28
[12807]29namespace HeuristicLab.Problems.DataAnalysis.Symbolic {
30  [StorableClass]
[13039]31  [Item("FunctionSymbol", "Symbol that wraps a user-defined function.")]
[12807]32  public sealed class FunctionSymbol : Symbol {
[13039]33    private readonly int minimumArity;
34    private readonly int maximumArity;
[12807]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
[13039]60    public FunctionSymbol(string name, Func<double, double> f) : base(name, "Symbol that wraps a user-defined unary function.") {
[12807]61      MethodInfo = f.GetMethodInfo();
62      minimumArity = maximumArity = 1;
63    }
64
[13039]65    public FunctionSymbol(string name, Func<double, double, double> f) : base(name, "Symbol that wraps a user-defined binary function.") {
[12807]66      MethodInfo = f.GetMethodInfo();
67      minimumArity = maximumArity = 2;
68    }
69
[13039]70    public FunctionSymbol(string name, Func<double, double, double, double> f) : base(name, "Symbol that wraps a user-defined tertiary function.") {
[12807]71      MethodInfo = f.GetMethodInfo();
72      minimumArity = maximumArity = 3;
73    }
74
[13039]75    public FunctionSymbol(string name, Func<double, double, double, double, double> f) : base(name, "Symbol that wraps a user-defined quaternary function.") {
[12807]76      MethodInfo = f.GetMethodInfo();
77      minimumArity = maximumArity = 4;
78    }
79  }
80}
Note: See TracBrowser for help on using the repository browser.