#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 System.Linq; using HeuristicLab.Common; using HeuristicLab.Core; using HeuristicLab.Data; using HeuristicLab.Encodings.IntegerVectorEncoding; using HeuristicLab.Operators; using HeuristicLab.Optimization; using HeuristicLab.Parameters; using HeuristicLab.Persistence.Default.CompositeSerializers.Storable; namespace HeuristicLab.Problems.GeneralizedQuadraticAssignment { /// /// An operator for analyzing the best solution of Generalized Quadratic Assignment Problems. /// [Item("GeneralizedQAP Solution Archive Analyzer", "An operator for analyzing the archive of found solutions for the GQAP.")] [StorableClass] public sealed class GQAPSolutionArchiveAnalyzer : SingleSuccessorOperator, IAssignmentsAwareGQAPOperator, IQualitiesAwareGQAPOperator, IDistancesAwareGQAPOperator, IWeightsAwareGQAPOperator, IInstallationCostsAwareGQAPOperator, IDemandsAwareGQAPOperator, ICapacitiesAwareGQAPOperator, ITransportationCostsAwareGQAPOperator, IExpectedRandomQualityAwareGQAPOperator, IEquipmentNamesAwareGQAPOperator, ILocationNamesAwareGQAPOperator, IBestKnownSolutionsAwareGQAPOperator, IEvaluatorAwareGQAPOperator, IAnalyzer { public bool EnabledByDefault { get { return true; } } public IScopeTreeLookupParameter AssignmentParameter { get { return (IScopeTreeLookupParameter)Parameters["Assignment"]; } } public ILookupParameter MaximizationParameter { get { return (ILookupParameter)Parameters["Maximization"]; } } public IScopeTreeLookupParameter QualityParameter { get { return (IScopeTreeLookupParameter)Parameters["Quality"]; } } public IScopeTreeLookupParameter FlowDistanceQualityParameter { get { return (IScopeTreeLookupParameter)Parameters["FlowDistanceQuality"]; } } public IScopeTreeLookupParameter InstallationQualityParameter { get { return (IScopeTreeLookupParameter)Parameters["InstallationQuality"]; } } public IScopeTreeLookupParameter OverbookedCapacityParameter { get { return (IScopeTreeLookupParameter)Parameters["OverbookedCapacity"]; } } public ILookupParameter DistancesParameter { get { return (ILookupParameter)Parameters["Distances"]; } } public ILookupParameter WeightsParameter { get { return (ILookupParameter)Parameters["Weights"]; } } public ILookupParameter InstallationCostsParameter { get { return (ILookupParameter)Parameters["InstallationCosts"]; } } public ILookupParameter DemandsParameter { get { return (ILookupParameter)Parameters["Demands"]; } } public ILookupParameter CapacitiesParameter { get { return (ILookupParameter)Parameters["Capacities"]; } } public IValueLookupParameter TransportationCostsParameter { get { return (IValueLookupParameter)Parameters["TransportationCosts"]; } } public IValueLookupParameter ExpectedRandomQualityParameter { get { return (IValueLookupParameter)Parameters["ExpectedRandomQuality"]; } } public ILookupParameter EquipmentNamesParameter { get { return (ILookupParameter)Parameters["EquipmentNames"]; } } public ILookupParameter LocationNamesParameter { get { return (ILookupParameter)Parameters["LocationNames"]; } } public IValueLookupParameter ResultsParameter { get { return (IValueLookupParameter)Parameters["Results"]; } } public ILookupParameter BestKnownSolutionsParameter { get { return (ILookupParameter)Parameters["BestKnownSolutions"]; } } public IValueLookupParameter EvaluatorParameter { get { return (IValueLookupParameter)Parameters["Evaluator"]; } } [StorableConstructor] private GQAPSolutionArchiveAnalyzer(bool deserializing) : base(deserializing) { } private GQAPSolutionArchiveAnalyzer(GQAPSolutionArchiveAnalyzer original, Cloner cloner) : base(original, cloner) { } public override IDeepCloneable Clone(Cloner cloner) { return new GQAPSolutionArchiveAnalyzer(this, cloner); } public GQAPSolutionArchiveAnalyzer() : base() { Parameters.Add(new LookupParameter("Maximization", GeneralizedQuadraticAssignmentProblem.MaximizationDescription)); Parameters.Add(new LookupParameter("Distances", GeneralizedQuadraticAssignmentProblem.DistancesDescription)); Parameters.Add(new LookupParameter("Weights", GeneralizedQuadraticAssignmentProblem.WeightsDescription)); Parameters.Add(new LookupParameter("InstallationCosts", GeneralizedQuadraticAssignmentProblem.InstallationCostsDescription)); Parameters.Add(new LookupParameter("Demands", GeneralizedQuadraticAssignmentProblem.DemandsDescription)); Parameters.Add(new LookupParameter("Capacities", GeneralizedQuadraticAssignmentProblem.CapacitiesDescription)); Parameters.Add(new ValueLookupParameter("TransportationCosts", GeneralizedQuadraticAssignmentProblem.TransportationCostsDescription)); Parameters.Add(new ValueLookupParameter("ExpectedRandomQuality", GeneralizedQuadraticAssignmentProblem.ExpectedRandomQualityDescription)); Parameters.Add(new ScopeTreeLookupParameter("Assignment", GQAPSolutionCreator.AssignmentDescription)); Parameters.Add(new ScopeTreeLookupParameter("Quality", GQAPEvaluator.QualityDescription)); Parameters.Add(new ScopeTreeLookupParameter("FlowDistanceQuality", GQAPEvaluator.FlowDistanceQualityDescription)); Parameters.Add(new ScopeTreeLookupParameter("InstallationQuality", GQAPEvaluator.InstallationQualityDescription)); Parameters.Add(new ScopeTreeLookupParameter("OverbookedCapacity", GQAPEvaluator.OverbookedCapacityDescription)); Parameters.Add(new LookupParameter("EquipmentNames", GeneralizedQuadraticAssignmentProblem.EquipmentNamesDescription)); Parameters.Add(new LookupParameter("LocationNames", GeneralizedQuadraticAssignmentProblem.LocationNamesDescription)); Parameters.Add(new ValueLookupParameter("Results", "The result collection where the best GQAP solution should be stored.")); Parameters.Add(new LookupParameter("BestKnownSolutions", GeneralizedQuadraticAssignmentProblem.BestKnownSolutionsDescription)); Parameters.Add(new ValueLookupParameter("Evaluator", "The evaluator that is used to evaluate GQAP solutions.")); } public override IOperation Apply() { var evaluator = EvaluatorParameter.ActualValue; var assignments = AssignmentParameter.ActualValue; var qualities = QualityParameter.ActualValue; var equipmentNames = EquipmentNamesParameter.ActualValue; var locationNames = LocationNamesParameter.ActualValue; var flowDistanceQualities = FlowDistanceQualityParameter.ActualValue; var installationQualities = InstallationQualityParameter.ActualValue; var overbookedCapacities = OverbookedCapacityParameter.ActualValue; var distances = DistancesParameter.ActualValue; var weights = WeightsParameter.ActualValue; var installationCosts = InstallationCostsParameter.ActualValue; var demands = DemandsParameter.ActualValue; var capacities = CapacitiesParameter.ActualValue; var transportationCosts = TransportationCostsParameter.ActualValue; var expectedRandomQuality = ExpectedRandomQualityParameter.ActualValue; var results = ResultsParameter.ActualValue; var maximization = MaximizationParameter.ActualValue.Value; GQAPAssignmentArchive archive = results.ContainsKey("Solution Archive") ? results["Solution Archive"].Value as GQAPAssignmentArchive : null; if (archive == null) { archive = new GQAPAssignmentArchive(equipmentNames, locationNames, distances, weights, installationCosts, demands, capacities, transportationCosts, expectedRandomQuality, evaluator); results.Add(new Result("Solution Archive", archive)); } else { archive.EquipmentNames = equipmentNames; archive.LocationNames = locationNames; archive.Distances = distances; archive.Weights = weights; archive.InstallationCosts = installationCosts; archive.Demands = demands; archive.Capacities = capacities; archive.TransportationCosts = transportationCosts; archive.ExpectedRandomQuality = expectedRandomQuality; archive.Evaluator = evaluator; } var solutions = Enumerable.Range(0, assignments.Length) .Select(i => new GQAPSolution(assignments[i], qualities[i], flowDistanceQualities[i], installationQualities[i], overbookedCapacities[i])) .Concat(archive.Solutions); archive.Solutions = GQAPSolutionArchiveUpdater.GetFeasibleParetoFront(solutions); GQAPAssignmentArchive bestKnownArchive = BestKnownSolutionsParameter.ActualValue; if (bestKnownArchive == null) { bestKnownArchive = new GQAPAssignmentArchive(); BestKnownSolutionsParameter.ActualValue = bestKnownArchive; } else { var archiveSolutions = Enumerable.Range(0, assignments.Length) .Select(i => new GQAPSolution(assignments[i], qualities[i], flowDistanceQualities[i], installationQualities[i], overbookedCapacities[i])) .Concat(archive.Solutions); bestKnownArchive.Solutions = GQAPSolutionArchiveUpdater.GetFeasibleParetoFront(archiveSolutions); } return base.Apply(); } } }