Free cookie consent management tool by TermsFeed Policy Generator

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

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