Free cookie consent management tool by TermsFeed Policy Generator

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

Last change on this file since 10586 was 10586, checked in by tsteinre, 11 years ago
  • divided/refactored PreprocessingData into TransactionalPreprocessingData and preprocessingData
File size: 3.3 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 PreprocessingContext(IDataAnalysisProblemData dataAnalysisProblemData, IAlgorithm algorithm, IDataAnalysisProblem problem) {
34      Data = new TransactionalPreprocessingData(dataAnalysisProblemData);
35      DataAnalysisProblemData = dataAnalysisProblemData;
36      Algorithm = algorithm;
37      Problem = problem;
38    }
39
40    private PreprocessingContext(PreprocessingContext original, Cloner cloner)
41      : base(original, cloner) {
42      Data = cloner.Clone(original.Data);
43      DataAnalysisProblemData = original.DataAnalysisProblemData;
44      Algorithm = original.Algorithm;
45      Problem = original.Problem;
46    }
47
48    public ITransactionalPreprocessingData Data { get; private set; }
49
50    public IDataAnalysisProblemData DataAnalysisProblemData { get; private set; }
51
52    public IAlgorithm Algorithm { get; private set; }
53
54    public IDataAnalysisProblem Problem { get; private set; }
55
56    public override IDeepCloneable Clone(Cloner cloner) {
57      return new PreprocessingContext(this, cloner);
58    }
59
60    public IItem ExportAlgorithmOrProblem() {
61      if (Algorithm != null) {
62        return ExportAlgorithm();
63      } else {
64        return ExportProblem();
65      }
66    }
67
68    public IProblem ExportProblem() {
69      return Export(Problem, SetupProblem);
70    }
71
72    private IDataAnalysisProblem SetupProblem(IProblem problem) {
73      return (IDataAnalysisProblem)problem;
74    }
75
76    public IAlgorithm ExportAlgorithm() {
77      return Export(Algorithm, SetupAlgorithm);
78    }
79
80    private IDataAnalysisProblem SetupAlgorithm(IAlgorithm algorithm) {
81      algorithm.Name = algorithm.Name + "(Preprocessed)";
82      algorithm.Runs.Clear();
83
84      return (IDataAnalysisProblem)algorithm.Problem;
85    }
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
98      return clone;
99    }
100  }
101}
Note: See TracBrowser for help on using the repository browser.