Free cookie consent management tool by TermsFeed Policy Generator

source: branches/HeuristicLab.Problems.BioBoost/HeuristicLab.Problems.BioBoost/3.3/Operators/Transformation/FeedstockTransformer.cs @ 13069

Last change on this file since 13069 was 13069, checked in by gkronber, 8 years ago

#2499: imported source code for HeuristicLab.BioBoost from private repository with some changes

File size: 2.3 KB
Line 
1using HeuristicLab.Common;
2using HeuristicLab.Core;
3using HeuristicLab.Data;
4using HeuristicLab.Encodings.IntegerVectorEncoding;
5using HeuristicLab.Encodings.RealVectorEncoding;
6using HeuristicLab.Parameters;
7using HeuristicLab.Persistence.Default.CompositeSerializers.Storable;
8
9namespace HeuristicLab.BioBoost.Operators.Transformation {
10
11  [StorableClass]
12  public class FeedstockTransformer : BioBoostOperator {
13
14
15    public ValueLookupParameter<StringValue> ProductNameParameter { get { return (ValueLookupParameter<StringValue>) Parameters["ProductName"]; } }
16
17    public string ProductName {
18      get { return ProductNameParameter.Value.Value; }
19      set { ProductNameParameter.Value = new StringValue(value);}
20    }
21
22    #region Construction & Cloning
23    [StorableConstructor]
24    protected FeedstockTransformer(bool isDeserializing) : base(isDeserializing) {}
25    protected FeedstockTransformer(FeedstockTransformer orig, Cloner cloner) : base(orig, cloner) {}
26    public FeedstockTransformer() {
27      Parameters.Add(new ValueLookupParameter<StringValue>("ProductName", "The product name to be transformed."));
28    }
29    public override IDeepCloneable  Clone(Cloner cloner) {
30      return new FeedstockTransformer(this, cloner);
31    }
32    #endregion
33
34    public override IOperation Execute(IExecutionContext context, System.Threading.CancellationToken cancellationToken) {
35      return base.Execute(context, cancellationToken);
36    }
37
38    protected void TransformValue<T>(string valueName, T value) where T : class, IItem {
39      IParameter param;
40      if (!Parameters.TryGetValue(valueName, out param)) {
41        param = new LookupParameter<T>(valueName, "Transformed value.");
42        ((ILookupParameter) param).ExecutionContext = ExecutionContext;
43        Parameters.Add(param);
44      }
45      param.ActualValue = value;
46    }
47
48
49    protected double GetMaxCapacity(int i, ValueParameterCollection maxCapacities, double defaultValue) {
50      var regionName = ProblemData.LocationNames[i];
51      IValueParameter param;
52      if (maxCapacities.TryGetValue(regionName, out param)) return ((DoubleValue) param.Value).Value;
53      if (maxCapacities.TryGetValue("Default", out param)) return ((DoubleValue) param.Value).Value;
54      return defaultValue;
55    }
56  }
57}
Note: See TracBrowser for help on using the repository browser.