#region License Information
/* HeuristicLab
* Copyright (C) 2002-2012 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 HeuristicLab.Analysis;
using HeuristicLab.Common;
using HeuristicLab.Core;
using HeuristicLab.Data;
using HeuristicLab.Encodings.IntegerVectorEncoding;
using HeuristicLab.Parameters;
using HeuristicLab.Persistence.Default.CompositeSerializers.Storable;
using HeuristicLab.Problems.GeneralizedQuadraticAssignment.Common;
namespace HeuristicLab.Problems.GeneralizedQuadraticAssignment.Analyzers {
[Item("GQAPPopulationDiversityAnalyzer", "Analyzes the population diversity.")]
[StorableClass]
public class GQAPPopulationDiversityAnalyzer : PopulationDiversityAnalyzer, IAssignmentsAwareGQAPOperator, IQualitiesAwareGQAPOperator {
public IScopeTreeLookupParameter AssignmentParameter {
get { return SolutionParameter; }
}
public new ILookupParameter MaximizationParameter {
get { return base.MaximizationParameter; }
}
public new IScopeTreeLookupParameter QualityParameter {
get { return base.QualityParameter; }
}
public IScopeTreeLookupParameter FlowDistanceQualityParameter {
get { return (IScopeTreeLookupParameter)Parameters["FlowDistanceQuality"]; }
}
public IScopeTreeLookupParameter InstallationQualityParameter {
get { return (IScopeTreeLookupParameter)Parameters["InstallationQuality"]; }
}
public IScopeTreeLookupParameter OverbookedCapacityParameter {
get { return (IScopeTreeLookupParameter)Parameters["OverbookedCapacity"]; }
}
[StorableConstructor]
protected GQAPPopulationDiversityAnalyzer(bool deserializing) : base(deserializing) { }
protected GQAPPopulationDiversityAnalyzer(GQAPPopulationDiversityAnalyzer original, Cloner cloner) : base(original, cloner) { }
public GQAPPopulationDiversityAnalyzer()
: base() {
Parameters.Add(new ScopeTreeLookupParameter("FlowDistanceQuality", GQAPEvaluator.FlowDistanceQualityDescription));
Parameters.Add(new ScopeTreeLookupParameter("InstallationQuality", GQAPEvaluator.InstallationQualityDescription));
Parameters.Add(new ScopeTreeLookupParameter("OverbookedCapacity", GQAPEvaluator.OverbookedCapacityDescription));
}
public override IDeepCloneable Clone(Cloner cloner) {
return new GQAPPopulationDiversityAnalyzer(this, cloner);
}
protected override double[,] CalculateSimilarities(IntegerVector[] solutions) {
double[,] result = new double[solutions.Length, solutions.Length];
for (int i = 0; i < solutions.Length - 1; i++)
for (int j = i + 1; j < solutions.Length; j++) {
result[i, j] = IntegerVectorEqualityComparer.GetSimilarity(solutions[i], solutions[j]);
result[j, i] = result[i, j];
}
return result;
}
}
}