Free cookie consent management tool by TermsFeed Policy Generator

source: branches/DataPreprocessing/HeuristicLab.DataPreprocessing/3.4/Implementations/PreprocessingContext.cs @ 11002

Last change on this file since 11002 was 10990, checked in by pfleck, 10 years ago
  • Simplified export in PreprocessingContext
  • Implemented export of DataAnalysisProblemData
File size: 3.5 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;
27using HeuristicLab.DataPreprocessing.Implementations;
28using HeuristicLab.DataPreprocessing.Interfaces;
29
30namespace HeuristicLab.DataPreprocessing {
31  [Item("PreprocessingContext", "PreprocessingContext")]
32  public class PreprocessingContext
33    : Item, IPreprocessingContext {
34
35
36    public IFilteredPreprocessingData Data { get; private set; }
37
38    public IAlgorithm Algorithm { get; private set; }
39    public IDataAnalysisProblem Problem { get; private set; }
40    public IDataAnalysisProblemData ProblemData { get; private set; }
41
42    private readonly ProblemDataCreator creator;
43
44    public PreprocessingContext(IDataAnalysisProblemData dataAnalysisProblemData, IAlgorithm algorithm, IDataAnalysisProblem problem) {
45      var transactionalPreprocessingData = new TransactionalPreprocessingData(dataAnalysisProblemData);
46      Data = new FilteredPreprocessingData(transactionalPreprocessingData);
47
48      ProblemData = dataAnalysisProblemData;
49      Algorithm = algorithm;
50      Problem = problem;
51
52      creator = new ProblemDataCreator(this);
53    }
54
55    private PreprocessingContext(PreprocessingContext original, Cloner cloner)
56      : base(original, cloner) {
57      Data = cloner.Clone(original.Data);
58      Algorithm = original.Algorithm;
59      Problem = original.Problem;
60    }
61
62    public override IDeepCloneable Clone(Cloner cloner) {
63      return new PreprocessingContext(this, cloner);
64    }
65
66    public IItem Export() {
67      if (Algorithm != null)
68        return ExportAlgorithm();
69      else if (Problem != null)
70        return ExportProblem();
71      return ExportProblemData();
72    }
73    public IAlgorithm ExportAlgorithm() {
74      var preprocessedAlgorithm = (IAlgorithm)Algorithm.Clone(new Cloner());
75      preprocessedAlgorithm.Name = preprocessedAlgorithm.Name + "(Preprocessed)";
76      Algorithm.Runs.Clear();
77      var problem = (IDataAnalysisProblem)preprocessedAlgorithm.Problem;
78      SetNewProblemData(problem);
79      return preprocessedAlgorithm;
80    }
81    public IDataAnalysisProblem ExportProblem() {
82      var preprocessedProblem = (IDataAnalysisProblem)Problem.Clone(new Cloner());
83      SetNewProblemData(preprocessedProblem);
84      return preprocessedProblem;
85    }
86
87    public IDataAnalysisProblemData ExportProblemData() {
88      return creator.CreateProblemData();
89    }
90
91    private void SetNewProblemData(IDataAnalysisProblem problem) {
92      var data = creator.CreateProblemData();
93      problem.ProblemDataParameter.ActualValue = data;
94      problem.Name = "Preprocessed " + problem.Name;
95    }
96  }
97}
Note: See TracBrowser for help on using the repository browser.