1 | using HeuristicLab.BioBoost.ProblemDescription;
|
---|
2 | using HeuristicLab.BioBoost.Representation;
|
---|
3 | using HeuristicLab.Common;
|
---|
4 | using HeuristicLab.Core;
|
---|
5 | using HeuristicLab.Operators;
|
---|
6 | using HeuristicLab.Parameters;
|
---|
7 | using HeuristicLab.Persistence.Default.CompositeSerializers.Storable;
|
---|
8 |
|
---|
9 | namespace HeuristicLab.BioBoost.Operators {
|
---|
10 | public abstract class BioBoostOperator : SingleSuccessorOperator {
|
---|
11 |
|
---|
12 | #region Parameters
|
---|
13 | public ILookupParameter<BioBoostProblemData> ProblemDataParameter {
|
---|
14 | get { return (ILookupParameter<BioBoostProblemData>) Parameters["ProblemData"]; }
|
---|
15 | }
|
---|
16 | #endregion
|
---|
17 |
|
---|
18 | #region Parameter Values
|
---|
19 | public BioBoostProblemData ProblemData {
|
---|
20 | get { return ProblemDataParameter.ActualValue; }
|
---|
21 | }
|
---|
22 | #endregion
|
---|
23 |
|
---|
24 | #region Construction & Cloning
|
---|
25 | [StorableConstructor]
|
---|
26 | protected BioBoostOperator(bool isDeserializing) : base(isDeserializing) {}
|
---|
27 |
|
---|
28 | protected BioBoostOperator(BioBoostOperator original, Cloner cloner) : base(original, cloner) { }
|
---|
29 |
|
---|
30 | protected BioBoostOperator() {
|
---|
31 | Parameters.Add(new LookupParameter<BioBoostProblemData>("ProblemData", "Contains fixed values describing the problem."));
|
---|
32 | }
|
---|
33 | #endregion
|
---|
34 |
|
---|
35 | protected T GetFromProblemData<T>(string label) where T : class, IItem {
|
---|
36 | IParameter param;
|
---|
37 | if(LayerDescriptor.PotentialsFromProblemData.IsSuffixOf(label)) {
|
---|
38 | ProblemData.FeedstockPotentials.TryGetValue(label, out param);
|
---|
39 | } else {
|
---|
40 | ProblemData.Parameters.TryGetValue(label, out param);
|
---|
41 | }
|
---|
42 | var valueParam = param as IValueParameter;
|
---|
43 | if (valueParam != null) return valueParam.Value as T;
|
---|
44 | if (param != null) return param.ActualValue as T;
|
---|
45 | return null;
|
---|
46 | }
|
---|
47 |
|
---|
48 | protected T GetFromScope<T>(string label) where T : class, IItem {
|
---|
49 | IVariable var = null;
|
---|
50 | ExecutionContext.Scope.Variables.TryGetValue(label, out var);
|
---|
51 | if (var != null) return var.Value as T;
|
---|
52 | return null;
|
---|
53 | }
|
---|
54 |
|
---|
55 | protected void RemoveFromScope(string label) {
|
---|
56 | ExecutionContext.Scope.Variables.Remove(label);
|
---|
57 | }
|
---|
58 |
|
---|
59 | protected void RenameInScope(string oldLabel, string newLabel) {
|
---|
60 | var vars = ExecutionContext.Scope.Variables;
|
---|
61 | IVariable var;
|
---|
62 | if (!vars.TryGetValue(oldLabel, out var)) return;
|
---|
63 | vars.Remove(oldLabel);
|
---|
64 | if (vars.ContainsKey(newLabel))
|
---|
65 | vars.Remove(newLabel);
|
---|
66 | vars.Add(new Variable(newLabel, var.Value));
|
---|
67 | }
|
---|
68 | }
|
---|
69 | } |
---|