Free cookie consent management tool by TermsFeed Policy Generator

Ignore:
Timestamp:
03/16/10 16:04:54 (14 years ago)
Author:
swagner
Message:

Implemented first version of distance matrix-based evaluation for the TSP (#912)

File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/sources/HeuristicLab.Problems.TSP/3.3/TSP.cs

    r3053 r3066  
    5252      get { return (ValueParameter<DoubleMatrix>)Parameters["Coordinates"]; }
    5353    }
     54    public OptionalValueParameter<DoubleMatrix> DistanceMatrixParameter {
     55      get { return (OptionalValueParameter<DoubleMatrix>)Parameters["DistanceMatrix"]; }
     56    }
     57    public ValueParameter<BoolValue> UseDistanceMatrixParameter {
     58      get { return (ValueParameter<BoolValue>)Parameters["UseDistanceMatrix"]; }
     59    }
    5460    public ValueParameter<IPermutationCreator> SolutionCreatorParameter {
    5561      get { return (ValueParameter<IPermutationCreator>)Parameters["SolutionCreator"]; }
     
    7480      set { CoordinatesParameter.Value = value; }
    7581    }
     82    public DoubleMatrix DistanceMatrix {
     83      get { return DistanceMatrixParameter.Value; }
     84      set { DistanceMatrixParameter.Value = value; }
     85    }
     86    public BoolValue UseDistanceMatrix {
     87      get { return UseDistanceMatrixParameter.Value; }
     88      set { UseDistanceMatrixParameter.Value = value; }
     89    }
    7690    public IPermutationCreator SolutionCreator {
    7791      get { return SolutionCreatorParameter.Value; }
     
    108122      Parameters.Add(new ValueParameter<BoolValue>("Maximization", "Set to false as the Traveling Salesman Problem is a minimization problem.", new BoolValue(false)));
    109123      Parameters.Add(new ValueParameter<DoubleMatrix>("Coordinates", "The x- and y-Coordinates of the cities.", new DoubleMatrix(0, 0)));
     124      Parameters.Add(new OptionalValueParameter<DoubleMatrix>("DistanceMatrix", "The matrix which contains the distances between the cities."));
     125      Parameters.Add(new ValueParameter<BoolValue>("UseDistanceMatrix", "True if a distance matrix should be calculated and used for evaluation, otherwise false.", new BoolValue(true)));
    110126      Parameters.Add(new ValueParameter<IPermutationCreator>("SolutionCreator", "The operator which should be used to create new TSP solutions.", creator));
    111127      Parameters.Add(new ValueParameter<ITSPEvaluator>("Evaluator", "The operator which should be used to evaluate TSP solutions.", evaluator));
     
    155171      Coordinates.Reset += new EventHandler(Coordinates_Reset);
    156172      ParameterizeSolutionCreator();
     173      ClearDistanceMatrix();
    157174    }
    158175    private void Coordinates_ItemChanged(object sender, EventArgs<int, int> e) {
     176      ClearDistanceMatrix();
    159177    }
    160178    private void Coordinates_Reset(object sender, EventArgs e) {
    161179      ParameterizeSolutionCreator();
     180      ClearDistanceMatrix();
    162181    }
    163182    private void SolutionCreatorParameter_ValueChanged(object sender, EventArgs e) {
     
    174193    private void EvaluatorParameter_ValueChanged(object sender, EventArgs e) {
    175194      ParameterizeEvaluator();
     195      ClearDistanceMatrix();
    176196      OnEvaluatorChanged();
    177197    }
     
    195215      if (Evaluator is ITSPPathEvaluator)
    196216        ((ITSPPathEvaluator)Evaluator).PermutationParameter.ActualName = SolutionCreator.PermutationParameter.ActualName;
    197       if (Evaluator is ITSPCoordinatesPathEvaluator)
    198         ((ITSPCoordinatesPathEvaluator)Evaluator).CoordinatesParameter.ActualName = CoordinatesParameter.Name;
     217      if (Evaluator is ITSPCoordinatesPathEvaluator) {
     218        ITSPCoordinatesPathEvaluator evaluator = (ITSPCoordinatesPathEvaluator)Evaluator;
     219        evaluator.CoordinatesParameter.ActualName = CoordinatesParameter.Name;
     220        evaluator.DistanceMatrixParameter.ActualName = DistanceMatrixParameter.Name;
     221        evaluator.UseDistanceMatrixParameter.ActualName = UseDistanceMatrixParameter.Name;
     222      }
    199223    }
    200224    private void InitializeOperators() {
     
    214238      }
    215239    }
     240    private void ClearDistanceMatrix() {
     241      DistanceMatrixParameter.Value = null;
     242    }
    216243    #endregion
    217244  }
Note: See TracChangeset for help on using the changeset viewer.