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

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

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

File size: 1.8 KB
Line 
1using System;
2using System.Linq;
3using HeuristicLab.BioBoost.Data;
4using HeuristicLab.Common;
5using HeuristicLab.Core;
6using HeuristicLab.Data;
7using HeuristicLab.Encodings.IntegerVectorEncoding;
8using HeuristicLab.Encodings.RealVectorEncoding;
9using HeuristicLab.Persistence.Default.CompositeSerializers.Storable;
10using System.Collections.Generic;
11using HeuristicLab.BioBoost.Representation;
12
13namespace 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}
Note: See TracBrowser for help on using the repository browser.