Free cookie consent management tool by TermsFeed Policy Generator

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

Added TSP instance visualization (#924).

File:
1 edited

Legend:

Unmodified
Added
Removed
  • 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);
Note: See TracChangeset for help on using the changeset viewer.