Free cookie consent management tool by TermsFeed Policy Generator

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