Free cookie consent management tool by TermsFeed Policy Generator

Changeset 3153


Ignore:
Timestamp:
03/22/10 01:00:52 (14 years ago)
Author:
swagner
Message:

Added TSP instance visualization (#924).

Location:
trunk/sources
Files:
8 edited

Legend:

Unmodified
Added
Removed
  • trunk/sources/HeuristicLab.Problems.TSP.Views/3.3/HeuristicLab.Problems.TSP.Views-3.3.csproj

    r3151 r3153  
    152152      <Name>HeuristicLab.Optimization-3.3</Name>
    153153    </ProjectReference>
     154    <ProjectReference Include="..\..\HeuristicLab.Parameters\3.3\HeuristicLab.Parameters-3.3.csproj">
     155      <Project>{56F9106A-079F-4C61-92F6-86A84C2D84B7}</Project>
     156      <Name>HeuristicLab.Parameters-3.3</Name>
     157    </ProjectReference>
    154158    <ProjectReference Include="..\..\HeuristicLab.PluginInfrastructure\HeuristicLab.PluginInfrastructure.csproj">
    155159      <Project>{94186A6A-5176-4402-AE83-886557B53CCA}</Project>
  • trunk/sources/HeuristicLab.Problems.TSP.Views/3.3/HeuristicLabProblemsTSPViewsPlugin.cs.frame

    r3151 r3153  
    3838  [PluginDependency("HeuristicLab.Optimization", "3.3")]
    3939  [PluginDependency("HeuristicLab.Optimization.Views", "3.3")]
     40  [PluginDependency("HeuristicLab.Parameters", "3.3")]
    4041  [PluginDependency("HeuristicLab.Problems.TSP", "3.3")]
    4142  public class HeuristicLabProblemsTSPViewsPlugin : PluginBase {
  • trunk/sources/HeuristicLab.Problems.TSP.Views/3.3/PathTSPTourView.cs

    r3139 r3153  
    6969      base.OnContentChanged();
    7070      if (Content == null) {
     71        pictureBox.Image = null;
    7172        pictureBox.Enabled = false;
    7273      } else {
    7374        pictureBox.Enabled = true;
     75        GenerateImage();
    7476      }
    75       GenerateImage();
    7677    }
    7778
     
    8586          Bitmap bitmap = new Bitmap(pictureBox.Width, pictureBox.Height);
    8687
    87           if (coordinates != null) {
     88          if ((coordinates != null) && (coordinates.Rows > 0) && (coordinates.Columns == 2)) {
    8889            double xMin = double.MaxValue, yMin = double.MaxValue, xMax = double.MinValue, yMax = double.MinValue;
    8990            for (int i = 0; i < coordinates.Rows; i++) {
     
    99100
    100101            Point[] points = new Point[coordinates.Rows];
    101             if (permutation == null) {
    102               for (int i = 0; i < coordinates.Rows; i++)
    103                 points[i] = new Point(border + ((int)((coordinates[i, 0] - xMin) * xStep)),
    104                                       border + ((int)((coordinates[i, 1] - yMin) * yStep)));
    105             } else {
    106               for (int i = 0; i < coordinates.Rows; i++)
    107                 points[i] = new Point(border + ((int)((coordinates[permutation[i], 0] - xMin) * xStep)),
    108                                       border + ((int)((coordinates[permutation[i], 1] - yMin) * yStep)));
    109             }
     102            for (int i = 0; i < coordinates.Rows; i++)
     103              points[i] = new Point(border + ((int)((coordinates[i, 0] - xMin) * xStep)),
     104                                    border + ((int)((coordinates[i, 1] - yMin) * yStep)));
    110105
    111106            Graphics graphics = Graphics.FromImage(bitmap);
    112             if (permutation != null) graphics.DrawPolygon(Pens.Black, points);
     107            if ((permutation != null) && (permutation.Length == coordinates.Rows) && (permutation.Validate())) {
     108              Point[] tour = new Point[permutation.Length];
     109              for (int i = 0; i < permutation.Length; i++) {
     110                tour[i] = points[permutation[i]];
     111              }
     112              graphics.DrawPolygon(Pens.Black, tour);
     113            }
    113114            for (int i = 0; i < points.Length; i++)
    114115              graphics.FillRectangle(Brushes.Red, points[i].X - 2, points[i].Y - 2, 6, 6);
  • trunk/sources/HeuristicLab.Problems.TSP.Views/3.3/TSPLIBImportDialog.cs

    r3151 r3153  
    2727
    2828namespace HeuristicLab.Problems.TSP.Views {
    29   public partial class TSPLIBImportDialog : Form {
     29  public sealed partial class TSPLIBImportDialog : Form {
    3030    private string tspFileName;
    3131    public string TSPFileName {
  • trunk/sources/HeuristicLab.Problems.TSP.Views/3.3/TSPView.Designer.cs

    r3151 r3153  
    4747    private void InitializeComponent() {
    4848      this.importButton = new System.Windows.Forms.Button();
     49      this.tabControl = new System.Windows.Forms.TabControl();
     50      this.parametersTabPage = new System.Windows.Forms.TabPage();
     51      this.parameterCollectionView = new HeuristicLab.Core.Views.ParameterCollectionView();
     52      this.visualizationTabPage = new System.Windows.Forms.TabPage();
     53      this.pathTSPTourView = new HeuristicLab.Problems.TSP.Views.PathTSPTourView();
    4954      ((System.ComponentModel.ISupportInitialize)(this.errorProvider)).BeginInit();
     55      this.tabControl.SuspendLayout();
     56      this.parametersTabPage.SuspendLayout();
     57      this.visualizationTabPage.SuspendLayout();
    5058      this.SuspendLayout();
    51       //
    52       // parameterCollectionView
    53       //
    54       this.parameterCollectionView.Size = new System.Drawing.Size(529, 341);
    5559      //
    5660      // nameTextBox
     
    7680      this.importButton.Click += new System.EventHandler(this.importButton_Click);
    7781      //
     82      // tabControl
     83      //
     84      this.tabControl.Anchor = ((System.Windows.Forms.AnchorStyles)((((System.Windows.Forms.AnchorStyles.Top | System.Windows.Forms.AnchorStyles.Bottom)
     85                  | System.Windows.Forms.AnchorStyles.Left)
     86                  | System.Windows.Forms.AnchorStyles.Right)));
     87      this.tabControl.Controls.Add(this.parametersTabPage);
     88      this.tabControl.Controls.Add(this.visualizationTabPage);
     89      this.tabControl.Location = new System.Drawing.Point(0, 52);
     90      this.tabControl.Name = "tabControl";
     91      this.tabControl.SelectedIndex = 0;
     92      this.tabControl.Size = new System.Drawing.Size(529, 341);
     93      this.tabControl.TabIndex = 4;
     94      //
     95      // parametersTabPage
     96      //
     97      this.parametersTabPage.Controls.Add(this.parameterCollectionView);
     98      this.parametersTabPage.Location = new System.Drawing.Point(4, 22);
     99      this.parametersTabPage.Name = "parametersTabPage";
     100      this.parametersTabPage.Padding = new System.Windows.Forms.Padding(3);
     101      this.parametersTabPage.Size = new System.Drawing.Size(521, 315);
     102      this.parametersTabPage.TabIndex = 0;
     103      this.parametersTabPage.Text = "Parameters";
     104      this.parametersTabPage.UseVisualStyleBackColor = true;
     105      //
     106      // parameterCollectionView
     107      //
     108      this.parameterCollectionView.Anchor = ((System.Windows.Forms.AnchorStyles)((((System.Windows.Forms.AnchorStyles.Top | System.Windows.Forms.AnchorStyles.Bottom)
     109                  | System.Windows.Forms.AnchorStyles.Left)
     110                  | System.Windows.Forms.AnchorStyles.Right)));
     111      this.parameterCollectionView.Caption = "ParameterCollection";
     112      this.parameterCollectionView.Content = null;
     113      this.parameterCollectionView.Location = new System.Drawing.Point(6, 6);
     114      this.parameterCollectionView.Name = "parameterCollectionView";
     115      this.parameterCollectionView.Size = new System.Drawing.Size(509, 303);
     116      this.parameterCollectionView.TabIndex = 0;
     117      //
     118      // visualizationTabPage
     119      //
     120      this.visualizationTabPage.Controls.Add(this.pathTSPTourView);
     121      this.visualizationTabPage.Location = new System.Drawing.Point(4, 22);
     122      this.visualizationTabPage.Name = "visualizationTabPage";
     123      this.visualizationTabPage.Padding = new System.Windows.Forms.Padding(3);
     124      this.visualizationTabPage.Size = new System.Drawing.Size(521, 315);
     125      this.visualizationTabPage.TabIndex = 1;
     126      this.visualizationTabPage.Text = "Visualization";
     127      this.visualizationTabPage.UseVisualStyleBackColor = true;
     128      //
     129      // pathTSPTourView
     130      //
     131      this.pathTSPTourView.Anchor = ((System.Windows.Forms.AnchorStyles)((((System.Windows.Forms.AnchorStyles.Top | System.Windows.Forms.AnchorStyles.Bottom)
     132                  | System.Windows.Forms.AnchorStyles.Left)
     133                  | System.Windows.Forms.AnchorStyles.Right)));
     134      this.pathTSPTourView.Caption = "View";
     135      this.pathTSPTourView.Content = null;
     136      this.pathTSPTourView.Location = new System.Drawing.Point(6, 6);
     137      this.pathTSPTourView.Name = "pathTSPTourView";
     138      this.pathTSPTourView.Size = new System.Drawing.Size(509, 303);
     139      this.pathTSPTourView.TabIndex = 0;
     140      //
    78141      // TSPView
    79142      //
    80143      this.AutoScaleDimensions = new System.Drawing.SizeF(6F, 13F);
    81144      this.AutoScaleMode = System.Windows.Forms.AutoScaleMode.Font;
     145      this.Controls.Add(this.tabControl);
    82146      this.Controls.Add(this.importButton);
    83147      this.Name = "TSPView";
    84148      this.Size = new System.Drawing.Size(529, 422);
    85149      this.Controls.SetChildIndex(this.importButton, 0);
    86       this.Controls.SetChildIndex(this.parameterCollectionView, 0);
     150      this.Controls.SetChildIndex(this.tabControl, 0);
    87151      this.Controls.SetChildIndex(this.nameLabel, 0);
    88152      this.Controls.SetChildIndex(this.descriptionLabel, 0);
     
    90154      this.Controls.SetChildIndex(this.descriptionTextBox, 0);
    91155      ((System.ComponentModel.ISupportInitialize)(this.errorProvider)).EndInit();
     156      this.tabControl.ResumeLayout(false);
     157      this.parametersTabPage.ResumeLayout(false);
     158      this.visualizationTabPage.ResumeLayout(false);
    92159      this.ResumeLayout(false);
    93160      this.PerformLayout();
     
    98165
    99166    private System.Windows.Forms.Button importButton;
     167    private System.Windows.Forms.TabControl tabControl;
     168    private System.Windows.Forms.TabPage parametersTabPage;
     169    private System.Windows.Forms.TabPage visualizationTabPage;
     170    private HeuristicLab.Core.Views.ParameterCollectionView parameterCollectionView;
     171    private PathTSPTourView pathTSPTourView;
    100172
    101173  }
  • trunk/sources/HeuristicLab.Problems.TSP.Views/3.3/TSPView.cs

    r3151 r3153  
    2222using System;
    2323using System.Windows.Forms;
     24using HeuristicLab.Core;
    2425using HeuristicLab.Core.Views;
    2526using HeuristicLab.MainForm;
    26 using HeuristicLab.Optimization.Views;
    2727
    2828namespace HeuristicLab.Problems.TSP.Views {
     
    3232  [View("TSP View")]
    3333  [Content(typeof(TSP), true)]
    34   public sealed partial class TSPView : ProblemView {
     34  public sealed partial class TSPView : NamedItemView {
    3535    private TSPLIBImportDialog tsplibImportDialog;
    3636
     
    5555    }
    5656
     57    protected override void DeregisterContentEvents() {
     58      Content.CoordinatesParameter.ValueChanged -= new EventHandler(CoordinatesParameter_ValueChanged);
     59      Content.BestKnownSolutionParameter.ValueChanged -= new EventHandler(BestKnownSolutionParameter_ValueChanged);
     60      base.DeregisterContentEvents();
     61    }
     62    protected override void RegisterContentEvents() {
     63      base.RegisterContentEvents();
     64      Content.CoordinatesParameter.ValueChanged += new EventHandler(CoordinatesParameter_ValueChanged);
     65      Content.BestKnownSolutionParameter.ValueChanged += new EventHandler(BestKnownSolutionParameter_ValueChanged);
     66    }
     67
    5768    protected override void OnContentChanged() {
    5869      base.OnContentChanged();
    5970      if (Content == null) {
     71        parameterCollectionView.Content = null;
     72        parameterCollectionView.Enabled = false;
     73        pathTSPTourView.Content = null;
     74        pathTSPTourView.Enabled = false;
    6075        importButton.Enabled = false;
    6176      } else {
     77        parameterCollectionView.Content = ((IParameterizedNamedItem)Content).Parameters;
     78        parameterCollectionView.Enabled = true;
     79        pathTSPTourView.Content = new PathTSPTour(Content.Coordinates, Content.BestKnownSolution);
     80        pathTSPTourView.Enabled = true;
    6281        importButton.Enabled = true;
    6382      }
     
    7998      }
    8099    }
     100
     101    private void CoordinatesParameter_ValueChanged(object sender, EventArgs e) {
     102      pathTSPTourView.Content.Coordinates = Content.Coordinates;
     103    }
     104    private void BestKnownSolutionParameter_ValueChanged(object sender, EventArgs e) {
     105      pathTSPTourView.Content.Permutation = Content.BestKnownSolution;
     106    }
    81107  }
    82108}
  • trunk/sources/HeuristicLab.Problems.TSP/3.3/HeuristicLab.Problems.TSP-3.3.csproj

    r3151 r3153  
    156156  </ItemGroup>
    157157  <ItemGroup>
     158    <None Include="ch130.opt.tour" />
    158159    <None Include="ch130.tsp" />
    159160    <None Include="fl1400.tsp" />
  • trunk/sources/HeuristicLab.Problems.TSP/3.3/TSP.cs

    r3151 r3153  
    2323using System.Collections.Generic;
    2424using System.Drawing;
     25using System.IO;
    2526using System.Linq;
    2627using HeuristicLab.Common;
     
    178179      Coordinates = new DoubleMatrix(tspParser.Vertices);
    179180      BestKnownQuality = null;
    180 
     181      BestKnownSolution = null;
    181182      if (!string.IsNullOrEmpty(optimalTourFileName)) {
    182183        TSPLIBTourParser tourParser = new TSPLIBTourParser(optimalTourFileName);
    183184        tourParser.Parse();
     185        if (tourParser.Tour.Length != Coordinates.Rows) throw new InvalidDataException("Length of optimal tour is not equal to number of cities.");
    184186        BestKnownSolution = new Permutation(tourParser.Tour);
    185187      }
Note: See TracChangeset for help on using the changeset viewer.