Free cookie consent management tool by TermsFeed Policy Generator

Ignore:
Timestamp:
03/29/11 16:54:52 (13 years ago)
Author:
abeham
Message:

#1330

  • Fixed normalized stress value
  • Changed method name and signature of MDS
  • Adapted unit tests
  • Adapted QAP View
File:
1 edited

Legend:

Unmodified
Added
Removed
  • branches/QAP/HeuristicLab.Problems.QuadraticAssignment.Views/3.3/QAPView.cs

    r5855 r5871  
    216216        Bitmap newBitmap = new Bitmap(pictureBox.Width, pictureBox.Height);
    217217
    218         for (int i = 0; i < distances.Rows; i++) {
    219           for (int j = i + 1; j < distances.Rows; j++)
    220             if (distances[i, j] != distances[j, i]) {
    221               WriteCenteredTextToBitmap(ref newBitmap, "Distance matrix is not symmetric");
    222               return newBitmap;
    223             }
    224         }
    225 
    226         double stress;
    227         DoubleMatrix coordinates = MultidimensionalScaling.MetricByDistance(distances, out stress);
    228         stressLabel.Text = stress.ToString("0.00", CultureInfo.CurrentCulture.NumberFormat);
     218        DoubleMatrix coordinates;
     219        double stress = double.NaN;
     220        try {
     221          coordinates = MultidimensionalScaling.KruskalShepard(distances);
     222          stress = MultidimensionalScaling.CalculateNormalizedStress(distances, coordinates);
     223          stressLabel.Text = stress.ToString("0.00", CultureInfo.CurrentCulture.NumberFormat);
     224        } catch {
     225          WriteCenteredTextToBitmap(ref newBitmap, "Distance matrix is not symmetric");
     226          stressLabel.Text = "-";
     227          return newBitmap;
     228        }
    229229        double xMin = double.MaxValue, yMin = double.MaxValue, xMax = double.MinValue, yMax = double.MinValue;
    230230        double maxDistance = double.MinValue;
     
    302302            if (weights[i, j] > maxWeight)
    303303              maxWeight = weights[i, j] + weights[j, i];
    304 
    305             if (weights[i, j] != weights[j, i]) {
    306               WriteCenteredTextToBitmap(ref newBitmap, "Weights matrix is not symmetric");
    307               return newBitmap;
    308             }
    309304          }
    310305
     
    315310          }
    316311
    317         double stress;
    318         DoubleMatrix coordinates = MultidimensionalScaling.MetricByDistance(distances, out stress);
    319         stressLabel.Text = stress.ToString("0.00", CultureInfo.CurrentCulture.NumberFormat);
     312        DoubleMatrix coordinates;
     313        double stress = double.NaN;
     314        try {
     315          coordinates = MultidimensionalScaling.KruskalShepard(distances);
     316          stress = MultidimensionalScaling.CalculateNormalizedStress(distances, coordinates);
     317          stressLabel.Text = stress.ToString("0.00", CultureInfo.CurrentCulture.NumberFormat);
     318        } catch {
     319          WriteCenteredTextToBitmap(ref newBitmap, "Weights matrix is not symmetric");
     320          stressLabel.Text = "-";
     321          return newBitmap;
     322        }
    320323        double xMin = double.MaxValue, yMin = double.MaxValue, xMax = double.MinValue, yMax = double.MinValue;
    321324        for (int i = 0; i < coordinates.Rows; i++) {
     
    382385            if (distances[i, j] != distances[j, i]) {
    383386              WriteCenteredTextToBitmap(ref newBitmap, "Distance matrix is not symmetric");
     387              stressLabel.Text = "-";
    384388              return newBitmap;
    385389            }
    386390            if (weights[i, j] != weights[j, i]) {
    387391              WriteCenteredTextToBitmap(ref newBitmap, "Weights matrix is not symmetric");
     392              stressLabel.Text = "-";
     393              return newBitmap;
    388394            }
    389395          }
    390396        }
    391397
    392         double stress;
    393         DoubleMatrix coordinates = MultidimensionalScaling.MetricByDistance(distances, out stress);
    394         stressLabel.Text = stress.ToString("0.00", CultureInfo.CurrentCulture.NumberFormat);
     398        DoubleMatrix coordinates = null;
     399        double stress = double.NaN;
     400        try {
     401          coordinates = MultidimensionalScaling.KruskalShepard(distances);
     402          stress = MultidimensionalScaling.CalculateNormalizedStress(distances, coordinates);
     403          stressLabel.Text = stress.ToString("0.00", CultureInfo.CurrentCulture.NumberFormat);
     404        } catch {
     405          WriteCenteredTextToBitmap(ref newBitmap, "Unknown error");
     406          stressLabel.Text = "-";
     407          return newBitmap;
     408        }
     409
    395410        double xMin = double.MaxValue, yMin = double.MaxValue, xMax = double.MinValue, yMax = double.MinValue;
    396411        double maxWeight = double.MinValue;
Note: See TracChangeset for help on using the changeset viewer.