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