#region License Information
/* HeuristicLab
* Copyright (C) 2002-2010 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.Core;
using HeuristicLab.Data;
using HeuristicLab.Operators;
using HeuristicLab.Optimization;
using HeuristicLab.Parameters;
using HeuristicLab.Persistence.Default.CompositeSerializers.Storable;
using HeuristicLab.Encodings.SymbolicExpressionTreeEncoding;
namespace HeuristicLab.Problems.ArtificialAnt {
///
/// An operator for visualizing the best ant trail of an artificial ant problem.
///
[Item("BestAntTrailVisualizer", "An operator for visualizing the best ant trail of an artificial ant problem.")]
[StorableClass]
public sealed class BestAntTrailVisualizer : SingleSuccessorOperator, IAntTrailVisualizer {
public ILookupParameter> SymbolicExpressionTreeParameter {
get { return (ILookupParameter>)Parameters["SymbolicExpressionTree"]; }
}
public ILookupParameter> QualityParameter {
get { return (ILookupParameter>)Parameters["Quality"]; }
}
public ILookupParameter AntTrailParameter {
get { return (ILookupParameter)Parameters["AntTrail"]; }
}
ILookupParameter ISolutionsVisualizer.VisualizationParameter {
get { return AntTrailParameter; }
}
public BestAntTrailVisualizer()
: base() {
Parameters.Add(new LookupParameter("Coordinates", "The x- and y-Coordinates of the cities."));
Parameters.Add(new SubScopesLookupParameter("SymbolicExpressionTree", "The artificial ant solutions from which the best solution should be visualized."));
Parameters.Add(new SubScopesLookupParameter("Quality", "The qualities of the artificial ant solutions which should be visualized."));
Parameters.Add(new LookupParameter("AntTrail", "The visual representation of the best ant trail."));
}
public override IOperation Apply() {
ItemArray expressions = SymbolicExpressionTreeParameter.ActualValue;
ItemArray qualities = QualityParameter.ActualValue;
int i = qualities.Select((x, index) => new { index, x.Value }).OrderBy(x => -x.Value).First().index;
AntTrail antTrail = AntTrailParameter.ActualValue;
if (antTrail == null) AntTrailParameter.ActualValue = new AntTrail(expressions[i]);
else {
antTrail.SymbolicExpressionTree = expressions[i];
}
return base.Apply();
}
}
}