source: branches/HeuristicLab.Problems.BioBoost/HeuristicLab.Problems.BioBoost/3.3/Data/Logistic.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: 6.3 KB
Line 
1using System;
2using System.Collections.Generic;
3using HeuristicLab.Common;
4using HeuristicLab.Core;
5using HeuristicLab.Data;
6using HeuristicLab.Parameters;
7using HeuristicLab.Persistence.Default.CompositeSerializers.Storable;
8
9namespace HeuristicLab.BioBoost.Data {
10  [StorableClass]
11  [Item("Logistic", "Describes a logistic modality for a certain product.")]
12  public class Logistic : DataItem {
13
14    #region Parameters
15    public IValueParameter<StringValue> ModeParameter { get { return (IValueParameter<StringValue>)Parameters["Mode"]; } }
16    public IValueParameter<StringValue> ProductParameter { get { return (IValueParameter<StringValue>)Parameters["Product"]; } }
17    public IValueParameter<StringValue> DistancesParameter { get { return (IValueParameter<StringValue>)Parameters["Distances"]; } }
18    public IValueParameter<LogisticAction> TransportParameter { get { return (IValueParameter<LogisticAction>)Parameters["Transport"]; } }
19    public IValueParameter<LogisticAction> HandlingParameter { get { return (IValueParameter<LogisticAction>)Parameters["Handling"]; } }
20    public IValueParameter<DoubleValue> MinAmountParameter { get { return (IValueParameter<DoubleValue>)Parameters["MinAmount"]; } }
21    public IValueParameter<DoubleValue> MaxAmountParameter { get { return (IValueParameter<DoubleValue>)Parameters["MaxAmount"]; } }
22    public IValueParameter<DoubleValue> MaxDistanceParameter { get { return (IValueParameter<DoubleValue>)Parameters["MaxDistance"]; } }
23    public IValueParameter<DoubleValue> WaterContentParameter { get { return (IValueParameter<DoubleValue>)Parameters["WaterContent"]; } }
24    #endregion
25
26    #region Parameter Values
27    public string Mode { get { return ModeParameter.Value.Value; } }
28    public string Product { get { return ProductParameter.Value.Value; } }
29    public string Distances { get { return DistancesParameter.Value.Value; } }
30    public double MinAmount { get { return MinAmountParameter.Value.Value; } }
31    public double MaxAmount { get { return MaxAmountParameter.Value.Value; } }
32    public double MaxDistance { get { return MaxDistanceParameter.Value.Value; } }
33    public double WaterContent { get { return WaterContentParameter.Value.Value; } }
34    public LogisticAction Transport { get { return TransportParameter.Value; } }
35    public LogisticAction Handling { get { return HandlingParameter.Value; } }
36    #endregion
37
38    #region Construction & Cloning
39    public Logistic() {
40      Parameters.Add(new ValueParameter<StringValue>("Mode", "The logistic's mode."));
41      Parameters.Add(new ValueParameter<StringValue>("Product", "The logistic's transported product (from source to target)."));
42      Parameters.Add(new ValueParameter<StringValue>("Distances", "The distances matrix to be used."));
43      Parameters.Add(new ValueParameter<DoubleValue>("MinAmount", "The minimum amount per year to be transported (if any)", new DoubleValue(0)));
44      Parameters.Add(new ValueParameter<DoubleValue>("MaxAmount", "The maximum amount per year to be transported (if any)", new DoubleValue(Double.MaxValue)));
45      Parameters.Add(new ValueParameter<DoubleValue>("MaxDistance", "The maximum distance this logistic should cover", new DoubleValue(Double.MaxValue)));
46      Parameters.Add(new ValueParameter<DoubleValue>("WaterContent", "The amount of water considered in tranport/handling costs", new DoubleValue(0)));
47      Parameters.Add(new ValueParameter<LogisticAction>("Transport", "The single or compound transport cost per tkm."));
48      Parameters.Add(new ValueParameter<LogisticAction>("Handling", "The single or compound handling cost per t."));
49
50      RegisterEventHandlers();
51    }
52
53    [StorableConstructor]
54    protected Logistic(bool isDeserializing) : base(isDeserializing) { }
55
56    [StorableHook(HookType.AfterDeserialization)]
57    private void AfterDeserialization() {
58      if (!Parameters.ContainsKey("MinAmount"))
59        Parameters.Add(new ValueParameter<DoubleValue>("MinAmount", "The minimum amount per year to be transported (if any)", new DoubleValue(0)));
60      if (!Parameters.ContainsKey("MaxAmount"))
61        Parameters.Add(new ValueParameter<DoubleValue>("MaxAmount", "The maximum amount per year to be transported (if any)", new DoubleValue(Double.MaxValue)));
62      if (!Parameters.ContainsKey("MaxDistance"))
63        Parameters.Add(new ValueParameter<DoubleValue>("MaxDistance", "The maximum distance this logistic should cover", new DoubleValue(Double.MaxValue)));
64      if (!Parameters.ContainsKey("WaterContent"))
65        Parameters.Add(new ValueParameter<DoubleValue>("WaterContent", "The amount of water considered in tranport/handling costs", new DoubleValue(0)));
66      RegisterEventHandlers();
67    }
68
69    protected Logistic(Logistic orig, Cloner cloner)
70      : base(orig, cloner) {
71      RegisterEventHandlers();
72    }
73
74    public override IDeepCloneable Clone(Cloner cloner) {
75      return new Logistic(this, cloner);
76    }
77    #endregion
78
79    public override void CollectParameterValues(System.Collections.Generic.IDictionary<string, IItem> values) {
80      var tmpDict = new Dictionary<string, IItem>();
81      base.CollectParameterValues(tmpDict);
82      foreach (var entry in tmpDict) {
83        if (entry.Key == "Mode") continue;
84        if (entry.Key == "Product") continue;
85        values.Add("Logistics " + Product + "." + Mode + "." + entry.Key, entry.Value);
86      }
87    }
88
89    private void RegisterEventHandlers() {
90      // when the HL value is changed
91      ModeParameter.ValueChanged += (sender, args) => {
92        UpdateName();
93        ModeParameter.Value.ValueChanged += (s, a) => { UpdateName(); };
94      };
95      ProductParameter.ValueChanged += (sender, args) => {
96        UpdateName();
97        ProductParameter.Value.ValueChanged += (s, a) => { UpdateName(); };
98      };
99      // when the HL value's value is changed
100      ModeParameter.Value.ValueChanged += (sender, args) => { UpdateName(); };
101      ProductParameter.Value.ValueChanged += (sender, args) => { UpdateName(); };
102    }
103
104    private void UpdateName() {
105      this.Name = ItemName + ": " + Product + " (" + Mode + ")";
106    }
107
108    public override bool IsEquivalentTo(DataItem other) {
109      var l = other as Logistic;
110      if (l == null) return false;
111      return l.Mode == Mode && l.Product == Product;
112    }
113  }
114}
Note: See TracBrowser for help on using the repository browser.