source: branches/HeuristicLab.Problems.BioBoost/HeuristicLab.Problems.BioBoost/3.3/Representation/LayerDescriptor.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: 13.0 KB
Line 
1using System;
2using System.Collections.Generic;
3using System.Drawing;
4using System.Linq;
5using System.Reflection;
6using System.Runtime.CompilerServices;
7using System.Runtime.Serialization;
8using System.Text;
9using System.Threading.Tasks;
10using GeoAPI;
11using HeuristicLab.Common;
12using HeuristicLab.Core;
13using HeuristicLab.Data;
14using HeuristicLab.Persistence.Default.CompositeSerializers.Storable;
15using SharpMap;
16
17namespace HeuristicLab.BioBoost.Representation {
18
19  public interface ILayerDescriptor : IItem {
20    string Name { get; }
21    string Unit { get; }
22    string Description { get; }
23    string Separator { get; }
24    string FullName { get; }
25  }
26
27  public interface IValueLayer {
28    LayerDescriptor LayerDescriptor { get; }
29    double this[int idx] { get; set; }
30  }
31
32  public interface IAggregator {
33    IEnumerable<IValueLayer> Aggregate(IEnumerable<IValueLayer> layers, ItemArray<ItemList<IntValue>> sources);
34  }
35
36  public class SumAggregator : IAggregator {
37    public ILayerDescriptor TargetLayerDescriptor { get; private set; }
38    public SumAggregator(ILayerDescriptor descriptor) { TargetLayerDescriptor = descriptor; }
39    public IEnumerable<IValueLayer> Aggregate(IEnumerable<IValueLayer> layers, ItemArray<ItemList<IntValue>> sources) {
40      foreach (var layer in layers) {
41        if (layer.LayerDescriptor == TargetLayerDescriptor) {
42          //yield return
43        }
44      }
45      yield break;
46    }
47  }
48
49  [StorableClass(StorableClassType.AllFieldsAndAllProperties)]
50  public class LayerDescriptor : Item, ILayerDescriptor {
51
52    public string Name  { get; private set; }
53    public string Unit { get; private set; }
54    public string Description { get; private set; }
55    public string Separator { get; private set; }
56    public string FullName { get; private set; }
57
58    protected LayerDescriptor(bool isDeserializing) : base(isDeserializing) { }
59    protected LayerDescriptor(LayerDescriptor orig, Cloner cloner) : base(orig, cloner) { }
60
61    public LayerDescriptor(string name, string unit, string separator = " ") {
62      Name = name;
63      Unit = unit;
64      Separator = separator;
65      FullName = separator + name;
66    }
67
68    public string NameWithPrefix(string prefix) { return string.Format("{0}{1}", prefix, FullName); }
69    public bool IsSuffixOf(string s) { return s.EndsWith(FullName); }
70    public string RemoveSuffixFrom(string s) {
71      if (!s.EndsWith(FullName)) return s;
72      return s.Substring(0, s.Length - FullName.Length);
73    }
74
75    public override IDeepCloneable Clone(Cloner cloner) { return new LayerDescriptor(this, cloner); }
76
77    public static LayerDescriptor AmountsAtSource = new LayerDescriptor("amounts at source", "t/a");
78    public static LayerDescriptor AmountsAtTarget = new LayerDescriptor("amounts at target", "t/a");
79    public static LayerDescriptor AmountsTransportedFromSource = new LayerDescriptor("amounts transported from source", "t/a");
80    public static LayerDescriptor PotentialsFromProblemData = new LayerDescriptor("Potentials", "t/a", "");
81    public static LayerDescriptor Utilizations = new LayerDescriptor("Utilizations", "");
82    public static LayerDescriptor UtilizationsEffective = new LayerDescriptor("utilizations (effective)", "");
83    public static LayerDescriptor TransportTargets = new LayerDescriptor("Transport Targets", "region");
84    public static LayerDescriptor ConverterCapacities = new LayerDescriptor("converter capacities", "t/a");
85    public static LayerDescriptor StorageCapacities = new LayerDescriptor("storage capacities", "t/a");
86    public static LayerDescriptor AcquisitionCosts = new LayerDescriptor("acquisition costs", "€/a");
87    public static LayerDescriptor DischargeCosts = new LayerDescriptor("discharge costs", "€/a");
88    public static LayerDescriptor TransportCosts = new LayerDescriptor("transport costs", "€/a");
89    public static LayerDescriptor TransportCostsPerT = new LayerDescriptor("transport costs (per t)", "€/t");
90    public static LayerDescriptor TransportCostsPerTkm = new LayerDescriptor("transport costs (per tkm)", "€/tkm");
91    public static LayerDescriptor HandlingCosts = new LayerDescriptor("handling costs", "€/a");
92    public static LayerDescriptor RelativeHandlingCosts = new LayerDescriptor("handling costs (relative)", "€/t");
93    public static LayerDescriptor TransportModes = new LayerDescriptor("transport modes", "mode");
94    public static LayerDescriptor ConversionCosts = new LayerDescriptor("conversion costs", "€/a");
95    public static LayerDescriptor TotalAmortizedConversionCosts = new LayerDescriptor("total amortized conversion costs (incl. OPEX, CAPEX)", "€/a");
96    public static LayerDescriptor RelativeTotalAmortizedConversionCosts = new LayerDescriptor("total amortized conversion costs (incl. OPEX, CAPEX, relative)", "€/t");
97    public static LayerDescriptor ConversionPlantConstructionCost = new LayerDescriptor("conversion plant construction costs", "€/a");
98    public static LayerDescriptor ConversionPlantOperationCost = new LayerDescriptor("conversion plant operation costs", "€/a");
99    public static LayerDescriptor RelativeConversionCosts = new LayerDescriptor("conversion costs (relative)", "€/t");
100    public static LayerDescriptor RelativeConversionPlantConstructionCosts = new LayerDescriptor("conversion plant construction costs (relative)", "€/t");
101    public static LayerDescriptor RelativeConversionPlantOperationCosts = new LayerDescriptor("conversion plant operation costs (relative)", "€/t");
102    public static LayerDescriptor StorageCost = new LayerDescriptor("storage costs", "€/a");
103    public static LayerDescriptor RelativeStorageCost = new LayerDescriptor("storage costs (relative)", "€/t");
104    public static LayerDescriptor TransportDistance = new LayerDescriptor("transport distances", "km");
105    public static LayerDescriptor ExceedingTransportDistancePenalty = new LayerDescriptor("transport penalties", "");
106    public static LayerDescriptor Tkm = new LayerDescriptor("tkm", "tkm");
107    public static LayerDescriptor MaxConversionCapacity = new LayerDescriptor("converter capacities (max)", "t/a");
108    public static LayerDescriptor ScalingPenalty = new LayerDescriptor("converter scaling penalties", "");
109    public static LayerDescriptor TotalCostsAtTarget = new LayerDescriptor("total costs at target", "€/a");
110    public static LayerDescriptor TotalCostsAtSource = new LayerDescriptor("total costs at source", "€/a");
111    public static LayerDescriptor LocalAddedValue = new LayerDescriptor("local added value", "€/a", "");
112    public static LayerDescriptor RelativeCostAtSource = new LayerDescriptor("total costs at source (relative)", "€/t");
113    public static LayerDescriptor RelativeCostAtTarget = new LayerDescriptor("total costs at target (relative)", "€/t");
114    public static LayerDescriptor AmountsAtTargetConverted = new LayerDescriptor("amounts converted at target", "t/a");
115    public static LayerDescriptor TotalLogisticCosts = new LayerDescriptor("logistics costs", "€/a");
116    public static LayerDescriptor LogisticCostsPerTon = new LayerDescriptor("logistics costs (per t)", "€/t");
117    public static LayerDescriptor LogisticCostsPerTonKm = new LayerDescriptor("logistics costs (per tkm)", "€/tkm");
118    public static LayerDescriptor TotalDirectConversionCost = new LayerDescriptor("conversion costs (incl. supplies)", "€/a");
119    public static LayerDescriptor RelativeTotalDirectConversionCost = new LayerDescriptor("conversion costs (incl. supplies, relative)", "€/t");
120    public static LayerDescriptor TotalPenalty = new LayerDescriptor("total penalties", "", "");
121    public static LayerDescriptor Sources = new LayerDescriptor("conversion plant sources", "");
122    public static LayerDescriptor ScalingFactors = new LayerDescriptor("conversion plant scaling factors", "");
123    public static LayerDescriptor ExceedingCapacityPenalties = new LayerDescriptor("exceeding capacity penalties", "");
124
125    //public static LayerDescriptor AverageUtilizations = new LayerDescriptor("average utilizations", "t/a");
126    //public static LayerDescriptor AverageAmountsFromSource = new LayerDescriptor("average amounts from source", "t/a");
127    //public static LayerDescriptor AggregateAmountsFromSource = new LayerDescriptor("aggregate amounts from source", "t/a");
128    //public static LayerDescriptor AverageCostsFromSource = new LayerDescriptor("average costs from source", "t/a");
129    //public static LayerDescriptor AggregateCostsFromSource = new LayerDescriptor("aggregate costs from source", "t/a");
130
131    public static LayerDescriptor FeedstockCosts = new LayerDescriptor("feedstock costs", "€/a");
132    public static LayerDescriptor FeedstockCostsRelative = new LayerDescriptor("feedstock costs (relative)", "€/t");
133    //public static LayerDescriptor AggregatedAverageFeedstockCosts = new LayerDescriptor("aggregated average feedstock costs", "€/a");
134    //public static LayerDescriptor AggregatedFeedstockTransportCosts = new LayerDescriptor("aggregated feedstock transport costs", "€/a");
135    //public static LayerDescriptor RelativeAggregatedFeedstockTransportCosts = new LayerDescriptor("aggregated feedstock transport costs (relative)", "€/t");
136    //public static LayerDescriptor AggregatedFeedstockHandlingCosts = new LayerDescriptor("aggregated feedstock handling costs", "€/a");
137    //public static LayerDescriptor RelativeAggregatedFeedstockHandlingCosts = new LayerDescriptor("aggregated feedstock handling costs (relative)", "€/t");
138    //public static LayerDescriptor AggregatedFeedstockStorageCosts = new LayerDescriptor("aggregated feedstock storage costs", "€/a");
139    //public static LayerDescriptor RelativeAggregatedFeedstockStorageCosts = new LayerDescriptor("aggregated feedstock storage costs (relative)", "€/t");
140    public static LayerDescriptor DecentralLogisticCosts = new LayerDescriptor("logistic costs (decentral aggregated)", "€/a");
141    public static LayerDescriptor DecentralLogisticCostsRelative = new LayerDescriptor("logistic costs (decentral aggregated, relative)", "€/t");
142    //public static LayerDescriptor AggregatedDirectConversionCosts = new LayerDescriptor("aggregated direct conversion costs", "€/a");
143    //public static LayerDescriptor RelativeAggregatedDirectConversionCosts = new LayerDescriptor("aggregated direct conversion costs (relative)", "€/t");
144    //public static LayerDescriptor AggregatedConversionOperationCosts = new LayerDescriptor("aggregated conversion operation costs", "€/a");
145    //public static LayerDescriptor RelativeAggregatedConversionOperationCosts = new LayerDescriptor("aggregated conversion operation costs (relative)", "€/t");
146    //public static LayerDescriptor AggregatedConversionConstructionCosts = new LayerDescriptor("aggregated conversion construction costs", "€/a");
147    //public static LayerDescriptor RelativeAggregatedConversionConstructionCosts = new LayerDescriptor("aggregated conversion construction costs (relative)", "€/t");
148    public static LayerDescriptor DecentralConversionCosts = new LayerDescriptor("conversion costs (decentral aggregated)", "€/a");
149    public static LayerDescriptor DecentralConversionCostsRelative = new LayerDescriptor("conversion costs (decentral aggregated, relative)", "€/t");
150    public static LayerDescriptor CentralConversionCostsRelative = new LayerDescriptor("conversion costs (central aggregated, relative)", "€/t");
151    // ...
152    public static LayerDescriptor CentralLogisticCosts = new LayerDescriptor("logistic costs (central aggregated)", "€/a");
153    public static LayerDescriptor CentralLogisticCostsRelative = new LayerDescriptor("logistic costs (central aggregated, relative)", "€/t");
154
155    public static LayerDescriptor RoiFollowed = new LayerDescriptor("roi (followed)", "€/€");
156    public static LayerDescriptor RoiAggregated = new LayerDescriptor("roi (aggregated)", "€/€");
157
158
159
160    private static readonly List<LayerDescriptor> LAYERS = new List<LayerDescriptor>();
161
162    private static void DiscoverLayers() {
163        if (LAYERS.Count == 0) {
164          LAYERS.AddRange(
165            typeof (LayerDescriptor)
166              .GetFields(BindingFlags.Static | BindingFlags.Public)
167              .Select(f => f.GetValue(null))
168              .Where(v => v is LayerDescriptor)
169              .Cast<LayerDescriptor>()
170              .OrderByDescending(l => l.Name.Length));
171          foreach (var l1 in LAYERS) {
172            foreach (var l2 in LAYERS) {
173              if (l1 != l2 && l1.IsSuffixOf(l2.FullName))
174                throw new InvalidOperationException(string.Format("Layer overlap detected \"{0}\" is suffix of \"{1}\"", l1.FullName, l2.FullName));
175            }
176          }
177        }
178    }
179
180    public static IEnumerable<LayerDescriptor> Layers {
181      get {  DiscoverLayers(); return LAYERS; }
182    }
183
184    public static LayerDescriptor GetLayer(string fullName) {
185      DiscoverLayers();
186      foreach (var layer in LAYERS) {
187        if (layer.IsSuffixOf(fullName)) return layer;
188      }
189      return null;
190    }
191  }
192}
Note: See TracBrowser for help on using the repository browser.