1 | #region License Information
|
---|
2 | /* HeuristicLab
|
---|
3 | * Copyright (C) 2002-2015 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 HeuristicLab.BioBoost.ProblemDescription;
|
---|
23 | using HeuristicLab.BioBoost.Representation;
|
---|
24 | using HeuristicLab.Common;
|
---|
25 | using HeuristicLab.Core;
|
---|
26 | using HeuristicLab.Operators;
|
---|
27 | using HeuristicLab.Parameters;
|
---|
28 | using HEAL.Attic;
|
---|
29 |
|
---|
30 | namespace HeuristicLab.BioBoost.Operators {
|
---|
31 | [StorableType("9413703D-B45E-42AF-B2AE-82E6414E3924")]
|
---|
32 | public abstract class BioBoostOperator : SingleSuccessorOperator {
|
---|
33 |
|
---|
34 | #region Parameters
|
---|
35 | public ILookupParameter<BioBoostProblemData> ProblemDataParameter
|
---|
36 | {
|
---|
37 | get { return (ILookupParameter<BioBoostProblemData>)Parameters["ProblemData"]; }
|
---|
38 | }
|
---|
39 | #endregion
|
---|
40 |
|
---|
41 | #region Parameter Values
|
---|
42 | public BioBoostProblemData ProblemData
|
---|
43 | {
|
---|
44 | get { return ProblemDataParameter.ActualValue; }
|
---|
45 | }
|
---|
46 | #endregion
|
---|
47 |
|
---|
48 | #region Construction & Cloning
|
---|
49 | [StorableConstructor]
|
---|
50 | protected BioBoostOperator(StorableConstructorFlag _) : base(_) { }
|
---|
51 |
|
---|
52 | protected BioBoostOperator(BioBoostOperator original, Cloner cloner) : base(original, cloner) { }
|
---|
53 |
|
---|
54 | protected BioBoostOperator() {
|
---|
55 | Parameters.Add(new LookupParameter<BioBoostProblemData>("ProblemData", "Contains fixed values describing the problem."));
|
---|
56 | }
|
---|
57 | #endregion
|
---|
58 |
|
---|
59 | protected T GetFromProblemData<T>(string label) where T : class, IItem {
|
---|
60 | IParameter param;
|
---|
61 | if (LayerDescriptor.PotentialsFromProblemData.IsSuffixOf(label)) {
|
---|
62 | ProblemData.FeedstockPotentials.TryGetValue(label, out param);
|
---|
63 | } else {
|
---|
64 | ProblemData.Parameters.TryGetValue(label, out param);
|
---|
65 | }
|
---|
66 | var valueParam = param as IValueParameter;
|
---|
67 | if (valueParam != null) return valueParam.Value as T;
|
---|
68 | if (param != null) return param.ActualValue as T;
|
---|
69 | return null;
|
---|
70 | }
|
---|
71 |
|
---|
72 | protected T GetFromScope<T>(string label) where T : class, IItem {
|
---|
73 | IVariable var = null;
|
---|
74 | ExecutionContext.Scope.Variables.TryGetValue(label, out var);
|
---|
75 | if (var != null) return var.Value as T;
|
---|
76 | return null;
|
---|
77 | }
|
---|
78 |
|
---|
79 | protected void RemoveFromScope(string label) {
|
---|
80 | ExecutionContext.Scope.Variables.Remove(label);
|
---|
81 | }
|
---|
82 |
|
---|
83 | protected void RenameInScope(string oldLabel, string newLabel) {
|
---|
84 | var vars = ExecutionContext.Scope.Variables;
|
---|
85 | IVariable var;
|
---|
86 | if (!vars.TryGetValue(oldLabel, out var)) return;
|
---|
87 | vars.Remove(oldLabel);
|
---|
88 | if (vars.ContainsKey(newLabel))
|
---|
89 | vars.Remove(newLabel);
|
---|
90 | vars.Add(new Variable(newLabel, var.Value));
|
---|
91 | }
|
---|
92 | }
|
---|
93 | } |
---|