source: branches/HeuristicLab.Problems.BioBoost/HeuristicLab.Problems.BioBoost/3.3/Operators/Transformation/FeedstockDeflater.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: 3.3 KB
Line 
1using System;
2using System.Globalization;
3using System.Linq;
4using HeuristicLab.BioBoost.Data;
5using HeuristicLab.Common;
6using HeuristicLab.Core;
7using HeuristicLab.Data;
8using HeuristicLab.Encodings.IntegerVectorEncoding;
9using HeuristicLab.Encodings.RealVectorEncoding;
10using HeuristicLab.Parameters;
11using HeuristicLab.Persistence.Default.CompositeSerializers.Storable;
12using System.Collections.Generic;
13using HeuristicLab.BioBoost.Representation;
14
15namespace HeuristicLab.BioBoost.Operators.Transformation {
16
17  [StorableClass]
18  public class FeedstockDeflater : FeedstockTransformer {
19
20    public ILookupParameter<IntArray> ViableSourcesParameter { get { return (ILookupParameter<IntArray>) Parameters["ViableSources"]; } }
21    public ILookupParameter<IntArray> ViableTargetsParameter { get { return (ILookupParameter<IntArray>) Parameters["ViableTargets"]; } }
22
23    public IntArray ViableSources { set { ViableSourcesParameter.ActualValue = value; } }
24    public IntArray ViableTargets { set { ViableTargetsParameter.ActualValue = value; } }
25
26    #region Construction & Cloning
27    [StorableConstructor]
28    protected FeedstockDeflater(bool isDeserializing) : base(isDeserializing) {}
29    protected FeedstockDeflater(FeedstockDeflater orig, Cloner cloner) : base(orig, cloner) {}
30    public FeedstockDeflater() {
31      Parameters.Add(new LookupParameter<IntArray>("ViableSources", "A list with all indices of viable source regions."));
32      Parameters.Add(new LookupParameter<IntArray>("ViableTargets", "A list with all indices of viable target regions."));
33    }
34    public override IDeepCloneable  Clone(Cloner cloner) {
35      return new FeedstockDeflater(this, cloner);
36    }
37    #endregion
38
39    public override IOperation Apply() {
40      var product = ProductName;
41      var potentials = GetFromProblemData<DoubleArray>(LayerDescriptor.PotentialsFromProblemData.NameWithPrefix(product));
42      var utilizations = GetFromScope<RealVector>(LayerDescriptor.Utilizations.NameWithPrefix(product));
43      if (potentials != null && utilizations != null) {
44        var newUtilizations = new List<double>();
45        for (int i = 0; i < potentials.Length; i++) {
46          if (potentials[i] > 0) {
47            newUtilizations.Add(utilizations[i]);
48          }
49        }
50        TransformValue(LayerDescriptor.Utilizations.NameWithPrefix(product), new RealVector(newUtilizations.ToArray()));
51      }
52      var targets = GetFromScope<IntegerVector>(LayerDescriptor.TransportTargets.NameWithPrefix(product));
53      var viableSources = new List<int>();
54      if (potentials != null && targets != null) {
55        for (int i = 0; i < potentials.Length; i++) {
56          if (potentials[i] > 0) {
57            viableSources.Add(i);
58          }
59        }
60        ViableSources = new IntArray(viableSources.ToArray());
61      }
62      var conversion = ProblemData.Conversions[product].FirstOrDefault();
63      var viableTargets = new List<int>();
64      if (conversion != null && targets != null) {
65        for (int i = 0; i < targets.Length; i++) {
66          if (GetMaxCapacity(i, conversion.MaxCapacities, Double.MaxValue) > 0) {
67            viableTargets.Add(i);
68          }
69        }
70        ViableTargets = new IntArray(viableTargets.ToArray());
71      }
72      return base.Apply();
73    }
74
75  }
76}
Note: See TracBrowser for help on using the repository browser.