[10219] | 1 | #region License Information
|
---|
| 2 | /* HeuristicLab
|
---|
[12009] | 3 | * Copyright (C) 2002-2015 Heuristic and Evolutionary Algorithms Laboratory (HEAL)
|
---|
[10219] | 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 |
|
---|
| 22 | using HeuristicLab.Common;
|
---|
| 23 | using HeuristicLab.Core;
|
---|
[11114] | 24 | using HeuristicLab.DataPreprocessing.Implementations;
|
---|
| 25 | using HeuristicLab.DataPreprocessing.Interfaces;
|
---|
[10240] | 26 | using HeuristicLab.Optimization;
|
---|
[10221] | 27 | using HeuristicLab.Problems.DataAnalysis;
|
---|
[10219] | 28 |
|
---|
| 29 | namespace HeuristicLab.DataPreprocessing {
|
---|
| 30 | [Item("PreprocessingContext", "PreprocessingContext")]
|
---|
[10383] | 31 | public class PreprocessingContext
|
---|
| 32 | : Item, IPreprocessingContext {
|
---|
| 33 |
|
---|
[10990] | 34 |
|
---|
[10783] | 35 | public IFilteredPreprocessingData Data { get; private set; }
|
---|
[10990] | 36 |
|
---|
[10614] | 37 | public IAlgorithm Algorithm { get; private set; }
|
---|
[10676] | 38 | public IDataAnalysisProblem Problem { get; private set; }
|
---|
[10990] | 39 | public IDataAnalysisProblemData ProblemData { get; private set; }
|
---|
[10614] | 40 |
|
---|
[10990] | 41 | private readonly ProblemDataCreator creator;
|
---|
| 42 |
|
---|
[10676] | 43 | public PreprocessingContext(IDataAnalysisProblemData dataAnalysisProblemData, IAlgorithm algorithm, IDataAnalysisProblem problem) {
|
---|
[10990] | 44 | var transactionalPreprocessingData = new TransactionalPreprocessingData(dataAnalysisProblemData);
|
---|
| 45 | Data = new FilteredPreprocessingData(transactionalPreprocessingData);
|
---|
[10783] | 46 |
|
---|
[10990] | 47 | ProblemData = dataAnalysisProblemData;
|
---|
[10240] | 48 | Algorithm = algorithm;
|
---|
[10307] | 49 | Problem = problem;
|
---|
[10990] | 50 |
|
---|
| 51 | creator = new ProblemDataCreator(this);
|
---|
[10219] | 52 | }
|
---|
| 53 |
|
---|
[11114] | 54 | protected PreprocessingContext(PreprocessingContext original, Cloner cloner)
|
---|
[10219] | 55 | : base(original, cloner) {
|
---|
| 56 | Data = cloner.Clone(original.Data);
|
---|
[10240] | 57 | Algorithm = original.Algorithm;
|
---|
[10307] | 58 | Problem = original.Problem;
|
---|
[10219] | 59 | }
|
---|
| 60 |
|
---|
| 61 | public override IDeepCloneable Clone(Cloner cloner) {
|
---|
| 62 | return new PreprocessingContext(this, cloner);
|
---|
| 63 | }
|
---|
[10383] | 64 |
|
---|
[10990] | 65 | public IItem Export() {
|
---|
| 66 | if (Algorithm != null)
|
---|
[10383] | 67 | return ExportAlgorithm();
|
---|
[10990] | 68 | else if (Problem != null)
|
---|
| 69 | return ExportProblem();
|
---|
| 70 | return ExportProblemData();
|
---|
[10383] | 71 | }
|
---|
[10614] | 72 | public IAlgorithm ExportAlgorithm() {
|
---|
[10990] | 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;
|
---|
[10614] | 79 | }
|
---|
[10990] | 80 | public IDataAnalysisProblem ExportProblem() {
|
---|
| 81 | var preprocessedProblem = (IDataAnalysisProblem)Problem.Clone(new Cloner());
|
---|
| 82 | SetNewProblemData(preprocessedProblem);
|
---|
| 83 | return preprocessedProblem;
|
---|
| 84 | }
|
---|
[10383] | 85 |
|
---|
[10990] | 86 | public IDataAnalysisProblemData ExportProblemData() {
|
---|
| 87 | return creator.CreateProblemData();
|
---|
[10383] | 88 | }
|
---|
[10990] | 89 |
|
---|
| 90 | private void SetNewProblemData(IDataAnalysisProblem problem) {
|
---|
[10383] | 91 | var data = creator.CreateProblemData();
|
---|
| 92 | problem.ProblemDataParameter.ActualValue = data;
|
---|
[10536] | 93 | problem.Name = "Preprocessed " + problem.Name;
|
---|
[10383] | 94 | }
|
---|
[10219] | 95 | }
|
---|
| 96 | }
|
---|