Free cookie consent management tool by TermsFeed Policy Generator

source: branches/3.2/sources/HeuristicLab.GP/3.3/BaseClasses/FunctionLibraryInjectorBase.cs @ 13780

Last change on this file since 13780 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: 3.5 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 System.Xml;
26using System.Linq;
27using HeuristicLab.Core;
28using HeuristicLab.GP.Interfaces;
29
30namespace HeuristicLab.GP {
31  public abstract class FunctionLibraryInjectorBase : OperatorBase {
32    private const string FUNCTIONLIBRARY = "FunctionLibrary";
33
34    public override string Description {
35      get { return @"Description is missing."; }
36    }
37
38    private FunctionLibrary functionLibrary;
39    public FunctionLibrary FunctionLibrary {
40      get {
41        return functionLibrary;
42      }
43      set {
44        this.functionLibrary = value;
45        FireChanged();
46      }
47    }
48
49    public FunctionLibraryInjectorBase()
50      : base() {
51      AddVariableInfo(new VariableInfo(FUNCTIONLIBRARY, "Preconfigured default function library", typeof(FunctionLibrary), VariableKind.New));
52      // create the default function library
53      functionLibrary = CreateFunctionLibrary();
54    }
55
56    public override IOperation Apply(IScope scope) {
57      scope.AddVariable(new HeuristicLab.Core.Variable(scope.TranslateName(FUNCTIONLIBRARY), (FunctionLibrary)functionLibrary.Clone()));
58      return null;
59    }
60
61    protected abstract FunctionLibrary CreateFunctionLibrary();
62
63    protected static void SetAllowedSubOperators(IFunction f, IEnumerable<IFunction> gs) {
64      for (int i = 0; i < f.MaxSubTrees; i++) {
65        SetAllowedSubOperators(f, i, gs);
66      }
67    }
68
69    protected static void SetAllowedSubOperators(IFunction f, int i, IEnumerable<IFunction> gs) {
70      foreach (var g in gs) {
71        f.AddAllowedSubFunction(g, i);
72      }
73    }
74
75    public override IView CreateView() {
76      return new FunctionLibraryInjectorView(this);
77    }
78
79    #region persistence
80    public override object Clone(IDictionary<Guid, object> clonedObjects) {
81      FunctionLibraryInjectorBase clone = (FunctionLibraryInjectorBase)base.Clone(clonedObjects);
82      clone.functionLibrary = (FunctionLibrary)Auxiliary.Clone(functionLibrary, clonedObjects);
83      return clone;
84    }
85    public override XmlNode GetXmlNode(string name, XmlDocument document, IDictionary<Guid, IStorable> persistedObjects) {
86      XmlNode node = base.GetXmlNode(name, document, persistedObjects);
87      node.AppendChild(PersistenceManager.Persist("FunctionLibrary", FunctionLibrary, document, persistedObjects));
88      return node;
89    }
90    public override void Populate(XmlNode node, IDictionary<Guid, IStorable> restoredObjects) {
91      base.Populate(node, restoredObjects);
92      functionLibrary = (FunctionLibrary)PersistenceManager.Restore(node.SelectSingleNode("FunctionLibrary"), restoredObjects);
93    }
94    #endregion
95  }
96}
Note: See TracBrowser for help on using the repository browser.