using System.Collections.Generic; using System.Linq; using HeuristicLab.Common; using HeuristicLab.Core; using HeuristicLab.Persistence.Default.CompositeSerializers.Storable; namespace HeuristicLab.Problems.GeneralizedQuadraticAssignment { [Item("GQAP Evaluation", "Class that contains the results of evaluating a solution to the GQAP.")] [StorableClass] public class Evaluation : Item { /// /// The solution is feasible if there is no excess demand /// public bool IsFeasible { get { return ExcessDemand <= double.Epsilon; } } /// /// The amount of demand that exceeds the respective capacities /// [Storable] public double ExcessDemand { get; private set; } /// /// The amount of slack at each location, is negative in case of excess demand. /// /// /// Slack.Select(x => x < 0 ? -x : 0).Sum() is equivalent to . /// [Storable] private double[] slack; public IReadOnlyList Slack { get { return slack; } } /// /// The quadratic part of the fitness function that represents the flow or transportation costs. /// [Storable] public double FlowCosts { get; private set; } /// /// The linear part of the fitness function that represents the installation costs. /// [Storable] public double InstallationCosts { get; private set; } [StorableConstructor] protected Evaluation(bool deserializing) : base(deserializing) { } protected Evaluation(Evaluation original, Cloner cloner) : base(original, cloner) { ExcessDemand = original.ExcessDemand; if (original.slack != null) slack = original.slack.ToArray(); FlowCosts = original.FlowCosts; InstallationCosts = original.InstallationCosts; } public Evaluation(double flowCosts, double installationCosts, double excessDemand, double[] slack) { FlowCosts = flowCosts; InstallationCosts = installationCosts; ExcessDemand = excessDemand; this.slack = slack; } public override IDeepCloneable Clone(Cloner cloner) { return new Evaluation(this, cloner); } } }