Free cookie consent management tool by TermsFeed Policy Generator

source: branches/HeuristicLab.Problems.BioBoost/HeuristicLab.Problems.BioBoost/3.3/Representation/LayerDescriptor.cs @ 13071

Last change on this file since 13071 was 13071, checked in by gkronber, 9 years ago

#2499: added license headers and removed unused usings

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