[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;
|
---|
[10219] | 27 |
|
---|
| 28 | namespace HeuristicLab.DataPreprocessing {
|
---|
| 29 | [Item("PreprocessingContext", "PreprocessingContext")]
|
---|
[10383] | 30 | public class PreprocessingContext
|
---|
| 31 | : Item, IPreprocessingContext {
|
---|
| 32 |
|
---|
| 33 | public PreprocessingContext(IDataAnalysisProblemData dataAnalysisProblemData, IAlgorithm algorithm, IDataAnalysisProblem problem) {
|
---|
[10586] | 34 | Data = new TransactionalPreprocessingData(dataAnalysisProblemData);
|
---|
[10221] | 35 | DataAnalysisProblemData = dataAnalysisProblemData;
|
---|
[10240] | 36 | Algorithm = algorithm;
|
---|
[10307] | 37 | Problem = problem;
|
---|
[10219] | 38 | }
|
---|
| 39 |
|
---|
| 40 | private PreprocessingContext(PreprocessingContext original, Cloner cloner)
|
---|
| 41 | : base(original, cloner) {
|
---|
| 42 | Data = cloner.Clone(original.Data);
|
---|
[10221] | 43 | DataAnalysisProblemData = original.DataAnalysisProblemData;
|
---|
[10240] | 44 | Algorithm = original.Algorithm;
|
---|
[10307] | 45 | Problem = original.Problem;
|
---|
[10219] | 46 | }
|
---|
| 47 |
|
---|
[10586] | 48 | public ITransactionalPreprocessingData Data { get; private set; }
|
---|
[10219] | 49 |
|
---|
[10221] | 50 | public IDataAnalysisProblemData DataAnalysisProblemData { get; private set; }
|
---|
| 51 |
|
---|
[10240] | 52 | public IAlgorithm Algorithm { get; private set; }
|
---|
| 53 |
|
---|
[10383] | 54 | public IDataAnalysisProblem Problem { get; private set; }
|
---|
[10307] | 55 |
|
---|
[10219] | 56 | public override IDeepCloneable Clone(Cloner cloner) {
|
---|
| 57 | return new PreprocessingContext(this, cloner);
|
---|
| 58 | }
|
---|
[10383] | 59 |
|
---|
| 60 | public IItem ExportAlgorithmOrProblem() {
|
---|
| 61 | if (Algorithm != null) {
|
---|
| 62 | return ExportAlgorithm();
|
---|
| 63 | } else {
|
---|
| 64 | return ExportProblem();
|
---|
| 65 | }
|
---|
| 66 | }
|
---|
| 67 |
|
---|
| 68 | public IProblem ExportProblem() {
|
---|
| 69 | return Export(Problem, SetupProblem);
|
---|
| 70 | }
|
---|
| 71 |
|
---|
| 72 | private IDataAnalysisProblem SetupProblem(IProblem problem) {
|
---|
| 73 | return (IDataAnalysisProblem)problem;
|
---|
| 74 | }
|
---|
| 75 |
|
---|
| 76 | public IAlgorithm ExportAlgorithm() {
|
---|
| 77 | return Export(Algorithm, SetupAlgorithm);
|
---|
| 78 | }
|
---|
| 79 |
|
---|
| 80 | private IDataAnalysisProblem SetupAlgorithm(IAlgorithm algorithm) {
|
---|
[10536] | 81 | algorithm.Name = algorithm.Name + "(Preprocessed)";
|
---|
[10383] | 82 | algorithm.Runs.Clear();
|
---|
| 83 |
|
---|
| 84 | return (IDataAnalysisProblem)algorithm.Problem;
|
---|
| 85 | }
|
---|
| 86 |
|
---|
[10536] | 87 | private T Export<T>(T original, Func<T, IDataAnalysisProblem> setup)
|
---|
| 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 |
|
---|
| 98 | return clone;
|
---|
| 99 | }
|
---|
[10219] | 100 | }
|
---|
| 101 | }
|
---|