Free cookie consent management tool by TermsFeed Policy Generator

source: branches/2708_ScopedAlgorithms/HeuristicLab.DataPreprocessing/3.4/Implementations/PreprocessingContext.cs @ 17958

Last change on this file since 17958 was 12012, checked in by ascheibe, 10 years ago

#2212 merged r12008, r12009, r12010 back into trunk

File size: 3.5 KB
Line 
1#region License Information
2/* HeuristicLab
3 * Copyright (C) 2002-2015 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 HeuristicLab.Common;
23using HeuristicLab.Core;
24using HeuristicLab.DataPreprocessing.Implementations;
25using HeuristicLab.DataPreprocessing.Interfaces;
26using HeuristicLab.Optimization;
27using HeuristicLab.Problems.DataAnalysis;
28
29namespace HeuristicLab.DataPreprocessing {
30  [Item("PreprocessingContext", "PreprocessingContext")]
31  public class PreprocessingContext
32    : Item, IPreprocessingContext {
33
34
35    public IFilteredPreprocessingData Data { get; private set; }
36
37    public IAlgorithm Algorithm { get; private set; }
38    public IDataAnalysisProblem Problem { get; private set; }
39    public IDataAnalysisProblemData ProblemData { get; private set; }
40
41    private readonly ProblemDataCreator creator;
42
43    public PreprocessingContext(IDataAnalysisProblemData dataAnalysisProblemData, IAlgorithm algorithm, IDataAnalysisProblem problem) {
44      var transactionalPreprocessingData = new TransactionalPreprocessingData(dataAnalysisProblemData);
45      Data = new FilteredPreprocessingData(transactionalPreprocessingData);
46
47      ProblemData = dataAnalysisProblemData;
48      Algorithm = algorithm;
49      Problem = problem;
50
51      creator = new ProblemDataCreator(this);
52    }
53
54    protected PreprocessingContext(PreprocessingContext original, Cloner cloner)
55      : base(original, cloner) {
56      Data = cloner.Clone(original.Data);
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 Export() {
66      if (Algorithm != null)
67        return ExportAlgorithm();
68      else if (Problem != null)
69        return ExportProblem();
70      return ExportProblemData();
71    }
72    public IAlgorithm ExportAlgorithm() {
73      var preprocessedAlgorithm = (IAlgorithm)Algorithm.Clone(new Cloner());
74      preprocessedAlgorithm.Name = preprocessedAlgorithm.Name + "(Preprocessed)";
75      Algorithm.Runs.Clear();
76      var problem = (IDataAnalysisProblem)preprocessedAlgorithm.Problem;
77      SetNewProblemData(problem);
78      return preprocessedAlgorithm;
79    }
80    public IDataAnalysisProblem ExportProblem() {
81      var preprocessedProblem = (IDataAnalysisProblem)Problem.Clone(new Cloner());
82      SetNewProblemData(preprocessedProblem);
83      return preprocessedProblem;
84    }
85
86    public IDataAnalysisProblemData ExportProblemData() {
87      return creator.CreateProblemData();
88    }
89
90    private void SetNewProblemData(IDataAnalysisProblem problem) {
91      var data = creator.CreateProblemData();
92      problem.ProblemDataParameter.ActualValue = data;
93      problem.Name = "Preprocessed " + problem.Name;
94    }
95  }
96}
Note: See TracBrowser for help on using the repository browser.