1 | #region License Information
|
---|
2 | /* HeuristicLab
|
---|
3 | * Copyright (C) 2002-2012 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 HeuristicLab.Common;
|
---|
23 | using HeuristicLab.Core;
|
---|
24 | using HeuristicLab.Parameters;
|
---|
25 | using HeuristicLab.Persistence.Default.CompositeSerializers.Storable;
|
---|
26 |
|
---|
27 | using CloneMapType = HeuristicLab.Core.ItemDictionary<HeuristicLab.Core.IItem, HeuristicLab.Core.IItem>;
|
---|
28 | using TraceMapType = HeuristicLab.Core.ItemDictionary<HeuristicLab.Core.IItem, HeuristicLab.Core.IItemList<HeuristicLab.Core.IItem>>;
|
---|
29 |
|
---|
30 | namespace HeuristicLab.Encodings.SymbolicExpressionTreeEncoding {
|
---|
31 | /// <summary>
|
---|
32 | /// A base class for operators for symbolic expression trees.
|
---|
33 | /// </summary>
|
---|
34 | [Item("SymbolicExpressionTreeOperator", "A base class for operators for symbolic expression trees.")]
|
---|
35 | [StorableClass]
|
---|
36 | public abstract class TracingSymbolicExpressionTreeOperator : SymbolicExpressionTreeOperator, ITracingSymbolicExpressionTreeOperator {
|
---|
37 | private const string GlobalTraceMapParameterName = "GlobalTraceMap";
|
---|
38 | private const string GlobalCloneMapParameterName = "GlobalCloneMap";
|
---|
39 | private const string GlobalFragmentMapParameterName = "GlobalFragmentMap";
|
---|
40 |
|
---|
41 | private const string SymbolicExpressionTreeNodeComparerParameterName = "SymbolicExpressionTreeNodeComparer";
|
---|
42 | private const string SymbolicExpressionTreeNodeComparerParameterDescription = "The comparison operator used to check if two symbolic expression tree nodes are equal or similar.";
|
---|
43 |
|
---|
44 | #region Parameter properties
|
---|
45 | public LookupParameter<CloneMapType> GlobalCloneMapParameter {
|
---|
46 | get { return (LookupParameter<CloneMapType>)Parameters[GlobalCloneMapParameterName]; }
|
---|
47 | }
|
---|
48 | public LookupParameter<TraceMapType> GlobalTraceMapParameter {
|
---|
49 | get { return (LookupParameter<TraceMapType>)Parameters[GlobalTraceMapParameterName]; }
|
---|
50 | }
|
---|
51 | public LookupParameter<CloneMapType> GlobalFragmentMapParameter {
|
---|
52 | get { return (LookupParameter<CloneMapType>)Parameters[GlobalFragmentMapParameterName]; }
|
---|
53 | }
|
---|
54 | public ValueParameter<ISymbolicExpressionTreeNodeComparer> SymbolicExpressionTreeNodeComparerParameter {
|
---|
55 | get { return (ValueParameter<ISymbolicExpressionTreeNodeComparer>)Parameters[SymbolicExpressionTreeNodeComparerParameterName]; }
|
---|
56 | }
|
---|
57 | #endregion
|
---|
58 |
|
---|
59 | #region Properties
|
---|
60 | public CloneMapType GlobalCloneMap {
|
---|
61 | get { return GlobalCloneMapParameter.ActualValue; }
|
---|
62 | }
|
---|
63 | public TraceMapType GlobalTraceMap {
|
---|
64 | get { return GlobalTraceMapParameter.ActualValue; }
|
---|
65 | }
|
---|
66 | public CloneMapType GlobalFragmentMap {
|
---|
67 | get { return GlobalFragmentMapParameter.ActualValue; }
|
---|
68 | }
|
---|
69 | public ISymbolicExpressionTreeNodeComparer SymbolicExpressionTreeNodeComparer {
|
---|
70 | get { return (ISymbolicExpressionTreeNodeComparer)SymbolicExpressionTreeNodeComparerParameter.ActualValue; }
|
---|
71 | }
|
---|
72 | #endregion
|
---|
73 |
|
---|
74 | [StorableConstructor]
|
---|
75 | protected TracingSymbolicExpressionTreeOperator(bool deserializing) : base(deserializing) { }
|
---|
76 | protected TracingSymbolicExpressionTreeOperator(TracingSymbolicExpressionTreeOperator original, Cloner cloner) : base(original, cloner) { }
|
---|
77 | protected TracingSymbolicExpressionTreeOperator()
|
---|
78 | : base() {
|
---|
79 | Parameters.Add(new LookupParameter<CloneMapType>(GlobalCloneMapParameterName, "A global map keeping track of trees and their clones (made during selection)."));
|
---|
80 | Parameters.Add(new LookupParameter<CloneMapType>(GlobalFragmentMapParameterName, "A global map keeping track of tree fragments received via crossover."));
|
---|
81 | Parameters.Add(new LookupParameter<TraceMapType>(GlobalTraceMapParameterName, "A global cache containing tracing info."));
|
---|
82 | Parameters.Add(new ValueParameter<ISymbolicExpressionTreeNodeComparer>(SymbolicExpressionTreeNodeComparerParameterName, SymbolicExpressionTreeNodeComparerParameterDescription));
|
---|
83 | }
|
---|
84 |
|
---|
85 | protected void AddTracingVariablesToGlobalScope() {
|
---|
86 | // add global trace cache if not already present in global scope
|
---|
87 | var gScope = ExecutionContext.Scope;
|
---|
88 | while (gScope.Parent != null) gScope = gScope.Parent;
|
---|
89 | if (GlobalTraceMap == null) gScope.Variables.Add(new Variable(GlobalTraceMapParameterName, new TraceMapType()));
|
---|
90 | if (GlobalFragmentMap == null) gScope.Variables.Add(new Variable(GlobalFragmentMapParameterName, new CloneMapType()));
|
---|
91 | }
|
---|
92 | }
|
---|
93 | }
|
---|