[10219] | 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 |
|
---|
[10383] | 22 | using System;
|
---|
[10219] | 23 | using HeuristicLab.Common;
|
---|
| 24 | using HeuristicLab.Core;
|
---|
[10240] | 25 | using HeuristicLab.Optimization;
|
---|
[10221] | 26 | using HeuristicLab.Problems.DataAnalysis;
|
---|
[10219] | 27 |
|
---|
| 28 | namespace HeuristicLab.DataPreprocessing {
|
---|
| 29 | [Item("PreprocessingContext", "PreprocessingContext")]
|
---|
[10383] | 30 | public class PreprocessingContext
|
---|
| 31 | : Item, IPreprocessingContext {
|
---|
| 32 |
|
---|
[10614] | 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 |
|
---|
[10383] | 43 | public PreprocessingContext(IDataAnalysisProblemData dataAnalysisProblemData, IAlgorithm algorithm, IDataAnalysisProblem problem) {
|
---|
[10586] | 44 | Data = new TransactionalPreprocessingData(dataAnalysisProblemData);
|
---|
[10221] | 45 | DataAnalysisProblemData = dataAnalysisProblemData;
|
---|
[10240] | 46 | Algorithm = algorithm;
|
---|
[10307] | 47 | Problem = problem;
|
---|
[10614] | 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 | };
|
---|
[10219] | 66 | }
|
---|
| 67 |
|
---|
| 68 | private PreprocessingContext(PreprocessingContext original, Cloner cloner)
|
---|
| 69 | : base(original, cloner) {
|
---|
| 70 | Data = cloner.Clone(original.Data);
|
---|
[10221] | 71 | DataAnalysisProblemData = original.DataAnalysisProblemData;
|
---|
[10240] | 72 | Algorithm = original.Algorithm;
|
---|
[10307] | 73 | Problem = original.Problem;
|
---|
[10219] | 74 | }
|
---|
| 75 |
|
---|
| 76 | public override IDeepCloneable Clone(Cloner cloner) {
|
---|
| 77 | return new PreprocessingContext(this, cloner);
|
---|
| 78 | }
|
---|
[10383] | 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 | }
|
---|
[10614] | 90 | public IAlgorithm ExportAlgorithm() {
|
---|
| 91 | return Export(Algorithm, SetupAlgorithm);
|
---|
| 92 | }
|
---|
[10383] | 93 |
|
---|
| 94 | private IDataAnalysisProblem SetupProblem(IProblem problem) {
|
---|
| 95 | return (IDataAnalysisProblem)problem;
|
---|
| 96 | }
|
---|
| 97 | private IDataAnalysisProblem SetupAlgorithm(IAlgorithm algorithm) {
|
---|
[10536] | 98 | algorithm.Name = algorithm.Name + "(Preprocessed)";
|
---|
[10383] | 99 | algorithm.Runs.Clear();
|
---|
| 100 | return (IDataAnalysisProblem)algorithm.Problem;
|
---|
| 101 | }
|
---|
[10536] | 102 | private T Export<T>(T original, Func<T, IDataAnalysisProblem> setup)
|
---|
| 103 | where T : IItem {
|
---|
[10383] | 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;
|
---|
[10536] | 111 | problem.Name = "Preprocessed " + problem.Name;
|
---|
[10383] | 112 |
|
---|
| 113 | return clone;
|
---|
| 114 | }
|
---|
[10219] | 115 | }
|
---|
| 116 | }
|
---|