1 | using System;
|
---|
2 | using System.Globalization;
|
---|
3 | using System.Linq;
|
---|
4 | using HeuristicLab.BioBoost.Data;
|
---|
5 | using HeuristicLab.Common;
|
---|
6 | using HeuristicLab.Core;
|
---|
7 | using HeuristicLab.Data;
|
---|
8 | using HeuristicLab.Encodings.IntegerVectorEncoding;
|
---|
9 | using HeuristicLab.Encodings.RealVectorEncoding;
|
---|
10 | using HeuristicLab.Parameters;
|
---|
11 | using HeuristicLab.Persistence.Default.CompositeSerializers.Storable;
|
---|
12 | using System.Collections.Generic;
|
---|
13 | using HeuristicLab.BioBoost.Representation;
|
---|
14 |
|
---|
15 | namespace 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 | }
|
---|