Free cookie consent management tool by TermsFeed Policy Generator

source: addons/HeuristicLab.Problems.BioBoost/HeuristicLab.Problems.BioBoost/3.3/Representation/LayerDescriptor.cs @ 17777

Last change on this file since 17777 was 16575, checked in by gkronber, 5 years ago

#2520: changed HeuristicLab.BioBoost addon to compile with new HL.Persistence

File size: 14.0 KB
Line 
1#region License Information
2/* HeuristicLab
3 * Copyright (C) 2002-2015 Heuristic and Evolutionary Algorithms Laboratory (HEAL)
4 *
5 * This file is part of HeuristicLab.
6 *
7 * HeuristicLab is free software: you can redistribute it and/or modify
8 * it under the terms of the GNU General Public License as published by
9 * the Free Software Foundation, either version 3 of the License, or
10 * (at your option) any later version.
11 *
12 * HeuristicLab is distributed in the hope that it will be useful,
13 * but WITHOUT ANY WARRANTY; without even the implied warranty of
14 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
15 * GNU General Public License for more details.
16 *
17 * You should have received a copy of the GNU General Public License
18 * along with HeuristicLab. If not, see <http://www.gnu.org/licenses/>.
19 */
20#endregion
21
22using System;
23using System.Collections.Generic;
24using System.Linq;
25using System.Reflection;
26using HeuristicLab.Common;
27using HeuristicLab.Core;
28using HeuristicLab.Data;
29using HeuristicLab.Persistence.Default.CompositeSerializers.Storable;
30using HEAL.Attic;
31
32namespace HeuristicLab.BioBoost.Representation {
33  [StorableType("9464112A-FE8E-43C0-A6F9-5626D63D2D30")]
34  public interface ILayerDescriptor : IItem {
35    string Name { get; }
36    string Unit { get; }
37    string Description { get; }
38    string Separator { get; }
39    string FullName { get; }
40  }
41
42  [StorableType("D6229284-9C48-4FE9-B37F-34FA96B9FC55")]
43  public interface IValueLayer {
44    LayerDescriptor LayerDescriptor { get; }
45    double this[int idx] { get; set; }
46  }
47
48  [StorableType("507933FD-C6B8-44DB-BE23-0343CED49204")]
49  public interface IAggregator {
50    IEnumerable<IValueLayer> Aggregate(IEnumerable<IValueLayer> layers, ItemArray<ItemList<IntValue>> sources);
51  }
52
53  [StorableType("6CD7E1DD-7862-49C7-8B2A-6F756D7A775F")]
54  public class SumAggregator : IAggregator {
55    public ILayerDescriptor TargetLayerDescriptor { get; private set; }
56    [StorableConstructor]
57    protected SumAggregator(StorableConstructorFlag _) { }
58
59    public SumAggregator(ILayerDescriptor descriptor) { TargetLayerDescriptor = descriptor; }
60    public IEnumerable<IValueLayer> Aggregate(IEnumerable<IValueLayer> layers, ItemArray<ItemList<IntValue>> sources) {
61      foreach (var layer in layers) {
62        if (layer.LayerDescriptor == TargetLayerDescriptor) {
63          //yield return
64        }
65      }
66      yield break;
67    }
68  }
69
70  [StorableType(StorableMemberSelection.AllFieldsAndAllProperties, "4C00E073-D186-49CD-A794-8A44B55779E8")]
71  public class LayerDescriptor : Item, ILayerDescriptor {
72
73    public string Name { get; private set; }
74    public string Unit { get; private set; }
75    public string Description { get; private set; }
76    public string Separator { get; private set; }
77    public string FullName { get; private set; }
78
79    [StorableConstructor]
80    protected LayerDescriptor(StorableConstructorFlag _) : base(_) { }
81
82    protected LayerDescriptor(LayerDescriptor orig, Cloner cloner) : base(orig, cloner) { }
83
84    public LayerDescriptor(string name, string unit, string separator = " ") {
85      Name = name;
86      Unit = unit;
87      Separator = separator;
88      FullName = separator + name;
89    }
90
91    public string NameWithPrefix(string prefix) { return string.Format("{0}{1}", prefix, FullName); }
92    public bool IsSuffixOf(string s) { return s.EndsWith(FullName); }
93    public string RemoveSuffixFrom(string s) {
94      if (!s.EndsWith(FullName)) return s;
95      return s.Substring(0, s.Length - FullName.Length);
96    }
97
98    public override IDeepCloneable Clone(Cloner cloner) { return new LayerDescriptor(this, cloner); }
99
100    public static LayerDescriptor AmountsAtSource = new LayerDescriptor("amounts at source", "t/a");
101    public static LayerDescriptor AmountsAtTarget = new LayerDescriptor("amounts at target", "t/a");
102    public static LayerDescriptor AmountsTransportedFromSource = new LayerDescriptor("amounts transported from source", "t/a");
103    public static LayerDescriptor PotentialsFromProblemData = new LayerDescriptor("Potentials", "t/a", "");
104    public static LayerDescriptor Utilizations = new LayerDescriptor("Utilizations", "");
105    public static LayerDescriptor UtilizationsEffective = new LayerDescriptor("utilizations (effective)", "");
106    public static LayerDescriptor TransportTargets = new LayerDescriptor("Transport Targets", "region");
107    public static LayerDescriptor ConverterCapacities = new LayerDescriptor("converter capacities", "t/a");
108    public static LayerDescriptor StorageCapacities = new LayerDescriptor("storage capacities", "t/a");
109    public static LayerDescriptor AcquisitionCosts = new LayerDescriptor("acquisition costs", "€/a");
110    public static LayerDescriptor DischargeCosts = new LayerDescriptor("discharge costs", "€/a");
111    public static LayerDescriptor TransportCosts = new LayerDescriptor("transport costs", "€/a");
112    public static LayerDescriptor TransportCostsPerT = new LayerDescriptor("transport costs (per t)", "€/t");
113    public static LayerDescriptor TransportCostsPerTkm = new LayerDescriptor("transport costs (per tkm)", "€/tkm");
114    public static LayerDescriptor HandlingCosts = new LayerDescriptor("handling costs", "€/a");
115    public static LayerDescriptor RelativeHandlingCosts = new LayerDescriptor("handling costs (relative)", "€/t");
116    public static LayerDescriptor TransportModes = new LayerDescriptor("transport modes", "mode");
117    public static LayerDescriptor ConversionCosts = new LayerDescriptor("conversion costs", "€/a");
118    public static LayerDescriptor TotalAmortizedConversionCosts = new LayerDescriptor("total amortized conversion costs (incl. OPEX, CAPEX)", "€/a");
119    public static LayerDescriptor RelativeTotalAmortizedConversionCosts = new LayerDescriptor("total amortized conversion costs (incl. OPEX, CAPEX, relative)", "€/t");
120    public static LayerDescriptor ConversionPlantConstructionCost = new LayerDescriptor("conversion plant construction costs", "€/a");
121    public static LayerDescriptor ConversionPlantOperationCost = new LayerDescriptor("conversion plant operation costs", "€/a");
122    public static LayerDescriptor RelativeConversionCosts = new LayerDescriptor("conversion costs (relative)", "€/t");
123    public static LayerDescriptor RelativeConversionPlantConstructionCosts = new LayerDescriptor("conversion plant construction costs (relative)", "€/t");
124    public static LayerDescriptor RelativeConversionPlantOperationCosts = new LayerDescriptor("conversion plant operation costs (relative)", "€/t");
125    public static LayerDescriptor StorageCost = new LayerDescriptor("storage costs", "€/a");
126    public static LayerDescriptor RelativeStorageCost = new LayerDescriptor("storage costs (relative)", "€/t");
127    public static LayerDescriptor TransportDistance = new LayerDescriptor("transport distances", "km");
128    public static LayerDescriptor ExceedingTransportDistancePenalty = new LayerDescriptor("transport penalties", "");
129    public static LayerDescriptor Tkm = new LayerDescriptor("tkm", "tkm");
130    public static LayerDescriptor MaxConversionCapacity = new LayerDescriptor("converter capacities (max)", "t/a");
131    public static LayerDescriptor ScalingPenalty = new LayerDescriptor("converter scaling penalties", "");
132    public static LayerDescriptor TotalCostsAtTarget = new LayerDescriptor("total costs at target", "€/a");
133    public static LayerDescriptor TotalCostsAtSource = new LayerDescriptor("total costs at source", "€/a");
134    public static LayerDescriptor LocalAddedValue = new LayerDescriptor("local added value", "€/a", "");
135    public static LayerDescriptor RelativeCostAtSource = new LayerDescriptor("total costs at source (relative)", "€/t");
136    public static LayerDescriptor RelativeCostAtTarget = new LayerDescriptor("total costs at target (relative)", "€/t");
137    public static LayerDescriptor AmountsAtTargetConverted = new LayerDescriptor("amounts converted at target", "t/a");
138    public static LayerDescriptor TotalLogisticCosts = new LayerDescriptor("logistics costs", "€/a");
139    public static LayerDescriptor LogisticCostsPerTon = new LayerDescriptor("logistics costs (per t)", "€/t");
140    public static LayerDescriptor LogisticCostsPerTonKm = new LayerDescriptor("logistics costs (per tkm)", "€/tkm");
141    public static LayerDescriptor TotalDirectConversionCost = new LayerDescriptor("conversion costs (incl. supplies)", "€/a");
142    public static LayerDescriptor RelativeTotalDirectConversionCost = new LayerDescriptor("conversion costs (incl. supplies, relative)", "€/t");
143    public static LayerDescriptor TotalPenalty = new LayerDescriptor("total penalties", "", "");
144    public static LayerDescriptor Sources = new LayerDescriptor("conversion plant sources", "");
145    public static LayerDescriptor ScalingFactors = new LayerDescriptor("conversion plant scaling factors", "");
146    public static LayerDescriptor ExceedingCapacityPenalties = new LayerDescriptor("exceeding capacity penalties", "");
147
148    //public static LayerDescriptor AverageUtilizations = new LayerDescriptor("average utilizations", "t/a");
149    //public static LayerDescriptor AverageAmountsFromSource = new LayerDescriptor("average amounts from source", "t/a");
150    //public static LayerDescriptor AggregateAmountsFromSource = new LayerDescriptor("aggregate amounts from source", "t/a");
151    //public static LayerDescriptor AverageCostsFromSource = new LayerDescriptor("average costs from source", "t/a");
152    //public static LayerDescriptor AggregateCostsFromSource = new LayerDescriptor("aggregate costs from source", "t/a");
153
154    public static LayerDescriptor FeedstockCosts = new LayerDescriptor("feedstock costs", "€/a");
155    public static LayerDescriptor FeedstockCostsRelative = new LayerDescriptor("feedstock costs (relative)", "€/t");
156    //public static LayerDescriptor AggregatedAverageFeedstockCosts = new LayerDescriptor("aggregated average feedstock costs", "€/a");
157    //public static LayerDescriptor AggregatedFeedstockTransportCosts = new LayerDescriptor("aggregated feedstock transport costs", "€/a");
158    //public static LayerDescriptor RelativeAggregatedFeedstockTransportCosts = new LayerDescriptor("aggregated feedstock transport costs (relative)", "€/t");
159    //public static LayerDescriptor AggregatedFeedstockHandlingCosts = new LayerDescriptor("aggregated feedstock handling costs", "€/a");
160    //public static LayerDescriptor RelativeAggregatedFeedstockHandlingCosts = new LayerDescriptor("aggregated feedstock handling costs (relative)", "€/t");
161    //public static LayerDescriptor AggregatedFeedstockStorageCosts = new LayerDescriptor("aggregated feedstock storage costs", "€/a");
162    //public static LayerDescriptor RelativeAggregatedFeedstockStorageCosts = new LayerDescriptor("aggregated feedstock storage costs (relative)", "€/t");
163    public static LayerDescriptor DecentralLogisticCosts = new LayerDescriptor("logistic costs (decentral aggregated)", "€/a");
164    public static LayerDescriptor DecentralLogisticCostsRelative = new LayerDescriptor("logistic costs (decentral aggregated, relative)", "€/t");
165    //public static LayerDescriptor AggregatedDirectConversionCosts = new LayerDescriptor("aggregated direct conversion costs", "€/a");
166    //public static LayerDescriptor RelativeAggregatedDirectConversionCosts = new LayerDescriptor("aggregated direct conversion costs (relative)", "€/t");
167    //public static LayerDescriptor AggregatedConversionOperationCosts = new LayerDescriptor("aggregated conversion operation costs", "€/a");
168    //public static LayerDescriptor RelativeAggregatedConversionOperationCosts = new LayerDescriptor("aggregated conversion operation costs (relative)", "€/t");
169    //public static LayerDescriptor AggregatedConversionConstructionCosts = new LayerDescriptor("aggregated conversion construction costs", "€/a");
170    //public static LayerDescriptor RelativeAggregatedConversionConstructionCosts = new LayerDescriptor("aggregated conversion construction costs (relative)", "€/t");
171    public static LayerDescriptor DecentralConversionCosts = new LayerDescriptor("conversion costs (decentral aggregated)", "€/a");
172    public static LayerDescriptor DecentralConversionCostsRelative = new LayerDescriptor("conversion costs (decentral aggregated, relative)", "€/t");
173    public static LayerDescriptor CentralConversionCostsRelative = new LayerDescriptor("conversion costs (central aggregated, relative)", "€/t");
174    // ...
175    public static LayerDescriptor CentralLogisticCosts = new LayerDescriptor("logistic costs (central aggregated)", "€/a");
176    public static LayerDescriptor CentralLogisticCostsRelative = new LayerDescriptor("logistic costs (central aggregated, relative)", "€/t");
177
178    public static LayerDescriptor RoiFollowed = new LayerDescriptor("roi (followed)", "€/€");
179    public static LayerDescriptor RoiAggregated = new LayerDescriptor("roi (aggregated)", "€/€");
180
181
182
183    private static readonly List<LayerDescriptor> LAYERS = new List<LayerDescriptor>();
184
185    private static void DiscoverLayers() {
186      if (LAYERS.Count == 0) {
187        LAYERS.AddRange(
188          typeof(LayerDescriptor)
189            .GetFields(BindingFlags.Static | BindingFlags.Public)
190            .Select(f => f.GetValue(null))
191            .Where(v => v is LayerDescriptor)
192            .Cast<LayerDescriptor>()
193            .OrderByDescending(l => l.Name.Length));
194        foreach (var l1 in LAYERS) {
195          foreach (var l2 in LAYERS) {
196            if (l1 != l2 && l1.IsSuffixOf(l2.FullName))
197              throw new InvalidOperationException(string.Format("Layer overlap detected \"{0}\" is suffix of \"{1}\"", l1.FullName, l2.FullName));
198          }
199        }
200      }
201    }
202
203    public static IEnumerable<LayerDescriptor> Layers
204    {
205      get { DiscoverLayers(); return LAYERS; }
206    }
207
208    public static LayerDescriptor GetLayer(string fullName) {
209      DiscoverLayers();
210      foreach (var layer in LAYERS) {
211        if (layer.IsSuffixOf(fullName)) return layer;
212      }
213      return null;
214    }
215  }
216}
Note: See TracBrowser for help on using the repository browser.