Free cookie consent management tool by TermsFeed Policy Generator

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

Last change on this file since 10785 was 10783, checked in by mleitner, 11 years ago

Add FilteredPreprocessing data for applying and caching filter status

File size: 3.7 KB
RevLine 
[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]22using System;
[10219]23using HeuristicLab.Common;
24using HeuristicLab.Core;
[10673]25using HeuristicLab.Encodings.SymbolicExpressionTreeEncoding;
[10240]26using HeuristicLab.Optimization;
[10221]27using HeuristicLab.Problems.DataAnalysis;
[10673]28using HeuristicLab.Problems.DataAnalysis.Symbolic;
[10676]29using Variable = HeuristicLab.Problems.DataAnalysis.Symbolic.Variable;
[10783]30using HeuristicLab.DataPreprocessing.Implementations;
31using HeuristicLab.DataPreprocessing.Interfaces;
[10219]32
33namespace HeuristicLab.DataPreprocessing {
34  [Item("PreprocessingContext", "PreprocessingContext")]
[10383]35  public class PreprocessingContext
36    : Item, IPreprocessingContext {
37
[10783]38    public IFilteredPreprocessingData Data { get; private set; }
[10614]39
40    public IDataAnalysisProblemData DataAnalysisProblemData { get; private set; }
41
42    public IAlgorithm Algorithm { get; private set; }
43
[10676]44    public IDataAnalysisProblem Problem { get; private set; }
[10614]45
[10676]46    public PreprocessingContext(IDataAnalysisProblemData dataAnalysisProblemData, IAlgorithm algorithm, IDataAnalysisProblem problem) {
[10783]47
48      TransactionalPreprocessingData transactionalPreprocessingData = new TransactionalPreprocessingData(dataAnalysisProblemData);
49
50      Data = new FilteredPreprocessingData(transactionalPreprocessingData);
[10221]51      DataAnalysisProblemData = dataAnalysisProblemData;
[10240]52      Algorithm = algorithm;
[10307]53      Problem = problem;
[10219]54    }
55
56    private PreprocessingContext(PreprocessingContext original, Cloner cloner)
57      : base(original, cloner) {
58      Data = cloner.Clone(original.Data);
[10221]59      DataAnalysisProblemData = original.DataAnalysisProblemData;
[10240]60      Algorithm = original.Algorithm;
[10307]61      Problem = original.Problem;
[10219]62    }
63
64    public override IDeepCloneable Clone(Cloner cloner) {
65      return new PreprocessingContext(this, cloner);
66    }
[10383]67
68    public IItem ExportAlgorithmOrProblem() {
69      if (Algorithm != null) {
70        return ExportAlgorithm();
71      }
[10676]72      return ExportProblem();
[10383]73    }
[10676]74
[10383]75    public IProblem ExportProblem() {
76      return Export(Problem, SetupProblem);
77    }
[10614]78    public IAlgorithm ExportAlgorithm() {
79      return Export(Algorithm, SetupAlgorithm);
80    }
[10383]81
[10676]82    private IDataAnalysisProblem SetupProblem(IProblem problem) {
83      return (IDataAnalysisProblem)problem;
[10383]84    }
[10676]85    private IDataAnalysisProblem SetupAlgorithm(IAlgorithm algorithm) {
[10536]86      algorithm.Name = algorithm.Name + "(Preprocessed)";
[10383]87      algorithm.Runs.Clear();
[10676]88      return (IDataAnalysisProblem)algorithm.Problem;
[10383]89    }
[10676]90    private T Export<T>(T original, Func<T, IDataAnalysisProblem> setup)
[10536]91        where T : IItem {
[10383]92      var creator = new ProblemDataCreator(this);
93      var data = creator.CreateProblemData();
94
95      var clone = (T)original.Clone(new Cloner());
96
97      var problem = setup(clone);
98      problem.ProblemDataParameter.ActualValue = data;
[10536]99      problem.Name = "Preprocessed " + problem.Name;
[10383]100      return clone;
101    }
[10219]102  }
103}
Note: See TracBrowser for help on using the repository browser.