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