Free cookie consent management tool by TermsFeed Policy Generator

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

Last change on this file since 10622 was 10617, checked in by pfleck, 11 years ago
  • moved ViewShortcuts creations to PreprocessingView.
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 ITransactionalPreprocessingData Data { get; private set; }
34
35    public IDataAnalysisProblemData DataAnalysisProblemData { get; private set; }
36
37    public IAlgorithm Algorithm { get; private set; }
38
39    public IDataAnalysisProblem Problem { get; private set; }
40
41    public PreprocessingContext(IDataAnalysisProblemData dataAnalysisProblemData, IAlgorithm algorithm, IDataAnalysisProblem problem) {
42      Data = new TransactionalPreprocessingData(dataAnalysisProblemData);
43      DataAnalysisProblemData = dataAnalysisProblemData;
44      Algorithm = algorithm;
45      Problem = problem;
46    }
47
48    private PreprocessingContext(PreprocessingContext original, Cloner cloner)
49      : base(original, cloner) {
50      Data = cloner.Clone(original.Data);
51      DataAnalysisProblemData = original.DataAnalysisProblemData;
52      Algorithm = original.Algorithm;
53      Problem = original.Problem;
54    }
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    public IProblem ExportProblem() {
68      return Export(Problem, SetupProblem);
69    }
70    public IAlgorithm ExportAlgorithm() {
71      return Export(Algorithm, SetupAlgorithm);
72    }
73
74    private IDataAnalysisProblem SetupProblem(IProblem problem) {
75      return (IDataAnalysisProblem)problem;
76    }
77    private IDataAnalysisProblem SetupAlgorithm(IAlgorithm algorithm) {
78      algorithm.Name = algorithm.Name + "(Preprocessed)";
79      algorithm.Runs.Clear();
80      return (IDataAnalysisProblem)algorithm.Problem;
81    }
82    private T Export<T>(T original, Func<T, IDataAnalysisProblem> setup)
83        where T : IItem {
84      var creator = new ProblemDataCreator(this);
85      var data = creator.CreateProblemData();
86
87      var clone = (T)original.Clone(new Cloner());
88
89      var problem = setup(clone);
90      problem.ProblemDataParameter.ActualValue = data;
91      problem.Name = "Preprocessed " + problem.Name;
92
93      return clone;
94    }
95  }
96}
Note: See TracBrowser for help on using the repository browser.