Free cookie consent management tool by TermsFeed Policy Generator

Changeset 5648


Ignore:
Timestamp:
03/10/11 01:49:10 (14 years ago)
Author:
abeham
Message:

#1330

  • Unified QAP visualization in solution and problem view
  • Fixed bug in gradient-descent gradient calculation when performing multidimensional scaling
  • Extended QAPLIB parsers to cover some file format variations
  • Added unit tests to check if all QAPLIB instances import without error
  • Changed BestKnownSolution to be an OptionalValueParameter
Location:
branches/QAP
Files:
6 added
11 edited

Legend:

Unmodified
Added
Removed
  • branches/QAP

    • Property svn:ignore
      •  

        old new  
        11*.suo
         2TestResults
  • branches/QAP/HeuristicLab.Problems.QuadraticAssignment.Views/3.3/MultidimensionalScaling.cs

    r5641 r5648  
    2323using HeuristicLab.Data;
    2424
    25 namespace HeuristicLab.Problems.QuadraticAssignment {
     25namespace HeuristicLab.Problems.QuadraticAssignment.Views {
    2626  public static class MultidimensionalScaling {
    27 
    28     public static DoubleMatrix Classic(DoubleMatrix distances, out double error) {
    29       if (distances == null) throw new ArgumentNullException("distances");
    30       if (distances.Rows != distances.Columns) throw new ArgumentException("Distance matrix must be a square matrix.", "distances");
    31       error = 0.0;
    32 
    33       int dimension = distances.Rows;
    34       if (dimension == 1) return new DoubleMatrix(new double[,] { { 0, 0 } });
    35       else if (dimension == 2) return new DoubleMatrix(new double[,] { { 0, distances[0, 1] } });
    36 
    37       double[,] A = new double[dimension + 1, dimension + 1];
    38       for (int i = 1; i < dimension; i++) {
    39         for (int j = i + 1; j < dimension + 1; j++) {
    40           A[i, j] = -0.5 * distances[i - 1, j - 1] * distances[i - 1, j - 1];
    41           A[j, i] = A[i, j];
    42           A[0, 0] += A[i, j] / (dimension * dimension);
    43           double avg = A[i, j] / (double)dimension;
    44           A[0, j] += avg;
    45           A[0, i] += avg;
    46           A[i, 0] += avg;
    47           A[j, 0] += avg;
    48         }
    49       }
    50       double[,] B = new double[dimension, dimension];
    51       for (int i = 0; i < dimension - 1; i++) {
    52         for (int j = i + 1; j < dimension; j++) {
    53           B[i, j] = A[i + 1, j + 1] - A[0, j + 1] - A[i + 1, 0] + A[0, 0];
    54         }
    55       }
    56       double[] eigenvalues;
    57       double[,] eigenvectors;
    58       alglib.smatrixevd(B, dimension, 1, true, out eigenvalues, out eigenvectors);
    59 
    60       DoubleMatrix coordinates = new DoubleMatrix(dimension, 2);
    61       for (int i = 0; i < dimension; i++) {
    62         for (int j = 0; j < dimension; j++) {
    63           coordinates[i, 0] += eigenvectors[eigenvectors.GetLength(0) - 1, j]
    64                              * distances[i, j];
    65           coordinates[i, 1] += eigenvectors[eigenvectors.GetLength(0) - 2, j]
    66                              * distances[i, j];
    67         }
    68       }
    69 
    70       return coordinates;
    71     }
    7227
    7328    /// <summary>
     
    7732    /// </summary>
    7833    /// <param name="distances">A symmetric NxN matrix that specifies the distances between each element i and j. Diagonal elements are ignored.</param>
    79     /// <param name="error">Returns the error between the fit distances and the actual distances.</param>
     34    /// <param name="stress">Returns the stress between the fit distances and the actual distances.</param>
    8035    /// <returns>A Nx2 matrix where the first column represents the x- and the second column the y coordinates.</returns>
    81     public static DoubleMatrix Metric(DoubleMatrix distances, out double error) {
     36    public static DoubleMatrix MetricByDistance(DoubleMatrix distances, out double stress) {
    8237      if (distances == null) throw new ArgumentNullException("distances");
    8338      if (distances.Rows != distances.Columns) throw new ArgumentException("Distance matrix must be a square matrix.", "distances");
    84       error = 0.0;
     39      stress = 0.0;
    8540
    8641      int dimension = distances.Rows;
     
    9449        coordinates[i, 1] = 10 * Math.Sin(rad * i);
    9550      }
    96       double epsg = 0.0000000001;
     51
     52      double epsg = 1e-7;
    9753      double epsf = 0;
    9854      double epsx = 0;
    99       int maxits = 1000;
     55      int maxits = 0;
    10056      alglib.mincgstate state = null;
    10157      alglib.mincgreport rep;
    10258
    103       for (int iterations = 0; iterations < 200; iterations++) {
     59      for (int iterations = 0; iterations < 10; iterations++) {
    10460        for (int i = 0; i < dimension; i++) {
    10561          double[] c = new double[] { coordinates[i, 0], coordinates[i, 1] };
     
    11167            alglib.mincgrestartfrom(state, c);
    11268          }
    113           alglib.mincgoptimize(state, func, null, new Info(coordinates, distances, i));
     69          alglib.mincgoptimize(state, StressGradient, null, new Info(coordinates, distances, i));
    11470          alglib.mincgresults(state, out c, out rep);
    11571
     
    11874        }
    11975      }
    120       error = 0;
     76      stress = CalculateNormalizedStress(dimension, distances, coordinates);
     77      return coordinates;
     78    }
     79
     80    private static void StressGradient(double[] x, ref double func, double[] grad, object obj) {
     81      func = 0; grad[0] = 0; grad[1] = 0;
     82      Info info = (obj as Info);
     83      for (int i = 0; i < info.Coordinates.Rows; i++) {
     84        double c = info.Distances[info.Row, i];
     85        if (i != info.Row) {
     86          double a = info.Coordinates[i, 0];
     87          double b = info.Coordinates[i, 1];
     88          func += Stress(x, c, a, b);
     89          grad[0] += ((2 * x[0] - 2 * a) * Math.Sqrt(x[1] * x[1] - 2 * b * x[1] + x[0] * x[0] - 2 * a * x[0] + b * b + a * a) - 2 * c * x[0] + 2 * a * c) / Math.Sqrt(x[1] * x[1] - 2 * b * x[1] + x[0] * x[0] - 2 * a * x[0] + b * b + a * a);
     90          grad[1] += ((2 * x[1] - 2 * b) * Math.Sqrt(x[1] * x[1] - 2 * b * x[1] + x[0] * x[0] - 2 * a * x[0] + b * b + a * a) - 2 * c * x[1] + 2 * b * c) / Math.Sqrt(x[1] * x[1] - 2 * b * x[1] + x[0] * x[0] - 2 * a * x[0] + b * b + a * a);
     91        }
     92      }
     93    }
     94
     95    private static double Stress(double[] x, double distance, double xCoord, double yCoord) {
     96      return Stress(x[0], x[1], distance, xCoord, yCoord);
     97    }
     98
     99    private static double Stress(double x, double y, double distance, double otherX, double otherY) {
     100      double d = Math.Sqrt((x - otherX) * (x - otherX)
     101                         + (y - otherY) * (y - otherY));
     102      return (d - distance) * (d - distance);
     103    }
     104
     105    public static double CalculateNormalizedStress(int dimension, DoubleMatrix distances, DoubleMatrix coordinates) {
     106      double stress = 0;
    121107      for (int i = 0; i < dimension - 1; i++) {
    122108        for (int j = i + 1; j < dimension; j++) {
    123109          if (distances[i, j] != 0) {
    124             double dx = coordinates[i, 0] - coordinates[j, 0];
    125             double dy = coordinates[i, 1] - coordinates[j, 1];
    126             double d = Math.Sqrt(dx * dx + dy * dy);
    127             error += ((distances[i, j] - d) * (distances[i, j] - d)) / (distances[i, j] * distances[i, j]);
     110            stress += Stress(coordinates[i, 0], coordinates[i, 1], distances[i, j], coordinates[j, 0], coordinates[j, 1])
     111              / (distances[i, j] * distances[i, j]);
    128112          }
    129113        }
    130114      }
    131       return coordinates;
    132     }
    133 
    134     public static void func(double[] x, ref double func, double[] grad, object obj) {
    135       func = 0; grad[0] = 0; grad[1] = 0;
    136       Info info = (obj as Info);
    137       for (int i = 0; i < x.Length; i++) {
    138         if (i != info.Row) {
    139           double d = (x[0] - info.Coordinates[i, 0])
    140                    * (x[0] - info.Coordinates[i, 0])
    141                    + (x[1] - info.Coordinates[i, 1])
    142                    * (x[1] - info.Coordinates[i, 1]);
    143           func += (d - info.Distances[info.Row, i]) * (d - info.Distances[info.Row, i]);
    144           grad[0] += 2 * x[0] - 2 * info.Coordinates[i, 0];
    145           grad[1] += 2 * x[1] - 2 * info.Coordinates[i, 1];
    146         }
    147       }
     115      return stress;
    148116    }
    149117
  • branches/QAP/HeuristicLab.Problems.QuadraticAssignment.Views/3.3/QAPAssignmentView.Designer.cs

    r5641 r5648  
    5050      this.tabControl = new HeuristicLab.MainForm.WindowsForms.DragOverTabControl();
    5151      this.visualizationTabPage = new System.Windows.Forms.TabPage();
    52       this.distancesRadioButton = new System.Windows.Forms.RadioButton();
    53       this.weightsRadioButton = new System.Windows.Forms.RadioButton();
    54       this.pictureBox = new System.Windows.Forms.PictureBox();
    5552      this.valueTabPage = new System.Windows.Forms.TabPage();
    5653      this.assignmentGroupBox = new System.Windows.Forms.GroupBox();
    5754      this.assignmentViewHost = new HeuristicLab.MainForm.WindowsForms.ViewHost();
    58       this.redrawButton = new System.Windows.Forms.Button();
     55      this.qapView = new HeuristicLab.Problems.QuadraticAssignment.Views.QAPView();
    5956      ((System.ComponentModel.ISupportInitialize)(this.splitContainer)).BeginInit();
    6057      this.splitContainer.Panel1.SuspendLayout();
     
    6461      this.tabControl.SuspendLayout();
    6562      this.visualizationTabPage.SuspendLayout();
    66       ((System.ComponentModel.ISupportInitialize)(this.pictureBox)).BeginInit();
    6763      this.valueTabPage.SuspendLayout();
    6864      this.assignmentGroupBox.SuspendLayout();
     
    132128      // visualizationTabPage
    133129      //
    134       this.visualizationTabPage.Controls.Add(this.redrawButton);
    135       this.visualizationTabPage.Controls.Add(this.distancesRadioButton);
    136       this.visualizationTabPage.Controls.Add(this.weightsRadioButton);
    137       this.visualizationTabPage.Controls.Add(this.pictureBox);
     130      this.visualizationTabPage.Controls.Add(this.qapView);
    138131      this.visualizationTabPage.Location = new System.Drawing.Point(4, 22);
    139132      this.visualizationTabPage.Name = "visualizationTabPage";
     
    143136      this.visualizationTabPage.Text = "Visualization";
    144137      this.visualizationTabPage.UseVisualStyleBackColor = true;
    145       //
    146       // distancesRadioButton
    147       //
    148       this.distancesRadioButton.AutoSize = true;
    149       this.distancesRadioButton.Checked = true;
    150       this.distancesRadioButton.Location = new System.Drawing.Point(6, 6);
    151       this.distancesRadioButton.Name = "distancesRadioButton";
    152       this.distancesRadioButton.Size = new System.Drawing.Size(72, 17);
    153       this.distancesRadioButton.TabIndex = 2;
    154       this.distancesRadioButton.TabStop = true;
    155       this.distancesRadioButton.Text = "Distances";
    156       this.distancesRadioButton.UseVisualStyleBackColor = true;
    157       this.distancesRadioButton.CheckedChanged += new System.EventHandler(this.radioButton_CheckedChanged);
    158       //
    159       // weightsRadioButton
    160       //
    161       this.weightsRadioButton.AutoSize = true;
    162       this.weightsRadioButton.Location = new System.Drawing.Point(6, 29);
    163       this.weightsRadioButton.Name = "weightsRadioButton";
    164       this.weightsRadioButton.Size = new System.Drawing.Size(64, 17);
    165       this.weightsRadioButton.TabIndex = 1;
    166       this.weightsRadioButton.Text = "Weights";
    167       this.weightsRadioButton.UseVisualStyleBackColor = true;
    168       this.weightsRadioButton.CheckedChanged += new System.EventHandler(this.radioButton_CheckedChanged);
    169       //
    170       // pictureBox
    171       //
    172       this.pictureBox.Anchor = ((System.Windows.Forms.AnchorStyles)((((System.Windows.Forms.AnchorStyles.Top | System.Windows.Forms.AnchorStyles.Bottom)
    173                   | System.Windows.Forms.AnchorStyles.Left)
    174                   | System.Windows.Forms.AnchorStyles.Right)));
    175       this.pictureBox.BackColor = System.Drawing.Color.White;
    176       this.pictureBox.BorderStyle = System.Windows.Forms.BorderStyle.FixedSingle;
    177       this.pictureBox.Location = new System.Drawing.Point(84, 6);
    178       this.pictureBox.Name = "pictureBox";
    179       this.pictureBox.Size = new System.Drawing.Size(438, 269);
    180       this.pictureBox.TabIndex = 0;
    181       this.pictureBox.TabStop = false;
    182       this.pictureBox.SizeChanged += new System.EventHandler(this.pictureBox_SizeChanged);
    183138      //
    184139      // valueTabPage
     
    222177      this.assignmentViewHost.ViewType = null;
    223178      //
    224       // redrawButton
    225       //
    226       this.redrawButton.Location = new System.Drawing.Point(4, 53);
    227       this.redrawButton.Name = "redrawButton";
    228       this.redrawButton.Size = new System.Drawing.Size(74, 23);
    229       this.redrawButton.TabIndex = 3;
    230       this.redrawButton.Text = "Redraw";
    231       this.redrawButton.UseVisualStyleBackColor = true;
    232       this.redrawButton.Click += new System.EventHandler(this.redrawButton_Click);
     179      // qapView
     180      //
     181      this.qapView.Anchor = ((System.Windows.Forms.AnchorStyles)((((System.Windows.Forms.AnchorStyles.Top | System.Windows.Forms.AnchorStyles.Bottom)
     182                  | System.Windows.Forms.AnchorStyles.Left)
     183                  | System.Windows.Forms.AnchorStyles.Right)));
     184      this.qapView.Assignment = null;
     185      this.qapView.Distances = null;
     186      this.qapView.Location = new System.Drawing.Point(0, 3);
     187      this.qapView.Name = "qapView";
     188      this.qapView.Size = new System.Drawing.Size(526, 278);
     189      this.qapView.TabIndex = 0;
     190      this.qapView.Weights = null;
    233191      //
    234192      // QAPAssignmentView
     
    246204      this.tabControl.ResumeLayout(false);
    247205      this.visualizationTabPage.ResumeLayout(false);
    248       this.visualizationTabPage.PerformLayout();
    249       ((System.ComponentModel.ISupportInitialize)(this.pictureBox)).EndInit();
    250206      this.valueTabPage.ResumeLayout(false);
    251207      this.assignmentGroupBox.ResumeLayout(false);
     
    261217    private MainForm.WindowsForms.DragOverTabControl tabControl;
    262218    private System.Windows.Forms.TabPage visualizationTabPage;
    263     private System.Windows.Forms.PictureBox pictureBox;
    264219    private System.Windows.Forms.TabPage valueTabPage;
    265220    private System.Windows.Forms.GroupBox assignmentGroupBox;
    266221    private MainForm.WindowsForms.ViewHost assignmentViewHost;
    267     private System.Windows.Forms.RadioButton distancesRadioButton;
    268     private System.Windows.Forms.RadioButton weightsRadioButton;
    269     private System.Windows.Forms.Button redrawButton;
     222    private QAPView qapView;
    270223  }
    271224}
  • branches/QAP/HeuristicLab.Problems.QuadraticAssignment.Views/3.3/QAPAssignmentView.cs

    r5641 r5648  
    2020#endregion
    2121
    22 using System;
    2322using System.ComponentModel;
    24 using System.Drawing;
    25 using System.Globalization;
    2623using System.Windows.Forms;
    2724using HeuristicLab.Core.Views;
    28 using HeuristicLab.Data;
    29 using HeuristicLab.Encodings.PermutationEncoding;
    3025using HeuristicLab.MainForm;
    3126
     
    3732  [Content(typeof(QAPAssignment), true)]
    3833  public sealed partial class QAPAssignmentView : ItemView {
    39     private Bitmap bitmap;
    40 
    4134    public new QAPAssignment Content {
    4235      get { return (QAPAssignment)base.Content; }
     
    6457      if (Content == null) {
    6558        qualityViewHost.Content = null;
    66         pictureBox.Image = null;
    6759        assignmentViewHost.Content = null;
     60        qapView.Distances = null;
     61        qapView.Weights = null;
     62        qapView.Assignment = null;
    6863      } else {
    6964        qualityViewHost.Content = Content.Quality;
    70         GenerateImage();
    7165        assignmentViewHost.Content = Content.Assignment;
     66        qapView.Distances = Content.Distances;
     67        qapView.Weights = Content.Weights;
     68        qapView.Assignment = Content.Assignment;
    7269      }
    7370    }
     
    7673      base.SetEnabledStateOfControls();
    7774      qualityGroupBox.Enabled = Content != null;
    78       pictureBox.Enabled = Content != null;
    7975      assignmentGroupBox.Enabled = Content != null;
    80       distancesRadioButton.Enabled = Content != null;
    81       weightsRadioButton.Enabled = Content != null;
    82       redrawButton.Enabled = Content != null;
    83     }
    84 
    85     private void GenerateImage() {
    86       if ((pictureBox.Width > 0) && (pictureBox.Height > 0)) {
    87         if (Content == null) {
    88           pictureBox.Image = null;
    89           if (bitmap != null) bitmap.Dispose();
    90           bitmap = null;
    91         } else {
    92           bool drawDistances = distancesRadioButton.Checked;
    93           DoubleMatrix coordinates = Content.Coordinates;
    94           DoubleMatrix distances = Content.Distances;
    95 
    96           if ((coordinates == null || coordinates.Rows == 0)
    97             && (distances == null || distances.Rows == 0)) {
    98             Bitmap newBitmap = new Bitmap(pictureBox.Width, pictureBox.Height);
    99             using (Graphics g = Graphics.FromImage(newBitmap)) {
    100               string str = "No coordinates and no distance matrix specified.";
    101               SizeF strSize = g.MeasureString(str, Font);
    102               g.DrawString(str, Font, Brushes.Black, (float)(newBitmap.Width - strSize.Width) / 2.0f, (float)(newBitmap.Height - strSize.Height) / 2.0f);
    103             }
    104             pictureBox.Image = newBitmap;
    105             if (bitmap != null) bitmap.Dispose();
    106             bitmap = newBitmap;
    107           } else {
    108             if ((coordinates == null || coordinates.Rows == 0)
    109               && Content.ViewCoordinates == null) {
    110               coordinates = GetCoordinatesByMDS(distances);
    111               Content.ViewCoordinates = coordinates;
    112             } else if ((coordinates == null || coordinates.Rows == 0)
    113               && Content.ViewCoordinates != null) {
    114               coordinates = Content.ViewCoordinates;
    115             }
    116 
    117             DoubleMatrix weights = Content.Weights;
    118             Permutation assignment = Content.Assignment;
    119 
    120             GenerateImage(drawDistances, coordinates, distances, weights, assignment);
    121           }
    122         }
    123       }
    124     }
    125 
    126     private void GenerateImage(bool drawDistances, DoubleMatrix coordinates, DoubleMatrix distances, DoubleMatrix weights, Permutation assignment) {
    127       Bitmap newBitmap = new Bitmap(pictureBox.Width, pictureBox.Height);
    128       double xMin = double.MaxValue, yMin = double.MaxValue, xMax = double.MinValue, yMax = double.MinValue;
    129       double maxWeight = double.MinValue, maxDistance = double.MinValue;
    130       for (int i = 0; i < coordinates.Rows; i++) {
    131         if (xMin > coordinates[i, 0]) xMin = coordinates[i, 0];
    132         if (yMin > coordinates[i, 1]) yMin = coordinates[i, 1];
    133         if (xMax < coordinates[i, 0]) xMax = coordinates[i, 0];
    134         if (yMax < coordinates[i, 1]) yMax = coordinates[i, 1];
    135 
    136         for (int j = i + 1; j < coordinates.Rows; j++) {
    137           if (weights[i, j] + weights[j, i] > maxWeight)
    138             maxWeight = weights[i, j] + weights[j, i];
    139 
    140           if (distances[i, j] > maxDistance)
    141             maxDistance = distances[i, j];
    142           else if (distances[j, i] > maxDistance)
    143             maxDistance = distances[j, i];
    144         }
    145       }
    146 
    147       int border = 20;
    148       double xStep = xMax != xMin ? (pictureBox.Width - 2 * border) / (xMax - xMin) : 1;
    149       double yStep = yMax != yMin ? (pictureBox.Height - 2 * border) / (yMax - yMin) : 1;
    150 
    151       Point[] points = new Point[coordinates.Rows];
    152       for (int i = 0; i < coordinates.Rows; i++)
    153         points[i] = new Point(border + ((int)((coordinates[i, 0] - xMin) * xStep)),
    154                               newBitmap.Height - (border + ((int)((coordinates[i, 1] - yMin) * yStep))));
    155 
    156       Random rand = new Random();
    157       using (Graphics graphics = Graphics.FromImage(newBitmap)) {
    158         graphics.SmoothingMode = System.Drawing.Drawing2D.SmoothingMode.AntiAlias;
    159         graphics.TextRenderingHint = System.Drawing.Text.TextRenderingHint.AntiAlias;
    160         if ((assignment != null) && (assignment.Length == coordinates.Rows) && (assignment.Validate())) {
    161           for (int i = 0; i < assignment.Length - 1; i++) {
    162             for (int j = i + 1; j < assignment.Length; j++) {
    163               Point start, end;
    164               string caption = String.Empty;
    165               double d = Math.Max(distances[i, j], distances[j, i]);
    166               if (drawDistances) {
    167                 start = points[i];
    168                 end = points[j];
    169                 float width = (float)Math.Ceiling(5.0 * d / maxDistance);
    170                 graphics.DrawLine(new Pen(Color.IndianRed, width), start, end);
    171                 if (distances[i, j] != distances[j, i])
    172                   caption = distances[i, j].ToString(CultureInfo.InvariantCulture.NumberFormat)
    173                     + " / " + distances[j, i].ToString(CultureInfo.InvariantCulture.NumberFormat);
    174                 else
    175                   caption = distances[i, j].ToString(CultureInfo.InvariantCulture.NumberFormat);
    176               } else {
    177                 start = points[assignment[i]];
    178                 end = points[assignment[j]];
    179                 double w = weights[i, j] + weights[j, i];
    180                 if (w > 0) {
    181                   float width = (float)Math.Ceiling(5.0 * w / maxWeight);
    182                   graphics.DrawLine(new Pen(Color.MediumBlue, width), start, end);
    183                   caption = w.ToString(CultureInfo.InvariantCulture.NumberFormat);
    184                 }
    185                 if (!String.IsNullOrEmpty(caption)) {
    186                   double r = rand.NextDouble();
    187                   while (r < 0.2 || r > 0.8) r = rand.NextDouble();
    188                   float x = (float)(start.X + (end.X - start.X) * r + 5);
    189                   float y = (float)(start.Y + (end.Y - start.Y) * r + 5);
    190                   graphics.DrawString(caption, Font, Brushes.Black, x, y);
    191                 }
    192               }
    193             }
    194           }
    195         }
    196         for (int i = 0; i < points.Length; i++) {
    197           Point p = new Point(points[assignment[i]].X - 3, points[assignment[i]].Y - 3);
    198           graphics.FillRectangle(Brushes.Black, p.X, p.Y, 8, 8);
    199           graphics.DrawString(i.ToString(), Font, Brushes.Black, p.X, p.Y + 10);
    200         }
    201       }
    202       pictureBox.Image = newBitmap;
    203       if (bitmap != null) bitmap.Dispose();
    204       bitmap = newBitmap;
    205     }
    206 
    207     private DoubleMatrix GetCoordinatesByMDS(DoubleMatrix distances) {
    208       /*Random random = new Random();
    209       int points = distances.Rows;
    210       DoubleMatrix coordinates = new DoubleMatrix(points, 2);
    211       double rad = (2 * Math.PI) / coordinates.Rows;
    212       for (int i = 0; i < coordinates.Rows; i++) {
    213         coordinates[i, 0] = 10 * Math.Cos(rad * i);
    214         coordinates[i, 1] = 10 * Math.Sin(rad * i);
    215       }
    216       for (int iterations = 0; iterations < 1000; iterations++) {
    217         for (int i = 0; i < points; i++) {
    218           double x = coordinates[i, 0], y = coordinates[i, 1];
    219           for (int j = 0; j < points; j++) {
    220             if (i != j) {
    221               double dx = coordinates[i, 0] - coordinates[j, 0];
    222               double dy = coordinates[i, 1] - coordinates[j, 1];
    223               double l = Math.Sqrt(dx * dx + dy * dy);
    224               double dl = distances[i, j];
    225               if (Math.Abs(dx) < double.Epsilon) dx = random.NextDouble() + 1;
    226               if (Math.Abs(dy) < double.Epsilon) dy = random.NextDouble() + 1;
    227               x += random.NextDouble() * ((coordinates[j, 0] + (dx / l) * dl) - x);
    228               y += random.NextDouble() * ((coordinates[j, 1] + (dy / l) * dl) - y);
    229             }
    230           }
    231           coordinates[i, 0] = x;
    232           coordinates[i, 1] = y;
    233         }
    234         Content.ViewCoordinates = coordinates;
    235       }
    236       return coordinates;*/
    237       double error;
    238       return MultidimensionalScaling.Classic(distances, out error);
     76      qapView.Enabled = Content != null;
    23977    }
    24078
     
    24583        switch (e.PropertyName) {
    24684          case "Coordinates":
     85            break;
    24786          case "Distances":
     87            qapView.Distances = Content.Distances;
     88            break;
    24889          case "Weights":
    249             GenerateImage();
    250             break;
    251           case "Assignment":
    252             GenerateImage();
    253             assignmentViewHost.Content = Content.Assignment;
     90            qapView.Weights = Content.Weights;
    25491            break;
    25592          case "Quality":
    25693            break;
    257           case "ViewCoordinates":
    258             if (Content.ViewCoordinates != null)
    259               GenerateImage(distancesRadioButton.Checked, Content.ViewCoordinates, Content.Distances, Content.Weights, Content.Assignment);
     94          case "Assignment":
     95            assignmentViewHost.Content = Content.Assignment;
     96            qapView.Assignment = Content.Assignment;
    26097            break;
    26198          default:
     
    264101      }
    265102    }
    266 
    267     private void pictureBox_SizeChanged(object sender, EventArgs e) {
    268       GenerateImage();
    269     }
    270 
    271     private void radioButton_CheckedChanged(object sender, EventArgs e) {
    272       GenerateImage();
    273     }
    274 
    275     private void redrawButton_Click(object sender, EventArgs e) {
    276       Content.ViewCoordinates = null;
    277       GenerateImage();
    278     }
    279103  }
    280104}
  • branches/QAP/HeuristicLab.Problems.QuadraticAssignment.Views/3.3/QAPView.Designer.cs

    r5641 r5648  
    5050      this.weightsRadioButton = new System.Windows.Forms.RadioButton();
    5151      this.pictureBox = new System.Windows.Forms.PictureBox();
    52       this.errorLabel = new System.Windows.Forms.Label();
     52      this.stressLabel = new System.Windows.Forms.Label();
    5353      this.assignmentRadioButton = new System.Windows.Forms.RadioButton();
     54      this.label1 = new System.Windows.Forms.Label();
    5455      ((System.ComponentModel.ISupportInitialize)(this.pictureBox)).BeginInit();
    5556      this.SuspendLayout();
     
    101102      this.pictureBox.TabIndex = 4;
    102103      this.pictureBox.TabStop = false;
     104      this.pictureBox.SizeChanged += new System.EventHandler(this.pictureBox_SizeChanged);
    103105      //
    104       // errorLabel
     106      // stressLabel
    105107      //
    106       this.errorLabel.Anchor = ((System.Windows.Forms.AnchorStyles)((System.Windows.Forms.AnchorStyles.Top | System.Windows.Forms.AnchorStyles.Right)));
    107       this.errorLabel.AutoSize = true;
    108       this.errorLabel.Location = new System.Drawing.Point(323, 10);
    109       this.errorLabel.Name = "errorLabel";
    110       this.errorLabel.Size = new System.Drawing.Size(38, 13);
    111       this.errorLabel.TabIndex = 8;
    112       this.errorLabel.Text = "Error: -";
     108      this.stressLabel.AutoSize = true;
     109      this.stressLabel.Location = new System.Drawing.Point(423, 8);
     110      this.stressLabel.Name = "stressLabel";
     111      this.stressLabel.Size = new System.Drawing.Size(10, 13);
     112      this.stressLabel.TabIndex = 8;
     113      this.stressLabel.Text = "-";
    113114      //
    114115      // assignmentRadioButton
     
    123124      this.assignmentRadioButton.CheckedChanged += new System.EventHandler(this.Redraw);
    124125      //
     126      // label1
     127      //
     128      this.label1.AutoSize = true;
     129      this.label1.Location = new System.Drawing.Point(323, 8);
     130      this.label1.Name = "label1";
     131      this.label1.Size = new System.Drawing.Size(94, 13);
     132      this.label1.TabIndex = 8;
     133      this.label1.Text = "Normalized Stress:";
     134      //
    125135      // QAPView
    126136      //
    127137      this.AutoScaleDimensions = new System.Drawing.SizeF(6F, 13F);
    128138      this.AutoScaleMode = System.Windows.Forms.AutoScaleMode.Font;
    129       this.Controls.Add(this.errorLabel);
     139      this.Controls.Add(this.label1);
     140      this.Controls.Add(this.stressLabel);
    130141      this.Controls.Add(this.redrawButton);
    131142      this.Controls.Add(this.distancesRadioButton);
     
    147158    private System.Windows.Forms.RadioButton weightsRadioButton;
    148159    private System.Windows.Forms.PictureBox pictureBox;
    149     private System.Windows.Forms.Label errorLabel;
     160    private System.Windows.Forms.Label stressLabel;
    150161    private System.Windows.Forms.RadioButton assignmentRadioButton;
     162    private System.Windows.Forms.Label label1;
    151163
    152164  }
  • branches/QAP/HeuristicLab.Problems.QuadraticAssignment.Views/3.3/QAPView.cs

    r5641 r5648  
    3535    private Bitmap defaultBitmap;
    3636
     37    #region Properties
    3738    private DoubleMatrix distances;
    3839    public DoubleMatrix Distances {
     
    6768      }
    6869    }
    69 
     70    #endregion
     71
     72    #region Event Handling
    7073    private void DeregisterDistancesEvents() {
    7174      if (Distances != null) {
     
    128131    }
    129132
     133    private void pictureBox_SizeChanged(object sender, EventArgs e) {
     134      SetupDefaultBitmap();
     135      OnRedraw();
     136    }
     137    #endregion
     138
    130139    public QAPView() {
    131140      InitializeComponent();
    132141      SetupDefaultBitmap();
    133       pictureBox.Resize += new EventHandler(pictureBox_Resize);
    134     }
    135 
    136     private void pictureBox_Resize(object sender, EventArgs e) {
    137       SetupDefaultBitmap();
    138142    }
    139143
     
    141145      if (defaultBitmap != null) defaultBitmap.Dispose();
    142146      defaultBitmap = new Bitmap(pictureBox.Width, pictureBox.Height);
    143       using (Graphics g = Graphics.FromImage(defaultBitmap)) {
     147      WriteCenteredTextToBitmap(ref defaultBitmap, "No visualization available");
     148    }
     149
     150    private void WriteCenteredTextToBitmap(ref Bitmap bitmap, string text) {
     151      using (Graphics g = Graphics.FromImage(bitmap)) {
    144152        g.TextRenderingHint = TextRenderingHint.AntiAlias;
    145153        g.SmoothingMode = SmoothingMode.AntiAlias;
    146154
    147         string msg = "No visualization available";
    148         SizeF strSize = g.MeasureString(msg, Font);
    149         g.DrawString(msg, Font, Brushes.Black, (float)(pictureBox.Width - strSize.Width) / 2.0f, (float)(pictureBox.Height - strSize.Height) / 2.0f);
     155        SizeF strSize = g.MeasureString(text, Font);
     156        g.DrawString(text, Font, Brushes.Black, (float)(pictureBox.Width - strSize.Width) / 2.0f, (float)(pictureBox.Height - strSize.Height) / 2.0f);
    150157      }
    151158    }
     
    161168    private void GenerateImage() {
    162169      Bitmap newBitmap = null;
    163       errorLabel.Text = "Error: -";
     170      stressLabel.Text = "-";
    164171      if (distancesRadioButton.Checked && Distances != null && Distances.Rows > 0
    165172        && Distances.Rows == Distances.Columns) {
    166         newBitmap = GenerateDistanceImage();
     173        if (Distances.Rows > 30) {
     174          newBitmap = new Bitmap(pictureBox.Width, pictureBox.Height);
     175          WriteCenteredTextToBitmap(ref newBitmap, "Problem dimension too large for visualization.");
     176        } else newBitmap = GenerateDistanceImage();
    167177      } else if (weightsRadioButton.Checked && Weights != null && Weights.Rows > 0
    168178        && Weights.Rows == Weights.Columns) {
    169         newBitmap = GenerateWeightsImage();
     179        if (Weights.Rows > 30) {
     180          newBitmap = new Bitmap(pictureBox.Width, pictureBox.Height);
     181          WriteCenteredTextToBitmap(ref newBitmap, "Problem dimension too large for visualization.");
     182        } else newBitmap = GenerateWeightsImage();
    170183      } else if (assignmentRadioButton.Checked
    171184        && Assignment != null && Assignment.Length > 0
     
    175188        && Distances.Rows == Distances.Columns
    176189        && Assignment.Length == Weights.Rows
    177         && Assignment.Length == Distances.Rows) {
     190        && Assignment.Length == Distances.Rows
     191        && Assignment.Validate()) {
    178192        newBitmap = GenerateAssignmentImage();
    179193      }
     
    181195      pictureBox.Image = newBitmap != null ? newBitmap : defaultBitmap;
    182196      if (bitmap != null) bitmap.Dispose();
    183       bitmap = newBitmap;
    184     }
    185 
     197      if (newBitmap != null) bitmap = newBitmap;
     198      else bitmap = null;
     199    }
     200
     201    #region Draw distances
    186202    private Bitmap GenerateDistanceImage() {
    187203      if ((pictureBox.Width > 0) && (pictureBox.Height > 0)) {
    188204        Bitmap newBitmap = new Bitmap(pictureBox.Width, pictureBox.Height);
    189205
    190         double error;
    191         DoubleMatrix coordinates = MultidimensionalScaling.Metric(distances, out error);
    192         errorLabel.Text = "Error: " + error.ToString(CultureInfo.CurrentCulture.NumberFormat);
     206        for (int i = 0; i < distances.Rows; i++) {
     207          for (int j = i + 1; j < distances.Rows; j++)
     208            if (distances[i, j] != distances[j, i]) {
     209              WriteCenteredTextToBitmap(ref newBitmap, "Distance matrix is not symmetric");
     210              return newBitmap;
     211            }
     212        }
     213
     214        double stress;
     215        DoubleMatrix coordinates = MultidimensionalScaling.MetricByDistance(distances, out stress);
     216        stressLabel.Text = stress.ToString("0.00", CultureInfo.CurrentCulture.NumberFormat);
    193217        double xMin = double.MaxValue, yMin = double.MaxValue, xMax = double.MinValue, yMax = double.MinValue;
    194218        double maxDistance = double.MinValue;
     
    214238                                newBitmap.Height - (border + ((int)((coordinates[i, 1] - yMin) * yStep))));
    215239
     240        Random rand = new Random();
    216241        using (Graphics graphics = Graphics.FromImage(newBitmap)) {
    217242          graphics.SmoothingMode = SmoothingMode.AntiAlias;
    218243          graphics.TextRenderingHint = TextRenderingHint.AntiAlias;
    219           graphics.DrawString("Showing Locations spaced out according to their distances", Font, Brushes.Black, 5, 2);
     244          graphics.DrawString("Showing locations spaced out according to their distances", Font, Brushes.Black, 5, 2);
    220245
    221246          for (int i = 0; i < coordinates.Rows - 1; i++) {
     
    233258                  caption = distances[i, j].ToString(CultureInfo.InvariantCulture.NumberFormat);
    234259              }
     260              if (!String.IsNullOrEmpty(caption)) {
     261                double r = rand.NextDouble();
     262                while (r < 0.2 || r > 0.8) r = rand.NextDouble();
     263                float x = (float)(start.X + (end.X - start.X) * r + 5);
     264                float y = (float)(start.Y + (end.Y - start.Y) * r + 5);
     265                graphics.DrawString(caption, Font, Brushes.Black, x, y);
     266              }
    235267            }
    236268          }
     
    246278      return null;
    247279    }
    248 
     280    #endregion
     281
     282    #region Draw weights
    249283    private Bitmap GenerateWeightsImage() {
    250284      if ((pictureBox.Width > 0) && (pictureBox.Height > 0)) {
    251285        Bitmap newBitmap = new Bitmap(pictureBox.Width, pictureBox.Height);
    252286
    253         double error;
    254         DoubleMatrix coordinates = MultidimensionalScaling.Classic(weights, out error);
    255         errorLabel.Text = "Error: " + error.ToString(CultureInfo.CurrentCulture.NumberFormat);
     287        double maxWeight = double.MinValue;
     288        for (int i = 0; i < weights.Rows; i++)
     289          for (int j = i + 1; j < weights.Rows; j++) {
     290            if (weights[i, j] > maxWeight)
     291              maxWeight = weights[i, j] + weights[j, i];
     292
     293            if (weights[i, j] != weights[j, i]) {
     294              WriteCenteredTextToBitmap(ref newBitmap, "Weights matrix is not symmetric");
     295              return newBitmap;
     296            }
     297          }
     298
     299        DoubleMatrix distances = new DoubleMatrix(weights.Rows, weights.Columns);
     300        for (int i = 0; i < distances.Rows; i++)
     301          for (int j = 0; j < distances.Columns; j++) {
     302            distances[i, j] = maxWeight + 1 - weights[i, j];
     303          }
     304
     305        double stress;
     306        DoubleMatrix coordinates = MultidimensionalScaling.MetricByDistance(distances, out stress);
     307        stressLabel.Text = stress.ToString("0.00", CultureInfo.CurrentCulture.NumberFormat);
     308        double xMin = double.MaxValue, yMin = double.MaxValue, xMax = double.MinValue, yMax = double.MinValue;
     309        for (int i = 0; i < coordinates.Rows; i++) {
     310          if (xMin > coordinates[i, 0]) xMin = coordinates[i, 0];
     311          if (yMin > coordinates[i, 1]) yMin = coordinates[i, 1];
     312          if (xMax < coordinates[i, 0]) xMax = coordinates[i, 0];
     313          if (yMax < coordinates[i, 1]) yMax = coordinates[i, 1];
     314        }
     315
     316        int border = 20;
     317        double xStep = xMax != xMin ? (pictureBox.Width - 2 * border) / (xMax - xMin) : 1;
     318        double yStep = yMax != yMin ? (pictureBox.Height - 2 * border) / (yMax - yMin) : 1;
     319
     320        Point[] points = new Point[coordinates.Rows];
     321        for (int i = 0; i < coordinates.Rows; i++)
     322          points[i] = new Point(border + ((int)((coordinates[i, 0] - xMin) * xStep)),
     323                                newBitmap.Height - (border + ((int)((coordinates[i, 1] - yMin) * yStep))));
     324
     325        Random rand = new Random();
     326        using (Graphics graphics = Graphics.FromImage(newBitmap)) {
     327          graphics.SmoothingMode = SmoothingMode.AntiAlias;
     328          graphics.TextRenderingHint = TextRenderingHint.AntiAlias;
     329          graphics.DrawString("Showing facilities spaced out according to their weights", Font, Brushes.Black, 5, 2);
     330
     331          for (int i = 0; i < coordinates.Rows - 1; i++) {
     332            for (int j = i + 1; j < coordinates.Rows; j++) {
     333              Point start = points[i], end = points[j];
     334              string caption = String.Empty;
     335              double d = Math.Max(distances[i, j], distances[j, i]);
     336              double w = weights[i, j];
     337              if (w > 0) {
     338                float width = (float)Math.Ceiling(3.0 * w / maxWeight);
     339                graphics.DrawLine(new Pen(Color.MediumBlue, width), start, end);
     340                caption = w.ToString(CultureInfo.InvariantCulture.NumberFormat);
     341              }
     342              if (!String.IsNullOrEmpty(caption)) {
     343                double r = rand.NextDouble();
     344                while (r < 0.2 || r > 0.8) r = rand.NextDouble();
     345                float x = (float)(start.X + (end.X - start.X) * r + 5);
     346                float y = (float)(start.Y + (end.Y - start.Y) * r + 5);
     347                graphics.DrawString(caption, Font, Brushes.Black, x, y);
     348              }
     349            }
     350          }
     351          for (int i = 0; i < points.Length; i++) {
     352            Point p = new Point(points[i].X - 3, points[i].Y - 3);
     353            graphics.FillRectangle(Brushes.Black, p.X, p.Y, 8, 8);
     354            graphics.DrawString(i.ToString(), Font, Brushes.Black, p.X, p.Y + 10);
     355          }
     356        }
     357        return newBitmap;
     358      }
     359      return null;
     360    }
     361    #endregion
     362
     363    #region Draw assignment
     364    private Bitmap GenerateAssignmentImage() {
     365      if ((pictureBox.Width > 0) && (pictureBox.Height > 0)) {
     366        Bitmap newBitmap = new Bitmap(pictureBox.Width, pictureBox.Height);
     367
     368        for (int i = 0; i < distances.Rows; i++) {
     369          for (int j = i + 1; j < distances.Rows; j++) {
     370            if (distances[i, j] != distances[j, i]) {
     371              WriteCenteredTextToBitmap(ref newBitmap, "Distance matrix is not symmetric");
     372              return newBitmap;
     373            }
     374            if (weights[i, j] != weights[j, i]) {
     375              WriteCenteredTextToBitmap(ref newBitmap, "Weights matrix is not symmetric");
     376            }
     377          }
     378        }
     379
     380        double stress;
     381        DoubleMatrix coordinates = MultidimensionalScaling.MetricByDistance(distances, out stress);
     382        stressLabel.Text = stress.ToString("0.00", CultureInfo.CurrentCulture.NumberFormat);
    256383        double xMin = double.MaxValue, yMin = double.MaxValue, xMax = double.MinValue, yMax = double.MinValue;
    257384        double maxWeight = double.MinValue;
     
    263390
    264391          for (int j = i + 1; j < coordinates.Rows; j++) {
    265             if (weights[i, j] + weights[j, i] > maxWeight)
    266               maxWeight = weights[i, j] + weights[j, i];
     392            if (weights[i, j] > maxWeight) maxWeight = weights[i, j];
    267393          }
    268394        }
     
    279405        Random rand = new Random();
    280406        using (Graphics graphics = Graphics.FromImage(newBitmap)) {
    281           graphics.SmoothingMode = SmoothingMode.AntiAlias;
    282           graphics.TextRenderingHint = TextRenderingHint.AntiAlias;
    283           graphics.DrawString("Showing Facilities spaced out according to their weights", Font, Brushes.Black, 5, 2);
    284 
    285           for (int i = 0; i < coordinates.Rows - 1; i++) {
    286             for (int j = i + 1; j < coordinates.Rows; j++) {
    287               Point start = points[i], end = points[j];
     407          graphics.SmoothingMode = System.Drawing.Drawing2D.SmoothingMode.AntiAlias;
     408          graphics.TextRenderingHint = System.Drawing.Text.TextRenderingHint.AntiAlias;
     409
     410          for (int i = 0; i < assignment.Length - 1; i++) {
     411            for (int j = i + 1; j < assignment.Length; j++) {
     412              Point start, end;
    288413              string caption = String.Empty;
    289               double d = Math.Max(distances[i, j], distances[j, i]);
    290               double w = weights[i, j] + weights[j, i];
     414              double d = distances[i, j];
     415              start = points[assignment[i]];
     416              end = points[assignment[j]];
     417              double w = weights[i, j];
    291418              if (w > 0) {
    292                 float width = (float)Math.Ceiling(3.0 * w / maxWeight);
     419                float width = (float)Math.Ceiling(4.0 * w / maxWeight);
    293420                graphics.DrawLine(new Pen(Color.MediumBlue, width), start, end);
    294421                caption = w.ToString(CultureInfo.InvariantCulture.NumberFormat);
     
    303430            }
    304431          }
     432
    305433          for (int i = 0; i < points.Length; i++) {
    306434            Point p = new Point(points[i].X - 3, points[i].Y - 3);
     
    313441      return null;
    314442    }
    315 
    316     private Bitmap GenerateAssignmentImage() {
    317       return null;
    318     }
     443    #endregion
    319444
    320445    private void CustomDispose(bool disposing) {
  • branches/QAP/HeuristicLab.Problems.QuadraticAssignment/3.3/Parsers/QAPLIBParser.cs

    r5563 r5648  
    4141        Distances = new double[Size, Size];
    4242        Weights = new double[Size, Size];
    43         reader.ReadLine();
     43        string valLine = reader.ReadLine();
    4444        char[] delim = new char[] { ' ' };
    4545        for (int i = 0; i < Size; i++) {
    46           string valLine = reader.ReadLine();
     46          if (i > 0 || String.IsNullOrWhiteSpace(valLine))
     47            valLine = reader.ReadLine();
    4748          string[] vals = new string[Size];
    4849          string[] partVals = valLine.Split(delim, StringSplitOptions.RemoveEmptyEntries);
     
    5960          }
    6061        }
    61         reader.ReadLine();
     62        valLine = reader.ReadLine();
    6263        int read = 0;
    6364        int k = 0;
    6465        while (!reader.EndOfStream) {
    65           string valLine = reader.ReadLine();
     66          if (read > 0 || String.IsNullOrWhiteSpace(valLine))
     67            valLine = reader.ReadLine();
    6668          string[] vals = valLine.Split(delim, StringSplitOptions.RemoveEmptyEntries);
    6769          for (int j = 0; j < vals.Length; j++) {
  • branches/QAP/HeuristicLab.Problems.QuadraticAssignment/3.3/Parsers/QAPLIBSolutionParser.cs

    r5598 r5648  
    3838      try {
    3939        StreamReader reader = new StreamReader(stream);
    40         char[] delim = new char[] { ' ' };
     40        char[] delim = new char[] { ' ', ',' }; // comma is added for nug30.sln which is the only file that separates the permutation with commas
    4141        string[] firstline = reader.ReadLine().Split(delim, StringSplitOptions.RemoveEmptyEntries);
    4242        Size = int.Parse(firstline[0]);
  • branches/QAP/HeuristicLab.Problems.QuadraticAssignment/3.3/QAPAssignment.cs

    r5641 r5648  
    1818        coordinates = value;
    1919        if (changed) OnPropertyChanged("Coordinates");
    20       }
    21     }
    22 
    23     [Storable]
    24     private DoubleMatrix viewCoordinates;
    25     public DoubleMatrix ViewCoordinates {
    26       get { return viewCoordinates; }
    27       set {
    28         bool changed = (viewCoordinates != value);
    29         viewCoordinates = value;
    30         if (changed) OnPropertyChanged("ViewCoordinates");
    3120      }
    3221    }
     
    8574      assignment = cloner.Clone(original.assignment);
    8675      quality = cloner.Clone(original.quality);
    87       viewCoordinates = cloner.Clone(original.viewCoordinates);
    8876    }
    8977    public QAPAssignment(DoubleMatrix weights, Permutation assignment) {
  • branches/QAP/HeuristicLab.Problems.QuadraticAssignment/3.3/QuadraticAssignmentProblem.cs

    r5641 r5648  
    103103    public QuadraticAssignmentProblem()
    104104      : base() {
    105       Parameters.Add(new ValueParameter<Permutation>("BestKnownSolution", "The best known solution which is updated whenever a new better solution is found or may be the optimal solution if it is known beforehand.", null));
     105      Parameters.Add(new OptionalValueParameter<Permutation>("BestKnownSolution", "The best known solution which is updated whenever a new better solution is found or may be the optimal solution if it is known beforehand.", null));
    106106      Parameters.Add(new ValueParameter<DoubleMatrix>("Coordinates", "The coordinates of the locations. If this is changed the distance matrix is calculated automatically using the euclidean distance."));
    107107      Parameters.Add(new ValueParameter<DoubleMatrix>("Weights", "The strength of the connection between the facilities.", new DoubleMatrix(5, 5)));
     
    272272    private void UpdateDistanceMatrix() {
    273273      if (Coordinates != null && Coordinates.Columns == 2 && Coordinates.Rows > 1) {
    274         DistanceMatrix = new DoubleMatrix(Coordinates.Rows, Coordinates.Rows);
     274        DoubleMatrix distance = new DoubleMatrix(Coordinates.Rows, Coordinates.Rows);
    275275        for (int i = 0; i < Coordinates.Rows - 1; i++) {
    276276          for (int j = i + 1; j < Coordinates.Rows; j++) {
    277277            double dx = Coordinates[i, 0] - Coordinates[j, 0];
    278278            double dy = Coordinates[i, 1] - Coordinates[j, 1];
    279             DistanceMatrix[i, j] = Math.Sqrt(dx * dx + dy * dy);
    280             DistanceMatrix[j, i] = DistanceMatrix[i, j];
     279            distance[i, j] = Math.Sqrt(dx * dx + dy * dy);
     280            distance[j, i] = DistanceMatrix[i, j];
    281281          }
    282282        }
     283        DistanceMatrix = distance;
    283284      }
    284285    }
  • branches/QAP/QAP.sln

    r5563 r5648  
    66Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "HeuristicLab.Problems.QuadraticAssignment.Views-3.3", "HeuristicLab.Problems.QuadraticAssignment.Views\3.3\HeuristicLab.Problems.QuadraticAssignment.Views-3.3.csproj", "{997F018D-AEA2-4F21-9301-82FAF6A5612D}"
    77EndProject
     8Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "HeuristicLab.Problems.QuadraticAssignment.Tests-3.3", "HeuristicLab.Problems.QuadraticAssignment\3.3\Tests\HeuristicLab.Problems.QuadraticAssignment.Tests-3.3.csproj", "{00E73394-D41B-4C4F-963F-A59341FA1791}"
     9EndProject
     10Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "Solution Items", "Solution Items", "{2179B537-87D1-4AD9-B5FF-75447F08BDBD}"
     11  ProjectSection(SolutionItems) = preProject
     12    QAP.vsmdi = QAP.vsmdi
     13  EndProjectSection
     14EndProject
    815Global
     16  GlobalSection(TestCaseManagementSettings) = postSolution
     17    CategoryFile = QAP.vsmdi
     18  EndGlobalSection
    919  GlobalSection(SolutionConfigurationPlatforms) = preSolution
    1020    Debug|Any CPU = Debug|Any CPU
     
    4050    {997F018D-AEA2-4F21-9301-82FAF6A5612D}.Release|x86.ActiveCfg = Release|x86
    4151    {997F018D-AEA2-4F21-9301-82FAF6A5612D}.Release|x86.Build.0 = Release|x86
     52    {00E73394-D41B-4C4F-963F-A59341FA1791}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
     53    {00E73394-D41B-4C4F-963F-A59341FA1791}.Debug|Any CPU.Build.0 = Debug|Any CPU
     54    {00E73394-D41B-4C4F-963F-A59341FA1791}.Debug|x64.ActiveCfg = Debug|x64
     55    {00E73394-D41B-4C4F-963F-A59341FA1791}.Debug|x64.Build.0 = Debug|x64
     56    {00E73394-D41B-4C4F-963F-A59341FA1791}.Debug|x86.ActiveCfg = Debug|x86
     57    {00E73394-D41B-4C4F-963F-A59341FA1791}.Debug|x86.Build.0 = Debug|x86
     58    {00E73394-D41B-4C4F-963F-A59341FA1791}.Release|Any CPU.ActiveCfg = Release|Any CPU
     59    {00E73394-D41B-4C4F-963F-A59341FA1791}.Release|Any CPU.Build.0 = Release|Any CPU
     60    {00E73394-D41B-4C4F-963F-A59341FA1791}.Release|x64.ActiveCfg = Release|x64
     61    {00E73394-D41B-4C4F-963F-A59341FA1791}.Release|x64.Build.0 = Release|x64
     62    {00E73394-D41B-4C4F-963F-A59341FA1791}.Release|x86.ActiveCfg = Release|x86
     63    {00E73394-D41B-4C4F-963F-A59341FA1791}.Release|x86.Build.0 = Release|x86
    4264  EndGlobalSection
    4365  GlobalSection(SolutionProperties) = preSolution
Note: See TracChangeset for help on using the changeset viewer.