Free cookie consent management tool by TermsFeed Policy Generator

source: branches/DataPreprocessing/HeuristicLab.DataPreprocessing/3.3/Implementations/PreprocessingContext.cs @ 10785

Last change on this file since 10785 was 10783, checked in by mleitner, 11 years ago

Add FilteredPreprocessing data for applying and caching filter status

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;
23using HeuristicLab.Common;
24using HeuristicLab.Core;
25using HeuristicLab.Encodings.SymbolicExpressionTreeEncoding;
26using HeuristicLab.Optimization;
27using HeuristicLab.Problems.DataAnalysis;
28using HeuristicLab.Problems.DataAnalysis.Symbolic;
29using Variable = HeuristicLab.Problems.DataAnalysis.Symbolic.Variable;
30using HeuristicLab.DataPreprocessing.Implementations;
31using HeuristicLab.DataPreprocessing.Interfaces;
32
33namespace HeuristicLab.DataPreprocessing {
34  [Item("PreprocessingContext", "PreprocessingContext")]
35  public class PreprocessingContext
36    : Item, IPreprocessingContext {
37
38    public IFilteredPreprocessingData Data { get; private set; }
39
40    public IDataAnalysisProblemData DataAnalysisProblemData { get; private set; }
41
42    public IAlgorithm Algorithm { get; private set; }
43
44    public IDataAnalysisProblem Problem { get; private set; }
45
46    public PreprocessingContext(IDataAnalysisProblemData dataAnalysisProblemData, IAlgorithm algorithm, IDataAnalysisProblem problem) {
47
48      TransactionalPreprocessingData transactionalPreprocessingData = new TransactionalPreprocessingData(dataAnalysisProblemData);
49
50      Data = new FilteredPreprocessingData(transactionalPreprocessingData);
51      DataAnalysisProblemData = dataAnalysisProblemData;
52      Algorithm = algorithm;
53      Problem = problem;
54    }
55
56    private PreprocessingContext(PreprocessingContext original, Cloner cloner)
57      : base(original, cloner) {
58      Data = cloner.Clone(original.Data);
59      DataAnalysisProblemData = original.DataAnalysisProblemData;
60      Algorithm = original.Algorithm;
61      Problem = original.Problem;
62    }
63
64    public override IDeepCloneable Clone(Cloner cloner) {
65      return new PreprocessingContext(this, cloner);
66    }
67
68    public IItem ExportAlgorithmOrProblem() {
69      if (Algorithm != null) {
70        return ExportAlgorithm();
71      }
72      return ExportProblem();
73    }
74
75    public IProblem ExportProblem() {
76      return Export(Problem, SetupProblem);
77    }
78    public IAlgorithm ExportAlgorithm() {
79      return Export(Algorithm, SetupAlgorithm);
80    }
81
82    private IDataAnalysisProblem SetupProblem(IProblem problem) {
83      return (IDataAnalysisProblem)problem;
84    }
85    private IDataAnalysisProblem SetupAlgorithm(IAlgorithm algorithm) {
86      algorithm.Name = algorithm.Name + "(Preprocessed)";
87      algorithm.Runs.Clear();
88      return (IDataAnalysisProblem)algorithm.Problem;
89    }
90    private T Export<T>(T original, Func<T, IDataAnalysisProblem> setup)
91        where T : IItem {
92      var creator = new ProblemDataCreator(this);
93      var data = creator.CreateProblemData();
94
95      var clone = (T)original.Clone(new Cloner());
96
97      var problem = setup(clone);
98      problem.ProblemDataParameter.ActualValue = data;
99      problem.Name = "Preprocessed " + problem.Name;
100      return clone;
101    }
102  }
103}
Note: See TracBrowser for help on using the repository browser.