Free cookie consent management tool by TermsFeed Policy Generator

Changeset 3107


Ignore:
Timestamp:
03/19/10 04:56:06 (15 years ago)
Author:
swagner
Message:

Continued to implement TSP tour visualization (#924)

Location:
trunk/sources
Files:
5 added
4 deleted
11 edited
5 moved

Legend:

Unmodified
Added
Removed
  • trunk/sources/HeuristicLab.Algorithms.SGA/3.3/SGA.cs

    r3095 r3107  
    183183      ParameterizeStochasticOperator(Problem.SolutionCreator);
    184184      ParameterizeStochasticOperator(Problem.Evaluator);
     185      ParameterizeStochasticOperator(Problem.Visualizer);
    185186      foreach (IOperator op in Problem.Operators) ParameterizeStochasticOperator(op);
    186187      ParameterizeSolutionsCreator();
     
    204205      Problem.Evaluator.QualityParameter.ActualNameChanged += new EventHandler(Evaluator_QualityParameter_ActualNameChanged);
    205206      base.Problem_EvaluatorChanged(sender, e);
     207    }
     208    protected override void Problem_VisualizerChanged(object sender, EventArgs e) {
     209      ParameterizeStochasticOperator(Problem.Visualizer);
     210      ParameterizeSGAMainLoop();
     211      base.Problem_VisualizerChanged(sender, e);
    206212    }
    207213    protected override void Problem_OperatorsChanged(object sender, EventArgs e) {
     
    253259      SGAMainLoop.MaximizationParameter.ActualName = Problem.MaximizationParameter.Name;
    254260      SGAMainLoop.QualityParameter.ActualName = Problem.Evaluator.QualityParameter.ActualName;
     261      SGAMainLoop.VisualizerParameter.ActualName = Problem.VisualizerParameter.Name;
     262      SGAMainLoop.VisualizationParameter.ActualName = Problem.Visualizer.VisualizationParameter.ActualName;
    255263    }
    256264    private void ParameterizeStochasticOperator(IOperator op) {
  • trunk/sources/HeuristicLab.Algorithms.SGA/3.3/SGAMainLoop.cs

    r3096 r3107  
    7474      get { return (ValueLookupParameter<VariableCollection>)Parameters["Results"]; }
    7575    }
     76    public ValueLookupParameter<IOperator> VisualizerParameter {
     77      get { return (ValueLookupParameter<IOperator>)Parameters["Visualizer"]; }
     78    }
     79    public LookupParameter<IItem> VisualizationParameter {
     80      get { return (LookupParameter<IItem>)Parameters["Visualization"]; }
     81    }
    7682    private ScopeParameter CurrentScopeParameter {
    7783      get { return (ScopeParameter)Parameters["CurrentScope"]; }
     
    104110      Parameters.Add(new ValueLookupParameter<IntValue>("MaximumGenerations", "The maximum number of generations which should be processed."));
    105111      Parameters.Add(new ValueLookupParameter<VariableCollection>("Results", "The variable collection where results should be stored."));
     112      Parameters.Add(new ValueLookupParameter<IOperator>("Visualizer", "The operator used to visualize solutions."));
     113      Parameters.Add(new LookupParameter<IItem>("Visualization", "The item which represents the visualization of solutions."));
    106114      Parameters.Add(new ScopeParameter("CurrentScope", "The current scope which represents a population of solutions on which the SGA should be applied."));
    107115      #endregion
     
    114122      DataTableValuesCollector dataTableValuesCollector1 = new DataTableValuesCollector();
    115123      QualityDifferenceCalculator qualityDifferenceCalculator1 = new QualityDifferenceCalculator();
     124      Placeholder visualizer1 = new Placeholder();
    116125      ResultsCollector resultsCollector = new ResultsCollector();
    117126      Placeholder selector = new Placeholder();
     
    135144      DataTableValuesCollector dataTableValuesCollector2 = new DataTableValuesCollector();
    136145      QualityDifferenceCalculator qualityDifferenceCalculator2 = new QualityDifferenceCalculator();
     146      Placeholder visualizer2 = new Placeholder();
    137147      ConditionalBranch conditionalBranch = new ConditionalBranch();
    138148
     
    164174      qualityDifferenceCalculator1.RelativeDifferenceParameter.ActualName = "RelativeDifferenceBestKnownToBest";
    165175      qualityDifferenceCalculator1.SecondQualityParameter.ActualName = "BestQuality";
     176
     177      visualizer1.Name = "Visualizer";
     178      visualizer1.OperatorParameter.ActualName = "Visualizer";
    166179
    167180      resultsCollector.CollectedValues.Add(new LookupParameter<IntValue>("Generations"));
     
    173186      resultsCollector.CollectedValues.Add(new LookupParameter<DoubleValue>("Absolute Difference of Best Known Quality to Best Quality", null, "AbsoluteDifferenceBestKnownToBest"));
    174187      resultsCollector.CollectedValues.Add(new LookupParameter<DoubleValue>("Relative Difference of Best Known Quality to Best Quality", null, "RelativeDifferenceBestKnownToBest"));
     188      resultsCollector.CollectedValues.Add(new LookupParameter<IItem>("Solution Visualization", null, "Visualization"));
    175189      resultsCollector.CollectedValues.Add(new LookupParameter<DataTable>("Qualities"));
    176190      resultsCollector.ResultsParameter.ActualName = "Results";
     
    233247      qualityDifferenceCalculator2.RelativeDifferenceParameter.ActualName = "RelativeDifferenceBestKnownToBest";
    234248      qualityDifferenceCalculator2.SecondQualityParameter.ActualName = "BestQuality";
     249
     250      visualizer2.Name = "Visualizer";
     251      visualizer2.OperatorParameter.ActualName = "Visualizer";
    235252
    236253      conditionalBranch.ConditionParameter.ActualName = "Terminate";
     
    244261      bestAverageWorstQualityCalculator1.Successor = dataTableValuesCollector1;
    245262      dataTableValuesCollector1.Successor = qualityDifferenceCalculator1;
    246       qualityDifferenceCalculator1.Successor = resultsCollector;
     263      qualityDifferenceCalculator1.Successor = visualizer1;
     264      visualizer1.Successor = resultsCollector;
    247265      resultsCollector.Successor = selector;
    248266      selector.Successor = sequentialSubScopesProcessor1;
     
    272290      bestAverageWorstQualityCalculator2.Successor = dataTableValuesCollector2;
    273291      dataTableValuesCollector2.Successor = qualityDifferenceCalculator2;
    274       qualityDifferenceCalculator2.Successor = conditionalBranch;
     292      qualityDifferenceCalculator2.Successor = visualizer2;
     293      visualizer2.Successor = conditionalBranch;
    275294      conditionalBranch.FalseBranch = selector;
    276295      conditionalBranch.TrueBranch = null;
  • trunk/sources/HeuristicLab.Optimization/3.3/Algorithm.cs

    r3017 r3107  
    152152      problem.SolutionCreatorChanged -= new EventHandler(Problem_SolutionCreatorChanged);
    153153      problem.EvaluatorChanged -= new EventHandler(Problem_EvaluatorChanged);
     154      problem.VisualizerChanged -= new EventHandler(Problem_VisualizerChanged);
    154155      problem.OperatorsChanged -= new EventHandler(Problem_OperatorsChanged);
    155156    }
     
    157158      problem.SolutionCreatorChanged += new EventHandler(Problem_SolutionCreatorChanged);
    158159      problem.EvaluatorChanged += new EventHandler(Problem_EvaluatorChanged);
     160      problem.VisualizerChanged += new EventHandler(Problem_VisualizerChanged);
    159161      problem.OperatorsChanged += new EventHandler(Problem_OperatorsChanged);
    160162    }
     
    162164    protected virtual void Problem_SolutionCreatorChanged(object sender, EventArgs e) { }
    163165    protected virtual void Problem_EvaluatorChanged(object sender, EventArgs e) { }
     166    protected virtual void Problem_VisualizerChanged(object sender, EventArgs e) { }
    164167    protected virtual void Problem_OperatorsChanged(object sender, EventArgs e) { }
    165168    #endregion
  • trunk/sources/HeuristicLab.Optimization/3.3/HeuristicLab.Optimization-3.3.csproj

    r3104 r3107  
    8686    <None Include="HeuristicLabOptimizationPlugin.cs.frame" />
    8787    <Compile Include="Algorithm.cs" />
    88     <Compile Include="Interfaces\ISolutionVisualizer.cs" />
     88    <Compile Include="Interfaces\IMultiObjectiveSolutionsVisualizer.cs" />
     89    <Compile Include="Interfaces\ISingleObjectiveSolutionsVisualizer.cs" />
     90    <Compile Include="Interfaces\ISolutionsVisualizer.cs" />
    8991    <Compile Include="Interfaces\IDiscreteDoubleValueModifier.cs" />
    9092    <Compile Include="Interfaces\IExhaustiveMoveGenerator.cs" />
  • trunk/sources/HeuristicLab.Optimization/3.3/Interfaces/IProblem.cs

    r2975 r3107  
    3333    IParameter EvaluatorParameter { get; }
    3434    IEvaluator Evaluator { get; }
     35    IParameter VisualizerParameter { get; }
     36    ISolutionsVisualizer Visualizer { get; }
    3537    IEnumerable<IOperator> Operators { get; }
    3638
    3739    event EventHandler SolutionCreatorChanged;
    3840    event EventHandler EvaluatorChanged;
     41    event EventHandler VisualizerChanged;
    3942    event EventHandler OperatorsChanged;
    4043  }
  • trunk/sources/HeuristicLab.Optimization/3.3/Interfaces/ISolutionsVisualizer.cs

    r3106 r3107  
    2626  /// An interface which represents an operator for visualizing solutions.
    2727  /// </summary>
    28   public interface ISolutionVisualizer : IOperator {
    29     ILookupParameter<IItem> VisualizationParameter { get; }
     28  public interface ISolutionsVisualizer : IOperator {
     29    ILookupParameter VisualizationParameter { get; }
    3030  }
    3131}
  • trunk/sources/HeuristicLab.Problems.Knapsack/3.3/Knapsack.cs

    r3080 r3107  
    7373      get { return EvaluatorParameter; }
    7474    }
     75    IParameter IProblem.VisualizerParameter {
     76      get { throw new NotImplementedException(); }
     77    }
    7578    public OptionalValueParameter<DoubleValue> BestKnownQualityParameter {
    7679      get { return (OptionalValueParameter<DoubleValue>)Parameters["BestKnownQuality"]; }
     
    98101    IEvaluator IProblem.Evaluator {
    99102      get { return EvaluatorParameter.Value; }
     103    }
     104    ISolutionsVisualizer IProblem.Visualizer {
     105      get { throw new NotImplementedException(); }
    100106    }
    101107    public DoubleValue BestKnownQuality {
     
    153159        EvaluatorChanged(this, EventArgs.Empty);
    154160    }
     161    public event EventHandler VisualizerChanged;
    155162    public event EventHandler OperatorsChanged;
    156163    private void OnOperatorsChanged() {
  • trunk/sources/HeuristicLab.Problems.OneMax/3.3/Onemax.cs

    r3080 r3107  
    6464      get { return EvaluatorParameter; }
    6565    }
     66    IParameter IProblem.VisualizerParameter {
     67      get { throw new NotImplementedException(); }
     68    }
    6669    public ValueParameter<DoubleValue> BestKnownQualityParameter {
    6770      get { return (ValueParameter<DoubleValue>)Parameters["BestKnownQuality"]; }
     
    8992    IEvaluator IProblem.Evaluator {
    9093      get { return EvaluatorParameter.Value; }
     94    }
     95    ISolutionsVisualizer IProblem.Visualizer {
     96      get { throw new NotImplementedException(); }
    9197    }
    9298    public DoubleValue BestKnownQuality {
     
    138144        EvaluatorChanged(this, EventArgs.Empty);
    139145    }
     146    public event EventHandler VisualizerChanged;
    140147    public event EventHandler OperatorsChanged;
    141148    private void OnOperatorsChanged() {
  • trunk/sources/HeuristicLab.Problems.TSP.Views/3.3/HeuristicLab.Problems.TSP.Views-3.3.csproj

    r2900 r3107  
    8585  </ItemGroup>
    8686  <ItemGroup>
     87    <Compile Include="PathTSPTourView.cs">
     88      <SubType>UserControl</SubType>
     89    </Compile>
     90    <Compile Include="PathTSPTourView.Designer.cs">
     91      <DependentUpon>PathTSPTourView.cs</DependentUpon>
     92    </Compile>
    8793    <Compile Include="HeuristicLabProblemsTSPViewsPlugin.cs" />
    8894    <Compile Include="TSPView.cs">
     
    111117      <Project>{C36BD924-A541-4A00-AFA8-41701378DDC5}</Project>
    112118      <Name>HeuristicLab.Core-3.3</Name>
     119    </ProjectReference>
     120    <ProjectReference Include="..\..\HeuristicLab.Data\3.3\HeuristicLab.Data-3.3.csproj">
     121      <Project>{BBAB9DF5-5EF3-4BA8-ADE9-B36E82114937}</Project>
     122      <Name>HeuristicLab.Data-3.3</Name>
     123    </ProjectReference>
     124    <ProjectReference Include="..\..\HeuristicLab.Encodings.PermutationEncoding\3.3\HeuristicLab.Encodings.PermutationEncoding-3.3.csproj">
     125      <Project>{DBECB8B0-B166-4133-BAF1-ED67C3FD7FCA}</Project>
     126      <Name>HeuristicLab.Encodings.PermutationEncoding-3.3</Name>
    113127    </ProjectReference>
    114128    <ProjectReference Include="..\..\HeuristicLab.MainForm.WindowsForms\3.2\HeuristicLab.MainForm.WindowsForms-3.2.csproj">
  • trunk/sources/HeuristicLab.Problems.TSP.Views/3.3/HeuristicLabProblemsTSPViewsPlugin.cs.frame

    r2883 r3107  
    3131  [PluginDependency("HeuristicLab.Core", "3.3")]
    3232  [PluginDependency("HeuristicLab.Core.Views", "3.3")]
     33  [PluginDependency("HeuristicLab.Data", "3.3")]
     34  [PluginDependency("HeuristicLab.Encodings.PermutationEncoding", "3.3")]
    3335  [PluginDependency("HeuristicLab.MainForm", "3.2")]
    3436  [PluginDependency("HeuristicLab.MainForm.WindowsForms", "3.2")]
  • trunk/sources/HeuristicLab.Problems.TSP/3.3/HeuristicLab.Problems.TSP-3.3.csproj

    r3097 r3107  
    8484  </ItemGroup>
    8585  <ItemGroup>
    86     <Compile Include="Interfaces\IPathTSPTourVisualizer.cs" />
    87     <Compile Include="Interfaces\ITSPTourVisualizer.cs" />
    88     <Compile Include="TSPTour.cs" />
    89     <Compile Include="Visualizers\PathTSPTourVisualizer.cs" />
     86    <Compile Include="Interfaces\ICoordinatesTSPSolutionsVisualizer.cs" />
     87    <Compile Include="Interfaces\IPathCoordinatesTSPSolutionsVisualizer.cs" />
     88    <Compile Include="Interfaces\ITSPSolutionsVisualizer.cs" />
     89    <Compile Include="PathTSPTour.cs" />
     90    <Compile Include="Visualizers\BestPathTSPTourVisualizer.cs" />
    9091    <Compile Include="Evaluators\TSPCoordinatesPathEvaluator.cs" />
    9192    <Compile Include="Evaluators\TSPEvaluator.cs" />
  • trunk/sources/HeuristicLab.Problems.TSP/3.3/Interfaces/IPathCoordinatesTSPSolutionsVisualizer.cs

    r3106 r3107  
    2525namespace HeuristicLab.Problems.TSP {
    2626  /// <summary>
    27   /// An interface which represents an operator for visualizing tours of Traveling Salesman Problems given in path representation.
     27  /// An interface which represents an operator for visualizing tours of Traveling Salesman Problems given in path representation using city coordinates.
    2828  /// </summary>
    29   public interface IPathTSPTourVisualizer : ITSPTourVisualizer {
    30     ILookupParameter<Permutation> PermutationParameter { get; }
     29  public interface IPathCoordinatesTSPSolutionsVisualizer : ICoordinatesTSPSolutionsVisualizer {
     30    ILookupParameter<ItemArray<Permutation>> PermutationParameter { get; }
    3131  }
    3232}
  • trunk/sources/HeuristicLab.Problems.TSP/3.3/Interfaces/ITSPSolutionsVisualizer.cs

    r3106 r3107  
    2020#endregion
    2121
    22 using HeuristicLab.Core;
    23 using HeuristicLab.Data;
    2422using HeuristicLab.Optimization;
    2523
    2624namespace HeuristicLab.Problems.TSP {
    2725  /// <summary>
    28   /// An interface which represents an operator for visualizing tours of Traveling Salesman Problems.
     26  /// An interface which represents an operator for visualizing solutions of Traveling Salesman Problems.
    2927  /// </summary>
    30   public interface ITSPTourVisualizer : ISolutionVisualizer {
    31     ILookupParameter<DoubleMatrix> CoordinatesParameter { get; }
    32   }
     28  public interface ITSPSolutionsVisualizer : ISingleObjectiveSolutionsVisualizer { }
    3329}
  • trunk/sources/HeuristicLab.Problems.TSP/3.3/PathTSPTour.cs

    r3104 r3107  
    2121
    2222using System;
     23using HeuristicLab.Common;
    2324using HeuristicLab.Core;
    2425using HeuristicLab.Data;
     
    2829namespace HeuristicLab.Problems.TSP {
    2930  /// <summary>
    30   /// Represents a tour of a Traveling Salesman Problem which can be visualized in the GUI.
     31  /// Represents a tour of a Traveling Salesman Problem given in path representation which can be visualized in the GUI.
    3132  /// </summary>
    32   [Item("TSPTour", "Represents a tour of a Traveling Salesman Problem which can be visualized in the GUI.")]
     33  [Item("PathTSPTour", "Represents a tour of a Traveling Salesman Problem given in path representation which can be visualized in the GUI.")]
    3334  [StorableClass]
    34   public sealed class TSPTour : Item {
     35  public sealed class PathTSPTour : Item {
    3536    private DoubleMatrix coordinates;
    3637    [Storable]
     
    4041        if (value == null) throw new ArgumentNullException();
    4142        if (coordinates != value) {
     43          if (coordinates != null) DeregisterCoordinatesEvents();
    4244          coordinates = value;
     45          if (coordinates != null) RegisterCoordinatesEvents();
    4346          OnCoordinatesChanged();
    4447        }
     
    5255        if (value == null) throw new ArgumentNullException();
    5356        if (permutation != value) {
     57          if (permutation != null) DeregisterPermutationEvents();
    5458          permutation = value;
     59          if (permutation != null) RegisterCoordinatesEvents();
    5560          OnPermutationChanged();
    5661        }
     
    5863    }
    5964
    60     private TSPTour() : base() { }
    61     public TSPTour(DoubleMatrix coordinates, Permutation permutation)
     65    private PathTSPTour() : base() { }
     66    public PathTSPTour(DoubleMatrix coordinates, Permutation permutation)
    6267      : base() {
    63       if ((coordinates == null) || (permutation == null)) throw new ArgumentNullException();
    64       this.coordinates = coordinates;
    65       this.permutation = permutation;
     68      Coordinates = coordinates;
     69      Permutation = permutation;
    6670    }
    6771
    6872    public override IDeepCloneable Clone(Cloner cloner) {
    69       TSPTour clone = new TSPTour((DoubleMatrix)cloner.Clone(coordinates), (Permutation)cloner.Clone(permutation));
     73      PathTSPTour clone = new PathTSPTour();
    7074      cloner.RegisterClonedObject(this, clone);
     75      clone.Coordinates = (DoubleMatrix)cloner.Clone(coordinates);
     76      clone.Permutation = (Permutation)cloner.Clone(permutation);
    7177      return clone;
    7278    }
    7379
     80    #region Events
    7481    public event EventHandler CoordinatesChanged;
    7582    private void OnCoordinatesChanged() {
     
    8289        PermutationChanged(this, EventArgs.Empty);
    8390    }
     91
     92    private void RegisterCoordinatesEvents() {
     93      Coordinates.ItemChanged += new EventHandler<EventArgs<int, int>>(Coordinates_ItemChanged);
     94      Coordinates.Reset += new EventHandler(Coordinates_Reset);
     95    }
     96    private void DeregisterCoordinatesEvents() {
     97      Coordinates.ItemChanged -= new EventHandler<EventArgs<int, int>>(Coordinates_ItemChanged);
     98      Coordinates.Reset -= new EventHandler(Coordinates_Reset);
     99    }
     100    private void RegisterPermutationEvents() {
     101      Permutation.ItemChanged += new EventHandler<EventArgs<int>>(Permutation_ItemChanged);
     102      Permutation.Reset += new EventHandler(Permutation_Reset);
     103    }
     104    private void DeregisterPermutationEvents() {
     105      Permutation.ItemChanged -= new EventHandler<EventArgs<int>>(Permutation_ItemChanged);
     106      Permutation.Reset -= new EventHandler(Permutation_Reset);
     107    }
     108
     109    private void Coordinates_ItemChanged(object sender, EventArgs<int, int> e) {
     110      OnCoordinatesChanged();
     111    }
     112    private void Coordinates_Reset(object sender, EventArgs e) {
     113      OnCoordinatesChanged();
     114    }
     115    private void Permutation_ItemChanged(object sender, EventArgs<int> e) {
     116      OnPermutationChanged();
     117    }
     118    private void Permutation_Reset(object sender, EventArgs e) {
     119      OnPermutationChanged();
     120    }
     121    #endregion
    84122  }
    85123}
  • trunk/sources/HeuristicLab.Problems.TSP/3.3/TSP.cs

    r3099 r3107  
    7070      get { return EvaluatorParameter; }
    7171    }
     72    public OptionalValueParameter<ITSPSolutionsVisualizer> VisualizerParameter {
     73      get { return (OptionalValueParameter<ITSPSolutionsVisualizer>)Parameters["Visualizer"]; }
     74    }
     75    IParameter IProblem.VisualizerParameter {
     76      get { return VisualizerParameter; }
     77    }
    7278    public OptionalValueParameter<DoubleValue> BestKnownQualityParameter {
    7379      get { return (OptionalValueParameter<DoubleValue>)Parameters["BestKnownQuality"]; }
     
    108114      get { return EvaluatorParameter.Value; }
    109115    }
     116    public ITSPSolutionsVisualizer Visualizer {
     117      get { return VisualizerParameter.Value; }
     118      set { VisualizerParameter.Value = value; }
     119    }
     120    ISolutionsVisualizer IProblem.Visualizer {
     121      get { return VisualizerParameter.Value; }
     122    }
    110123    public DoubleValue BestKnownQuality {
    111124      get { return BestKnownQualityParameter.Value; }
     
    122135      RandomPermutationCreator creator = new RandomPermutationCreator();
    123136      TSPRoundedEuclideanPathEvaluator evaluator = new TSPRoundedEuclideanPathEvaluator();
     137      BestPathTSPTourVisualizer visualizer = new BestPathTSPTourVisualizer();
    124138
    125139      Parameters.Add(new ValueParameter<BoolValue>("Maximization", "Set to false as the Traveling Salesman Problem is a minimization problem.", new BoolValue(false)));
     
    129143      Parameters.Add(new ValueParameter<IPermutationCreator>("SolutionCreator", "The operator which should be used to create new TSP solutions.", creator));
    130144      Parameters.Add(new ValueParameter<ITSPEvaluator>("Evaluator", "The operator which should be used to evaluate TSP solutions.", evaluator));
     145      Parameters.Add(new OptionalValueParameter<ITSPSolutionsVisualizer>("Visualizer", "The operator which should be used to visualize TSP solutions.", visualizer));
    131146      Parameters.Add(new OptionalValueParameter<DoubleValue>("BestKnownQuality", "The quality of the best known solution of this TSP instance."));
    132147
     
    135150      ParameterizeSolutionCreator();
    136151      ParameterizeEvaluator();
     152      ParameterizeVisualizer();
    137153
    138154      Initialize();
     
    164180        EvaluatorChanged(this, EventArgs.Empty);
    165181    }
     182    public event EventHandler VisualizerChanged;
     183    private void OnVisualizerChanged() {
     184      if (VisualizerChanged != null)
     185        VisualizerChanged(this, EventArgs.Empty);
     186    }
    166187    public event EventHandler OperatorsChanged;
    167188    private void OnOperatorsChanged() {
     
    187208      ParameterizeSolutionCreator();
    188209      ParameterizeEvaluator();
     210      ParameterizeVisualizer();
    189211      ParameterizeOperators();
    190212      OnSolutionCreatorChanged();
     
    192214    private void SolutionCreator_PermutationParameter_ActualNameChanged(object sender, EventArgs e) {
    193215      ParameterizeEvaluator();
     216      ParameterizeVisualizer();
    194217      ParameterizeOperators();
    195218    }
    196219    private void EvaluatorParameter_ValueChanged(object sender, EventArgs e) {
    197220      ParameterizeEvaluator();
     221      ParameterizeVisualizer();
    198222      ClearDistanceMatrix();
    199223      OnEvaluatorChanged();
     224    }
     225    private void VisualizerParameter_ValueChanged(object sender, EventArgs e) {
     226      ParameterizeVisualizer();
     227      OnVisualizerChanged();
    200228    }
    201229    private void MoveGenerator_TwoOptMoveParameter_ActualNameChanged(object sender, EventArgs e) {
     
    223251      SolutionCreator.PermutationParameter.ActualNameChanged += new EventHandler(SolutionCreator_PermutationParameter_ActualNameChanged);
    224252      EvaluatorParameter.ValueChanged += new EventHandler(EvaluatorParameter_ValueChanged);
     253      VisualizerParameter.ValueChanged += new EventHandler(VisualizerParameter_ValueChanged);
    225254    }
    226255    private void InitializeOperators() {
     
    257286      }
    258287    }
     288    private void ParameterizeVisualizer() {
     289      Visualizer.QualityParameter.ActualName = Evaluator.QualityParameter.ActualName;
     290      if (Visualizer is ICoordinatesTSPSolutionsVisualizer)
     291        ((ICoordinatesTSPSolutionsVisualizer)Visualizer).CoordinatesParameter.ActualName = CoordinatesParameter.Name;
     292      if (Visualizer is IPathCoordinatesTSPSolutionsVisualizer)
     293        ((IPathCoordinatesTSPSolutionsVisualizer)Visualizer).PermutationParameter.ActualName = SolutionCreator.PermutationParameter.ActualName;
     294    }
    259295    private void ParameterizeOperators() {
    260296      foreach (IPermutationCrossover op in Operators.OfType<IPermutationCrossover>()) {
  • trunk/sources/HeuristicLab.Problems.TSP/3.3/Visualizers/BestPathTSPTourVisualizer.cs

    r3106 r3107  
    2020#endregion
    2121
     22using System.Linq;
    2223using HeuristicLab.Core;
    2324using HeuristicLab.Data;
    2425using HeuristicLab.Encodings.PermutationEncoding;
    2526using HeuristicLab.Operators;
     27using HeuristicLab.Optimization;
    2628using HeuristicLab.Parameters;
    2729using HeuristicLab.Persistence.Default.CompositeSerializers.Storable;
     
    2931namespace HeuristicLab.Problems.TSP {
    3032  /// <summary>
    31   /// An operator for visualizing tours of Traveling Salesman Problems given in path representation.
     33  /// An operator for visualizing the best tour of Traveling Salesman Problems given in path representation using city coordinates.
    3234  /// </summary>
    33   [Item("PathTSPTourVisualizer", "An operator for visualizing tours of Traveling Salesman Problems given in path representation.")]
     35  [Item("BestPathTSPTourVisualizer", "An operator for visualizing the best tour of Traveling Salesman Problems given in path representation using city coordinates.")]
    3436  [StorableClass]
    35   public sealed class PathTSPTourVisualizer : SingleSuccessorOperator, IPathTSPTourVisualizer {
     37  public sealed class BestPathTSPTourVisualizer : SingleSuccessorOperator, IPathCoordinatesTSPSolutionsVisualizer {
    3638    public ILookupParameter<DoubleMatrix> CoordinatesParameter {
    3739      get { return (ILookupParameter<DoubleMatrix>)Parameters["Coordinates"]; }
    3840    }
    39     public ILookupParameter<Permutation> PermutationParameter {
    40       get { return (ILookupParameter<Permutation>)Parameters["Permutation"]; }
     41    public ILookupParameter<ItemArray<Permutation>> PermutationParameter {
     42      get { return (ILookupParameter<ItemArray<Permutation>>)Parameters["Permutation"]; }
    4143    }
    42     public ILookupParameter<IItem> VisualizationParameter {
    43       get { return (ILookupParameter<IItem>)Parameters["Visualization"]; }
     44    public ILookupParameter<ItemArray<DoubleValue>> QualityParameter {
     45      get { return (ILookupParameter<ItemArray<DoubleValue>>)Parameters["Quality"]; }
     46    }
     47    public ILookupParameter<PathTSPTour> PathTSPTourParameter {
     48      get { return (ILookupParameter<PathTSPTour>)Parameters["PathTSPTour"]; }
     49    }
     50    ILookupParameter ISolutionsVisualizer.VisualizationParameter {
     51      get { return PathTSPTourParameter; }
    4452    }
    4553
    46     public PathTSPTourVisualizer()
     54    public BestPathTSPTourVisualizer()
    4755      : base() {
    4856      Parameters.Add(new LookupParameter<DoubleMatrix>("Coordinates", "The x- and y-Coordinates of the cities."));
    49       Parameters.Add(new LookupParameter<Permutation>("Permutation", "The TSP solution given in path representation which should be visualized."));
    50       Parameters.Add(new LookupParameter<IItem>("Visualization", "An item which represents the visualization of the given TSP solution."));
     57      Parameters.Add(new SubScopesLookupParameter<Permutation>("Permutation", "The TSP solutions given in path representation from which the best solution should be visualized."));
     58      Parameters.Add(new SubScopesLookupParameter<DoubleValue>("Quality", "The qualities of the TSP solutions which should be visualized."));
     59      Parameters.Add(new LookupParameter<PathTSPTour>("PathTSPTour", "The visual representation of the best TSP solution."));
    5160    }
    5261
    5362    public override IOperation Apply() {
    5463      DoubleMatrix coordinates = CoordinatesParameter.ActualValue;
    55       Permutation permutation = PermutationParameter.ActualValue;
    56       TSPTour tour = new TSPTour(coordinates, permutation);
    57       VisualizationParameter.ActualValue = tour;
     64      ItemArray<Permutation> permutations = PermutationParameter.ActualValue;
     65      ItemArray<DoubleValue> qualities = QualityParameter.ActualValue;
     66
     67      int i = qualities.Select((x, index) => new { index, x.Value }).OrderBy(x => x.Value).First().index;
     68
     69      PathTSPTour tour = PathTSPTourParameter.ActualValue;
     70      if (tour == null) PathTSPTourParameter.ActualValue = new PathTSPTour(coordinates, permutations[i]);
     71      else {
     72        tour.Coordinates = coordinates;
     73        tour.Permutation = permutations[i];
     74      }
    5875      return base.Apply();
    5976    }
Note: See TracChangeset for help on using the changeset viewer.