Free cookie consent management tool by TermsFeed Policy Generator

source: branches/Sliding Window GP/HeuristicLab.Problems.DataAnalysis.Symbolic/3.4/SlidingWindow/SlidingWindowBestSolutionsCollection.cs @ 10413

Last change on this file since 10413 was 10413, checked in by bburlacu, 10 years ago

#1837: Modified the SlidingWindowBestSolutionsCollection to use a dictionary for sliding window positions mapped to best solutions, because the last sliding window position before the algorithm reached its stop was not registered correctly.

File size: 3.7 KB
Line 
1#region License Information
2/* HeuristicLab
3 * Copyright (C) 2002-2013 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.Common;
24using HeuristicLab.Core;
25using HeuristicLab.Encodings.SymbolicExpressionTreeEncoding;
26using HeuristicLab.Persistence.Default.CompositeSerializers.Storable;
27
28using SlidingWindowRange = System.Tuple<int, int>;
29
30namespace HeuristicLab.Problems.DataAnalysis.Symbolic {
31  [StorableClass]
32  [Item("SlidingWindowBestSolutionsCollection", "An object holding a collection of the best sliding window solutions.")]
33  public abstract class SlidingWindowBestSolutionsCollection : Item {
34    [Storable]
35    private Dictionary<SlidingWindowRange, ISymbolicExpressionTree> bestSolutions;
36    public Dictionary<SlidingWindowRange, ISymbolicExpressionTree> BestSolutions {
37      get { return bestSolutions; }
38      set { bestSolutions = value; }
39    }
40
41    [Storable]
42    private IDataAnalysisProblemData problemData;
43    public IDataAnalysisProblemData ProblemData {
44      get { return problemData; }
45      set { problemData = value; }
46    }
47
48    [Storable]
49    private ISymbolicDataAnalysisExpressionTreeInterpreter interpreter;
50    public ISymbolicDataAnalysisExpressionTreeInterpreter Interpreter {
51      get { return interpreter; }
52      set { interpreter = value; }
53    }
54    [StorableHook(HookType.AfterDeserialization)]
55    private void AfterDeserialization() {
56    }
57
58    [StorableConstructor]
59    protected SlidingWindowBestSolutionsCollection(bool deserializing) : base(deserializing) { }
60    protected SlidingWindowBestSolutionsCollection(SlidingWindowBestSolutionsCollection original, Cloner cloner)
61      : base(original, cloner) {
62      this.bestSolutions = original.bestSolutions;
63      this.problemData = original.problemData;
64      this.interpreter = original.interpreter;
65    }
66    protected SlidingWindowBestSolutionsCollection() {
67      bestSolutions = new Dictionary<SlidingWindowRange, ISymbolicExpressionTree>();
68    }
69
70    public bool ContainsKey(SlidingWindowRange key) {
71      return bestSolutions.ContainsKey(key);
72    }
73
74    public ISymbolicExpressionTree this[SlidingWindowRange key] {
75      get {
76        return bestSolutions[key];
77      }
78      set {
79        if (bestSolutions.ContainsKey(key))
80          bestSolutions[key] = value;
81        else
82          bestSolutions.Add(key, value);
83      }
84    }
85
86    public void Add(SlidingWindowRange range, ISymbolicExpressionTree solution) {
87      bestSolutions.Add(range, solution);
88    }
89
90    public void Clear() {
91      if (bestSolutions != null) bestSolutions.Clear();
92    }
93
94    public abstract ISymbolicDataAnalysisModel CreateModel(ISymbolicExpressionTree tree, ISymbolicDataAnalysisExpressionTreeInterpreter interpreter,
95     double lowerEstimationLimit = double.MinValue, double upperEstimationLimit = double.MaxValue);
96
97    public abstract ISymbolicDataAnalysisSolution CreateSolution(ISymbolicDataAnalysisModel model, IDataAnalysisProblemData problemData);
98  }
99}
Note: See TracBrowser for help on using the repository browser.