Free cookie consent management tool by TermsFeed Policy Generator

source: branches/FunctionsAndStructIdRefactoring/HeuristicLab.Functions/FunctionBase.cs @ 147

Last change on this file since 147 was 147, checked in by gkronber, 17 years ago
  • changed signature of interface method Evaluate()
  • fixed evaluation of variables and constants
  • removed variable-cache fields and properties in variable and constant since they are not needed anymore. and removed the obsolete overrides of Populate() and Clone()

(ticket #112)

File size: 3.4 KB
Line 
1#region License Information
2/* HeuristicLab
3 * Copyright (C) 2002-2008 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.Collections.Generic;
24using System.Text;
25using HeuristicLab.Data;
26using HeuristicLab.Core;
27using System.Xml;
28using HeuristicLab.DataAnalysis;
29
30namespace HeuristicLab.Functions {
31  /// <summary>
32  /// Functions are like operators except that they do not allow sub-operators and the normal form of evaluation
33  /// is to evaluate all children first.
34  /// </summary>
35  public abstract class FunctionBase : OperatorBase, IFunction {
36   
37    public virtual double Evaluate(Dataset dataset, int sampleIndex, IFunctionTree tree) {
38      if(tree.SubTrees.Count > 0) {
39        double[] evaluationResults = new double[tree.SubTrees.Count];
40        for(int i = 0; i < evaluationResults.Length; i++) {
41          evaluationResults[i] = tree.SubTrees[i].Evaluate(dataset, sampleIndex);
42        }
43        return Apply(dataset, sampleIndex, evaluationResults);
44      } else {
45        return Apply(dataset, sampleIndex, null);
46      }
47    }
48
49    public abstract double Apply(Dataset dataset, int sampleIndex, double[] args);
50
51    // operator-tree style evaluation is not supported for functions.
52    public override IOperation Apply(IScope scope) {
53      throw new NotSupportedException();
54    }
55    public virtual void Accept(IFunctionVisitor visitor) {
56      visitor.Visit(this);
57    }
58
59    public override IList<IOperator> SubOperators {
60      get { return new List<IOperator>(); }
61    }
62
63    public override void AddSubOperator(IOperator subOperator) {
64      throw new NotSupportedException();
65    }
66
67    public override bool TryAddSubOperator(IOperator subOperator) {
68      throw new NotSupportedException();
69    }
70
71    public override bool TryAddSubOperator(IOperator subOperator, int index) {
72      throw new NotSupportedException();
73    }
74
75    public override bool TryAddSubOperator(IOperator subOperator, int index, out ICollection<IConstraint> violatedConstraints) {
76      throw new NotSupportedException();
77    }
78
79    public override bool TryAddSubOperator(IOperator subOperator, out ICollection<IConstraint> violatedConstraints) {
80      throw new NotSupportedException();
81    }
82
83    public override void AddSubOperator(IOperator subOperator, int index) {
84      throw new NotSupportedException();
85    }
86
87    public override void RemoveSubOperator(int index) {
88      throw new NotSupportedException();
89    }
90
91    public override bool TryRemoveSubOperator(int index) {
92      throw new NotSupportedException();
93    }
94
95    public override bool TryRemoveSubOperator(int index, out ICollection<IConstraint> violatedConstraints) {
96      throw new NotSupportedException();
97    }
98  }
99}
Note: See TracBrowser for help on using the repository browser.