1 | using System;
|
---|
2 | using System.Linq;
|
---|
3 | using HeuristicLab.BioBoost.Data;
|
---|
4 | using HeuristicLab.Common;
|
---|
5 | using HeuristicLab.Core;
|
---|
6 | using HeuristicLab.Data;
|
---|
7 | using HeuristicLab.Encodings.IntegerVectorEncoding;
|
---|
8 | using HeuristicLab.Encodings.RealVectorEncoding;
|
---|
9 | using HeuristicLab.Persistence.Default.CompositeSerializers.Storable;
|
---|
10 | using System.Collections.Generic;
|
---|
11 | using HeuristicLab.BioBoost.Representation;
|
---|
12 |
|
---|
13 | namespace HeuristicLab.BioBoost.Operators.Transformation {
|
---|
14 |
|
---|
15 | [StorableClass]
|
---|
16 | public class FeedstockInflater : FeedstockTransformer {
|
---|
17 |
|
---|
18 | #region Construction & Cloning
|
---|
19 | [StorableConstructor]
|
---|
20 | protected FeedstockInflater(bool isDeserializing) : base(isDeserializing) {}
|
---|
21 | protected FeedstockInflater(FeedstockInflater orig, Cloner cloner) : base(orig, cloner) {}
|
---|
22 | public FeedstockInflater() {}
|
---|
23 | public override IDeepCloneable Clone(Cloner cloner) {
|
---|
24 | return new FeedstockInflater(this, cloner);
|
---|
25 | }
|
---|
26 | #endregion
|
---|
27 |
|
---|
28 | public override IOperation Apply() {
|
---|
29 | var product = ProductName;
|
---|
30 | var potentials = GetFromProblemData<DoubleArray>(LayerDescriptor.PotentialsFromProblemData.NameWithPrefix(product));
|
---|
31 | var utilizations = GetFromScope<RealVector>(LayerDescriptor.Utilizations.NameWithPrefix(product));
|
---|
32 | if (potentials != null && utilizations != null) {
|
---|
33 | var newUtilizations = new List<double>();
|
---|
34 | var skipped = 0;
|
---|
35 | for (int i = 0; i < potentials.Length; i++) {
|
---|
36 | if (potentials[i] > 0) {
|
---|
37 | newUtilizations.Add(utilizations[i - skipped]);
|
---|
38 | } else {
|
---|
39 | skipped++;
|
---|
40 | newUtilizations.Add(0);
|
---|
41 | }
|
---|
42 | }
|
---|
43 | TransformValue(LayerDescriptor.Utilizations.NameWithPrefix(product), new RealVector(newUtilizations.ToArray()));
|
---|
44 | }
|
---|
45 | return base.Apply();
|
---|
46 | }
|
---|
47 | }
|
---|
48 | }
|
---|