Free cookie consent management tool by TermsFeed Policy Generator

source: addons/HeuristicLab.Problems.BioBoost/HeuristicLab.Problems.BioBoost/3.3/Operators/Transformation/FeedstockTransformer.cs @ 16575

Last change on this file since 16575 was 16575, checked in by gkronber, 5 years ago

#2520: changed HeuristicLab.BioBoost addon to compile with new HL.Persistence

File size: 3.1 KB
Line 
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
22using HeuristicLab.Common;
23using HeuristicLab.Core;
24using HeuristicLab.Data;
25using HeuristicLab.Parameters;
26using HeuristicLab.Persistence.Default.CompositeSerializers.Storable;
27using HEAL.Attic;
28
29namespace HeuristicLab.BioBoost.Operators.Transformation {
30
31  [StorableType("4899F5B6-FD69-4CAA-896C-20A51A4B0BCC")]
32  public class FeedstockTransformer : BioBoostOperator {
33
34
35    public ValueLookupParameter<StringValue> ProductNameParameter { get { return (ValueLookupParameter<StringValue>) Parameters["ProductName"]; } }
36
37    public string ProductName {
38      get { return ProductNameParameter.Value.Value; }
39      set { ProductNameParameter.Value = new StringValue(value);}
40    }
41
42    #region Construction & Cloning
43    [StorableConstructor]
44    protected FeedstockTransformer(StorableConstructorFlag _) : base(_) { }
45    protected FeedstockTransformer(FeedstockTransformer orig, Cloner cloner) : base(orig, cloner) {}
46    public FeedstockTransformer() {
47      Parameters.Add(new ValueLookupParameter<StringValue>("ProductName", "The product name to be transformed."));
48    }
49    public override IDeepCloneable  Clone(Cloner cloner) {
50      return new FeedstockTransformer(this, cloner);
51    }
52    #endregion
53
54    public override IOperation Execute(IExecutionContext context, System.Threading.CancellationToken cancellationToken) {
55      return base.Execute(context, cancellationToken);
56    }
57
58    protected void TransformValue<T>(string valueName, T value) where T : class, IItem {
59      IParameter param;
60      if (!Parameters.TryGetValue(valueName, out param)) {
61        param = new LookupParameter<T>(valueName, "Transformed value.");
62        ((ILookupParameter) param).ExecutionContext = ExecutionContext;
63        Parameters.Add(param);
64      }
65      param.ActualValue = value;
66    }
67
68
69    protected double GetMaxCapacity(int i, ValueParameterCollection maxCapacities, double defaultValue) {
70      var regionName = ProblemData.LocationNames[i];
71      IValueParameter param;
72      if (maxCapacities.TryGetValue(regionName, out param)) return ((DoubleValue) param.Value).Value;
73      if (maxCapacities.TryGetValue("Default", out param)) return ((DoubleValue) param.Value).Value;
74      return defaultValue;
75    }
76  }
77}
Note: See TracBrowser for help on using the repository browser.