Free cookie consent management tool by TermsFeed Policy Generator

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

Last change on this file since 10615 was 10614, checked in by pfleck, 11 years ago
  • replaced main menu list with ItemCollectionList
  • added ViewShortcut interface for menu items
File size: 4.2 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;
27
28namespace HeuristicLab.DataPreprocessing {
29  [Item("PreprocessingContext", "PreprocessingContext")]
30  public class PreprocessingContext
31    : Item, IPreprocessingContext {
32
33    public ITransactionalPreprocessingData Data { get; private set; }
34
35    public ViewShortcutCollection ViewShortcuts { 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      Data = new TransactionalPreprocessingData(dataAnalysisProblemData);
45      DataAnalysisProblemData = dataAnalysisProblemData;
46      Algorithm = algorithm;
47      Problem = problem;
48
49      var searchLogic = new SearchLogic(Data);
50      var dataGridLogic = new DataGridLogic(Data);
51      var statisticsLogic = new StatisticsLogic(Data, searchLogic);
52      var manipulationLogic = new ManipulationLogic(Data, searchLogic, statisticsLogic);
53      var transformationLogic = new TransformationLogic(Data, searchLogic, statisticsLogic);
54      var lineChartLogic = new LineChartLogic(Data);
55      var histogramLogic = new HistogramLogic(Data);
56      var filterLogic = new FilterLogic();
57
58      ViewShortcuts = new ViewShortcutCollection {
59        new DataGridContent(dataGridLogic, manipulationLogic),
60        new StatisticsContent(statisticsLogic),
61        new FilterContent(filterLogic),
62        new TransformationContent(transformationLogic),
63        new LineChartContent(lineChartLogic),
64        new HistogramContent(histogramLogic)
65      };
66    }
67
68    private PreprocessingContext(PreprocessingContext original, Cloner cloner)
69      : base(original, cloner) {
70      Data = cloner.Clone(original.Data);
71      DataAnalysisProblemData = original.DataAnalysisProblemData;
72      Algorithm = original.Algorithm;
73      Problem = original.Problem;
74    }
75
76    public override IDeepCloneable Clone(Cloner cloner) {
77      return new PreprocessingContext(this, cloner);
78    }
79
80    public IItem ExportAlgorithmOrProblem() {
81      if (Algorithm != null) {
82        return ExportAlgorithm();
83      } else {
84        return ExportProblem();
85      }
86    }
87    public IProblem ExportProblem() {
88      return Export(Problem, SetupProblem);
89    }
90    public IAlgorithm ExportAlgorithm() {
91      return Export(Algorithm, SetupAlgorithm);
92    }
93
94    private IDataAnalysisProblem SetupProblem(IProblem problem) {
95      return (IDataAnalysisProblem)problem;
96    }
97    private IDataAnalysisProblem SetupAlgorithm(IAlgorithm algorithm) {
98      algorithm.Name = algorithm.Name + "(Preprocessed)";
99      algorithm.Runs.Clear();
100      return (IDataAnalysisProblem)algorithm.Problem;
101    }
102    private T Export<T>(T original, Func<T, IDataAnalysisProblem> setup)
103        where T : IItem {
104      var creator = new ProblemDataCreator(this);
105      var data = creator.CreateProblemData();
106
107      var clone = (T)original.Clone(new Cloner());
108
109      var problem = setup(clone);
110      problem.ProblemDataParameter.ActualValue = data;
111      problem.Name = "Preprocessed " + problem.Name;
112
113      return clone;
114    }
115  }
116}
Note: See TracBrowser for help on using the repository browser.