Free cookie consent management tool by TermsFeed Policy Generator

Changeset 8221 for trunk/sources


Ignore:
Timestamp:
07/04/12 23:54:15 (12 years ago)
Author:
abeham
Message:

#1396: fixed loading errors when switching from coordinates to distance matrix evaluation

Location:
trunk/sources/HeuristicLab.Problems.TravelingSalesman/3.3
Files:
2 edited

Legend:

Unmodified
Added
Removed
  • trunk/sources/HeuristicLab.Problems.TravelingSalesman/3.3/Evaluators/TSPDistanceMatrixEvaluator.cs

    r7558 r8221  
    5959      if (distances == null || distances.Rows == 0 || distances.Columns == 0
    6060        || distances.Rows != distances.Columns)
    61         throw new InvalidOperationException("The distance matrix is empty or not square");
    62       if (tour == null) throw new ArgumentNullException("tour", "No tour is given.");
     61        throw new InvalidOperationException("TSPDistanceMatrixEvaluator: The distance matrix is empty or not square");
     62      if (tour == null) throw new ArgumentNullException("tour", "TSPDistanceMatrixEvaluator: No tour is given.");
    6363      Permutation p = tour;
    6464      double length = 0;
  • trunk/sources/HeuristicLab.Problems.TravelingSalesman/3.3/TravelingSalesmanProblem.cs

    r8208 r8221  
    112112      Parameters.Add(new OptionalValueParameter<DoubleMatrix>("Coordinates", "The x- and y-Coordinates of the cities."));
    113113      Parameters.Add(new OptionalValueParameter<DistanceMatrix>("DistanceMatrix", "The matrix which contains the distances between the cities."));
    114       Parameters.Add(new ValueParameter<BoolValue>("UseDistanceMatrix", "True if a distance matrix should be calculated and used for evaluation, otherwise false.", new BoolValue(true)));
     114      Parameters.Add(new ValueParameter<BoolValue>("UseDistanceMatrix", "True if the coordinates based evaluators should calculate the distance matrix from the coordinates and use it for evaluation similar to the distance matrix evaluator, otherwise false.", new BoolValue(true)));
    115115      Parameters.Add(new OptionalValueParameter<Permutation>("BestKnownSolution", "The best known solution of this TSP instance."));
    116116
    117117      Maximization.Value = false;
    118118      MaximizationParameter.Hidden = true;
     119      UseDistanceMatrixParameter.Hidden = true;
    119120      DistanceMatrixParameter.ReactOnValueToStringChangedAndValueItemImageChanged = false;
    120121
     
    151152      UpdateMoveEvaluators();
    152153      ParameterizeAnalyzers();
    153       ClearDistanceMatrix();
     154      if (Evaluator is ITSPCoordinatesPathEvaluator && Coordinates != null)
     155        ClearDistanceMatrix();
    154156    }
    155157    private void CoordinatesParameter_ValueChanged(object sender, EventArgs e) {
     
    158160        Coordinates.Reset += new EventHandler(Coordinates_Reset);
    159161      }
    160       ParameterizeSolutionCreator();
    161       ClearDistanceMatrix();
     162      if (Evaluator is ITSPCoordinatesPathEvaluator) {
     163        ParameterizeSolutionCreator();
     164        ClearDistanceMatrix();
     165      }
    162166    }
    163167    private void Coordinates_ItemChanged(object sender, EventArgs<int, int> e) {
    164       ClearDistanceMatrix();
     168      if (Evaluator is ITSPCoordinatesPathEvaluator) {
     169        ClearDistanceMatrix();
     170      }
    165171    }
    166172    private void Coordinates_Reset(object sender, EventArgs e) {
    167       ParameterizeSolutionCreator();
    168       ClearDistanceMatrix();
     173      if (Evaluator is ITSPCoordinatesPathEvaluator) {
     174        ParameterizeSolutionCreator();
     175        ClearDistanceMatrix();
     176      }
    169177    }
    170178    private void SolutionCreator_PermutationParameter_ActualNameChanged(object sender, EventArgs e) {
     
    346354
    347355    private void ClearDistanceMatrix() {
    348       if (!(Evaluator is ITSPDistanceMatrixEvaluator))
    349         DistanceMatrixParameter.Value = null;
     356      DistanceMatrixParameter.Value = null;
    350357    }
    351358    #endregion
     
    365372      Description = data.Description;
    366373
     374      bool clearCoordinates = false, clearDistanceMatrix = false;
    367375      if (data.Coordinates != null && data.Coordinates.GetLength(0) > 0)
    368376        Coordinates = new DoubleMatrix(data.Coordinates);
    369       else Coordinates = null;
     377      else clearCoordinates = true;
    370378
    371379      TSPEvaluator evaluator;
     
    382390        DistanceMatrix = new DistanceMatrix(data.Distances);
    383391      } else {
    384         DistanceMatrix = null;
     392        clearDistanceMatrix = true;
    385393        UseDistanceMatrix = new BoolValue(data.Dimension <= DistanceMatrixSizeLimit);
    386394        switch (data.DistanceMeasure) {
     
    401409      Evaluator = evaluator;
    402410
     411      // reset them after assigning the evaluator
     412      if (clearCoordinates) Coordinates = null;
     413      if (clearDistanceMatrix) DistanceMatrix = null;
     414
    403415      BestKnownSolution = null;
    404416      BestKnownQuality = null;
Note: See TracChangeset for help on using the changeset viewer.