1 | using HeuristicLab.Common;
|
---|
2 | using HeuristicLab.Core;
|
---|
3 | using HeuristicLab.Data;
|
---|
4 | using HeuristicLab.Encodings.IntegerVectorEncoding;
|
---|
5 | using HeuristicLab.Encodings.RealVectorEncoding;
|
---|
6 | using HeuristicLab.Parameters;
|
---|
7 | using HeuristicLab.Persistence.Default.CompositeSerializers.Storable;
|
---|
8 |
|
---|
9 | namespace 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 | }
|
---|