1 | #region License Information
|
---|
2 | /* HeuristicLab
|
---|
3 | * Copyright (C) 2002-2017 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 |
|
---|
22 | using System.Collections.Generic;
|
---|
23 | using System.Linq;
|
---|
24 | using HeuristicLab.Common;
|
---|
25 | using HeuristicLab.Core;
|
---|
26 | using HeuristicLab.Persistence.Default.CompositeSerializers.Storable;
|
---|
27 |
|
---|
28 | namespace HeuristicLab.Problems.GeneralizedQuadraticAssignment {
|
---|
29 | [Item("GQAP Evaluation", "Class that contains the results of evaluating a solution to the GQAP.")]
|
---|
30 | [StorableClass]
|
---|
31 | public class Evaluation : Item {
|
---|
32 |
|
---|
33 | /// <summary>
|
---|
34 | /// The solution is feasible if there is no excess demand
|
---|
35 | /// </summary>
|
---|
36 | public bool IsFeasible { get { return ExcessDemand <= double.Epsilon; } }
|
---|
37 |
|
---|
38 | /// <summary>
|
---|
39 | /// The amount of demand that exceeds the respective capacities
|
---|
40 | /// </summary>
|
---|
41 | [Storable]
|
---|
42 | public double ExcessDemand { get; private set; }
|
---|
43 | /// <summary>
|
---|
44 | /// The amount of slack at each location, is negative in case of excess demand.
|
---|
45 | /// </summary>
|
---|
46 | /// <remarks>
|
---|
47 | /// Slack.Select(x => x < 0 ? -x : 0).Sum() is equivalent to <see cref="ExcessDemand"/>.
|
---|
48 | /// </remarks>
|
---|
49 | [Storable]
|
---|
50 | private double[] slack;
|
---|
51 | public IReadOnlyList<double> Slack {
|
---|
52 | get { return slack; }
|
---|
53 | }
|
---|
54 | /// <summary>
|
---|
55 | /// The quadratic part of the fitness function that represents the flow or transportation costs.
|
---|
56 | /// </summary>
|
---|
57 | [Storable]
|
---|
58 | public double FlowCosts { get; private set; }
|
---|
59 | /// <summary>
|
---|
60 | /// The linear part of the fitness function that represents the installation costs.
|
---|
61 | /// </summary>
|
---|
62 | [Storable]
|
---|
63 | public double InstallationCosts { get; private set; }
|
---|
64 |
|
---|
65 | [StorableConstructor]
|
---|
66 | protected Evaluation(bool deserializing) : base(deserializing) { }
|
---|
67 | protected Evaluation(Evaluation original, Cloner cloner)
|
---|
68 | : base(original, cloner) {
|
---|
69 | ExcessDemand = original.ExcessDemand;
|
---|
70 | if (original.slack != null)
|
---|
71 | slack = original.slack.ToArray();
|
---|
72 | FlowCosts = original.FlowCosts;
|
---|
73 | InstallationCosts = original.InstallationCosts;
|
---|
74 | }
|
---|
75 | public Evaluation(double flowCosts, double installationCosts, double excessDemand, double[] slack) {
|
---|
76 | FlowCosts = flowCosts;
|
---|
77 | InstallationCosts = installationCosts;
|
---|
78 | ExcessDemand = excessDemand;
|
---|
79 | this.slack = slack;
|
---|
80 | }
|
---|
81 |
|
---|
82 | public override IDeepCloneable Clone(Cloner cloner) {
|
---|
83 | return new Evaluation(this, cloner);
|
---|
84 | }
|
---|
85 | }
|
---|
86 | }
|
---|