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 |
|
---|
22 | using System;
|
---|
23 | using System.Collections.Generic;
|
---|
24 | using System.Text;
|
---|
25 | using HeuristicLab.Data;
|
---|
26 | using HeuristicLab.Core;
|
---|
27 | using System.Xml;
|
---|
28 | using HeuristicLab.DataAnalysis;
|
---|
29 |
|
---|
30 | namespace 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 | public virtual void Accept(IFunctionVisitor visitor) {
|
---|
52 | visitor.Visit(this);
|
---|
53 | }
|
---|
54 |
|
---|
55 | // operator-tree style evaluation is not supported for functions.
|
---|
56 | public override IOperation Apply(IScope scope) {
|
---|
57 | throw new NotSupportedException();
|
---|
58 | }
|
---|
59 |
|
---|
60 | private static readonly List<IOperator> emptySubOperatorList = new List<IOperator>();
|
---|
61 | public override IList<IOperator> SubOperators {
|
---|
62 | get { return emptySubOperatorList; }
|
---|
63 | }
|
---|
64 |
|
---|
65 | public override void AddSubOperator(IOperator subOperator) {
|
---|
66 | throw new NotSupportedException();
|
---|
67 | }
|
---|
68 |
|
---|
69 | public override bool TryAddSubOperator(IOperator subOperator) {
|
---|
70 | throw new NotSupportedException();
|
---|
71 | }
|
---|
72 |
|
---|
73 | public override bool TryAddSubOperator(IOperator subOperator, int index) {
|
---|
74 | throw new NotSupportedException();
|
---|
75 | }
|
---|
76 |
|
---|
77 | public override bool TryAddSubOperator(IOperator subOperator, int index, out ICollection<IConstraint> violatedConstraints) {
|
---|
78 | throw new NotSupportedException();
|
---|
79 | }
|
---|
80 |
|
---|
81 | public override bool TryAddSubOperator(IOperator subOperator, out ICollection<IConstraint> violatedConstraints) {
|
---|
82 | throw new NotSupportedException();
|
---|
83 | }
|
---|
84 |
|
---|
85 | public override void AddSubOperator(IOperator subOperator, int index) {
|
---|
86 | throw new NotSupportedException();
|
---|
87 | }
|
---|
88 |
|
---|
89 | public override void RemoveSubOperator(int index) {
|
---|
90 | throw new NotSupportedException();
|
---|
91 | }
|
---|
92 |
|
---|
93 | public override bool TryRemoveSubOperator(int index) {
|
---|
94 | throw new NotSupportedException();
|
---|
95 | }
|
---|
96 |
|
---|
97 | public override bool TryRemoveSubOperator(int index, out ICollection<IConstraint> violatedConstraints) {
|
---|
98 | throw new NotSupportedException();
|
---|
99 | }
|
---|
100 | }
|
---|
101 | }
|
---|