#region License Information
/* HeuristicLab
* Copyright (C) 2002-2015 Heuristic and Evolutionary Algorithms Laboratory (HEAL)
*
* This file is part of HeuristicLab.
*
* HeuristicLab is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* HeuristicLab is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with HeuristicLab. If not, see .
*/
#endregion
using System;
using System.Collections.Generic;
using HeuristicLab.Common;
using HeuristicLab.Core;
using HeuristicLab.Data;
using HeuristicLab.Parameters;
using HeuristicLab.Persistence.Default.CompositeSerializers.Storable;
using HEAL.Attic;
namespace HeuristicLab.BioBoost.Data {
[StorableType("5604E9F0-F4C5-4C07-BE46-7895ED33A63E")]
[Item("Logistic", "Describes a logistic modality for a certain product.")]
public class Logistic : DataItem {
#region Parameters
public IValueParameter ModeParameter { get { return (IValueParameter)Parameters["Mode"]; } }
public IValueParameter ProductParameter { get { return (IValueParameter)Parameters["Product"]; } }
public IValueParameter DistancesParameter { get { return (IValueParameter)Parameters["Distances"]; } }
public IValueParameter TransportParameter { get { return (IValueParameter)Parameters["Transport"]; } }
public IValueParameter HandlingParameter { get { return (IValueParameter)Parameters["Handling"]; } }
public IValueParameter MinAmountParameter { get { return (IValueParameter)Parameters["MinAmount"]; } }
public IValueParameter MaxAmountParameter { get { return (IValueParameter)Parameters["MaxAmount"]; } }
public IValueParameter MaxDistanceParameter { get { return (IValueParameter)Parameters["MaxDistance"]; } }
public IValueParameter WaterContentParameter { get { return (IValueParameter)Parameters["WaterContent"]; } }
#endregion
#region Parameter Values
public string Mode { get { return ModeParameter.Value.Value; } }
public string Product { get { return ProductParameter.Value.Value; } }
public string Distances { get { return DistancesParameter.Value.Value; } }
public double MinAmount { get { return MinAmountParameter.Value.Value; } }
public double MaxAmount { get { return MaxAmountParameter.Value.Value; } }
public double MaxDistance { get { return MaxDistanceParameter.Value.Value; } }
public double WaterContent { get { return WaterContentParameter.Value.Value; } }
public LogisticAction Transport { get { return TransportParameter.Value; } }
public LogisticAction Handling { get { return HandlingParameter.Value; } }
#endregion
#region Construction & Cloning
public Logistic() {
Parameters.Add(new ValueParameter("Mode", "The logistic's mode."));
Parameters.Add(new ValueParameter("Product", "The logistic's transported product (from source to target)."));
Parameters.Add(new ValueParameter("Distances", "The distances matrix to be used."));
Parameters.Add(new ValueParameter("MinAmount", "The minimum amount per year to be transported (if any)", new DoubleValue(0)));
Parameters.Add(new ValueParameter("MaxAmount", "The maximum amount per year to be transported (if any)", new DoubleValue(Double.MaxValue)));
Parameters.Add(new ValueParameter("MaxDistance", "The maximum distance this logistic should cover", new DoubleValue(Double.MaxValue)));
Parameters.Add(new ValueParameter("WaterContent", "The amount of water considered in tranport/handling costs", new DoubleValue(0)));
Parameters.Add(new ValueParameter("Transport", "The single or compound transport cost per tkm."));
Parameters.Add(new ValueParameter("Handling", "The single or compound handling cost per t."));
RegisterEventHandlers();
}
[StorableConstructor]
protected Logistic(StorableConstructorFlag _) : base(_) { }
[StorableHook(HookType.AfterDeserialization)]
private void AfterDeserialization() {
if (!Parameters.ContainsKey("MinAmount"))
Parameters.Add(new ValueParameter("MinAmount", "The minimum amount per year to be transported (if any)", new DoubleValue(0)));
if (!Parameters.ContainsKey("MaxAmount"))
Parameters.Add(new ValueParameter("MaxAmount", "The maximum amount per year to be transported (if any)", new DoubleValue(Double.MaxValue)));
if (!Parameters.ContainsKey("MaxDistance"))
Parameters.Add(new ValueParameter("MaxDistance", "The maximum distance this logistic should cover", new DoubleValue(Double.MaxValue)));
if (!Parameters.ContainsKey("WaterContent"))
Parameters.Add(new ValueParameter("WaterContent", "The amount of water considered in tranport/handling costs", new DoubleValue(0)));
RegisterEventHandlers();
}
protected Logistic(Logistic orig, Cloner cloner)
: base(orig, cloner) {
RegisterEventHandlers();
}
public override IDeepCloneable Clone(Cloner cloner) {
return new Logistic(this, cloner);
}
#endregion
public override void CollectParameterValues(System.Collections.Generic.IDictionary values) {
var tmpDict = new Dictionary();
base.CollectParameterValues(tmpDict);
foreach (var entry in tmpDict) {
if (entry.Key == "Mode") continue;
if (entry.Key == "Product") continue;
values.Add("Logistics " + Product + "." + Mode + "." + entry.Key, entry.Value);
}
}
private void RegisterEventHandlers() {
// when the HL value is changed
ModeParameter.ValueChanged += (sender, args) => {
UpdateName();
ModeParameter.Value.ValueChanged += (s, a) => { UpdateName(); };
};
ProductParameter.ValueChanged += (sender, args) => {
UpdateName();
ProductParameter.Value.ValueChanged += (s, a) => { UpdateName(); };
};
// when the HL value's value is changed
ModeParameter.Value.ValueChanged += (sender, args) => { UpdateName(); };
ProductParameter.Value.ValueChanged += (sender, args) => { UpdateName(); };
}
private void UpdateName() {
this.Name = ItemName + ": " + Product + " (" + Mode + ")";
}
public override bool IsEquivalentTo(DataItem other) {
var l = other as Logistic;
if (l == null) return false;
return l.Mode == Mode && l.Product == Product;
}
}
}