1 | using System.Collections.Generic;
|
---|
2 | using System.Linq;
|
---|
3 | using HeuristicLab.Common;
|
---|
4 | using HeuristicLab.Core;
|
---|
5 | using HeuristicLab.Persistence.Default.CompositeSerializers.Storable;
|
---|
6 |
|
---|
7 | namespace HeuristicLab.Problems.GeneralizedQuadraticAssignment {
|
---|
8 | [Item("GQAP Evaluation", "Class that contains the results of evaluating a solution to the GQAP.")]
|
---|
9 | [StorableClass]
|
---|
10 | public class Evaluation : Item {
|
---|
11 |
|
---|
12 | /// <summary>
|
---|
13 | /// The solution is feasible if there is no excess demand
|
---|
14 | /// </summary>
|
---|
15 | public bool IsFeasible { get { return ExcessDemand <= double.Epsilon; } }
|
---|
16 |
|
---|
17 | /// <summary>
|
---|
18 | /// The amount of demand that exceeds the respective capacities
|
---|
19 | /// </summary>
|
---|
20 | [Storable]
|
---|
21 | public double ExcessDemand { get; private set; }
|
---|
22 | /// <summary>
|
---|
23 | /// The amount of slack at each location, is negative in case of excess demand.
|
---|
24 | /// </summary>
|
---|
25 | /// <remarks>
|
---|
26 | /// Slack.Select(x => x < 0 ? -x : 0).Sum() is equivalent to <see cref="ExcessDemand"/>.
|
---|
27 | /// </remarks>
|
---|
28 | [Storable]
|
---|
29 | private double[] slack;
|
---|
30 | public IReadOnlyList<double> Slack {
|
---|
31 | get { return slack; }
|
---|
32 | }
|
---|
33 | /// <summary>
|
---|
34 | /// The quadratic part of the fitness function that represents the flow or transportation costs.
|
---|
35 | /// </summary>
|
---|
36 | [Storable]
|
---|
37 | public double FlowCosts { get; private set; }
|
---|
38 | /// <summary>
|
---|
39 | /// The linear part of the fitness function that represents the installation costs.
|
---|
40 | /// </summary>
|
---|
41 | [Storable]
|
---|
42 | public double InstallationCosts { get; private set; }
|
---|
43 |
|
---|
44 | [StorableConstructor]
|
---|
45 | protected Evaluation(bool deserializing) : base(deserializing) { }
|
---|
46 | protected Evaluation(Evaluation original, Cloner cloner)
|
---|
47 | : base(original, cloner) {
|
---|
48 | ExcessDemand = original.ExcessDemand;
|
---|
49 | if (original.slack != null)
|
---|
50 | slack = original.slack.ToArray();
|
---|
51 | FlowCosts = original.FlowCosts;
|
---|
52 | InstallationCosts = original.InstallationCosts;
|
---|
53 | }
|
---|
54 | public Evaluation(double flowCosts, double installationCosts, double excessDemand, double[] slack) {
|
---|
55 | FlowCosts = flowCosts;
|
---|
56 | InstallationCosts = installationCosts;
|
---|
57 | ExcessDemand = excessDemand;
|
---|
58 | this.slack = slack;
|
---|
59 | }
|
---|
60 |
|
---|
61 | public override IDeepCloneable Clone(Cloner cloner) {
|
---|
62 | return new Evaluation(this, cloner);
|
---|
63 | }
|
---|
64 | }
|
---|
65 | }
|
---|