Free cookie consent management tool by TermsFeed Policy Generator

source: trunk/sources/HeuristicLab.GP.StructureIdentification.Networks/3.2/FunctionLibraryInjector.cs @ 3038

Last change on this file since 3038 was 2843, checked in by gkronber, 15 years ago

Removed max. and min. time offset constraints as algorithm parameters and from all engines. The time constraints were added to the relevant terminal symbols (variable & differential) instead. The time offset constraint can be changed by editing the symbols in the function library. #880 (Max and min time offsets for variable symbols are not set correctly by FunctionLibraryInjectors)

File size: 4.6 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.Collections.Generic;
23using HeuristicLab.Core;
24using HeuristicLab.Data;
25using HeuristicLab.GP.Interfaces;
26using HeuristicLab.GP;
27
28namespace HeuristicLab.GP.StructureIdentification.Networks {
29  public class FunctionLibraryInjector : FunctionLibraryInjectorBase {
30
31    public override string Description {
32      get { return @"Injects a function library for network structure identification."; }
33    }
34
35    protected override FunctionLibrary CreateFunctionLibrary() {
36      return Create();
37    }
38
39    public static FunctionLibrary Create() {
40      FunctionLibrary functionLibrary = new FunctionLibrary();
41
42      #region f0 (...) -> double
43      Variable variable = new Variable();
44      Constant constant = new Constant();
45      Differential differential = new Differential();
46      Addition addition = new Addition();
47      Division division = new Division();
48      Multiplication multiplication = new Multiplication();
49      Subtraction subtraction = new Subtraction();
50
51      List<IFunction> f0Functions =
52        new List<IFunction>() {
53          differential, variable, constant, addition, subtraction,
54          division, multiplication};
55
56
57      #endregion
58
59      #region f1: (...) -> (double -> double)
60      OpenParameter openPar = new OpenParameter();
61      OpenExp openExp = new OpenExp();
62      OpenLog openLog = new OpenLog();
63      //OpenSqrt openSqrt = new OpenSqrt();
64      //OpenSqr openSqr = new OpenSqr();
65      Flip flip = new Flip();
66      AdditionF1 addF1 = new AdditionF1();
67      SubtractionF1 subF1 = new SubtractionF1();
68      MultiplicationF1 mulF1 = new MultiplicationF1();
69      DivisionF1 divF1 = new DivisionF1();
70
71      List<IFunction> f1Functions = new List<IFunction>() {
72        openPar,
73        openExp, openLog, flip, // openSqrt, openSqr,
74        addF1, subF1, mulF1, divF1
75      };
76      #endregion
77
78      #region f2: (...) -> (double, double -> double)
79      Cycle cycle = new Cycle();
80      OpenAddition openAdd = new OpenAddition();
81      OpenSubtraction openSub = new OpenSubtraction();
82      OpenMultiplication openMul = new OpenMultiplication();
83      OpenDivision openDivision = new OpenDivision();
84      List<IFunction> f2Functions = new List<IFunction>() { openAdd, openSub, openMul, openDivision, cycle };
85      #endregion
86
87
88      SetAllowedSubOperators(addition, f0Functions);
89      SetAllowedSubOperators(division, f0Functions);
90      SetAllowedSubOperators(multiplication, f0Functions);
91      SetAllowedSubOperators(subtraction, f0Functions);
92
93      SetAllowedSubOperators(openExp, f1Functions);
94      SetAllowedSubOperators(openLog, f1Functions);
95      //SetAllowedSubOperators(openSqrt, f1Functions);
96      //SetAllowedSubOperators(openSqr, f1Functions);
97      SetAllowedSubOperators(flip, f1Functions);
98      SetAllowedSubOperators(addF1, 0, f1Functions);
99      SetAllowedSubOperators(addF1, 1, f0Functions);
100      SetAllowedSubOperators(subF1, 0, f1Functions);
101      SetAllowedSubOperators(subF1, 1, f0Functions);
102      SetAllowedSubOperators(mulF1, 0, f1Functions);
103      SetAllowedSubOperators(mulF1, 1, f0Functions);
104      SetAllowedSubOperators(divF1, 0, f1Functions);
105      SetAllowedSubOperators(divF1, 1, f0Functions);
106
107      SetAllowedSubOperators(cycle, f2Functions);
108      SetAllowedSubOperators(openAdd, f1Functions);
109      SetAllowedSubOperators(openDivision, f1Functions);
110      SetAllowedSubOperators(openMul, f1Functions);
111      SetAllowedSubOperators(openSub, f1Functions);
112
113      f0Functions.ForEach(x => functionLibrary.AddFunction(x));
114      f1Functions.ForEach(x => functionLibrary.AddFunction(x));
115      f2Functions.ForEach(x => functionLibrary.AddFunction(x));
116
117      openPar.SetConstraints(0, 0);
118
119
120      return functionLibrary;
121    }
122  }
123}
Note: See TracBrowser for help on using the repository browser.