Free cookie consent management tool by TermsFeed Policy Generator

source: branches/ParameterBinding/HeuristicLab.Problems.TravelingSalesman/3.3/TravelingSalesmanProblem.cs @ 4787

Last change on this file since 4787 was 4787, checked in by abeham, 13 years ago

#1258

  • Updated binding according to discussion
  • Added small test case for the TSP
File size: 20.9 KB
RevLine 
[2796]1#region License Information
2/* HeuristicLab
3 * Copyright (C) 2002-2010 Heuristic and Evolutionary Algorithms Laboratory (HEAL)
4 *
5 * This file is part of HeuristicLab.
6 *
7 * HeuristicLab is free software: you can redistribute it and/or modify
8 * it under the terms of the GNU General Public License as published by
9 * the Free Software Foundation, either version 3 of the License, or
10 * (at your option) any later version.
11 *
12 * HeuristicLab is distributed in the hope that it will be useful,
13 * but WITHOUT ANY WARRANTY; without even the implied warranty of
14 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
15 * GNU General Public License for more details.
16 *
17 * You should have received a copy of the GNU General Public License
18 * along with HeuristicLab. If not, see <http://www.gnu.org/licenses/>.
19 */
20#endregion
21
[2865]22using System;
[2975]23using System.Collections.Generic;
[2865]24using System.Drawing;
[3153]25using System.IO;
[2865]26using System.Linq;
[2975]27using HeuristicLab.Common;
[2796]28using HeuristicLab.Core;
29using HeuristicLab.Data;
[3053]30using HeuristicLab.Encodings.PermutationEncoding;
[2834]31using HeuristicLab.Optimization;
[2805]32using HeuristicLab.Parameters;
[2796]33using HeuristicLab.Persistence.Default.CompositeSerializers.Storable;
[2865]34using HeuristicLab.PluginInfrastructure;
[2796]35
[3158]36namespace HeuristicLab.Problems.TravelingSalesman {
[3159]37  [Item("Traveling Salesman Problem", "Represents a symmetric Traveling Salesman Problem.")]
[2796]38  [Creatable("Problems")]
[3017]39  [StorableClass]
[4419]40  public sealed class TravelingSalesmanProblem : ParameterizedNamedItem, ISingleObjectiveProblem, IStorableContent {
41    public string Filename { get; set; }
42
[2865]43    public override Image ItemImage {
44      get { return HeuristicLab.Common.Resources.VS2008ImageLibrary.Type; }
[2805]45    }
46
[2975]47    #region Parameter Properties
[3048]48    public ValueParameter<BoolValue> MaximizationParameter {
49      get { return (ValueParameter<BoolValue>)Parameters["Maximization"]; }
[2805]50    }
[2975]51    IParameter ISingleObjectiveProblem.MaximizationParameter {
52      get { return MaximizationParameter; }
[2865]53    }
[3048]54    public ValueParameter<DoubleMatrix> CoordinatesParameter {
55      get { return (ValueParameter<DoubleMatrix>)Parameters["Coordinates"]; }
[2865]56    }
[3066]57    public OptionalValueParameter<DoubleMatrix> DistanceMatrixParameter {
58      get { return (OptionalValueParameter<DoubleMatrix>)Parameters["DistanceMatrix"]; }
59    }
60    public ValueParameter<BoolValue> UseDistanceMatrixParameter {
61      get { return (ValueParameter<BoolValue>)Parameters["UseDistanceMatrix"]; }
62    }
[2975]63    public ValueParameter<IPermutationCreator> SolutionCreatorParameter {
64      get { return (ValueParameter<IPermutationCreator>)Parameters["SolutionCreator"]; }
[2865]65    }
[2975]66    IParameter IProblem.SolutionCreatorParameter {
67      get { return SolutionCreatorParameter; }
[2865]68    }
[2975]69    public ValueParameter<ITSPEvaluator> EvaluatorParameter {
70      get { return (ValueParameter<ITSPEvaluator>)Parameters["Evaluator"]; }
71    }
72    IParameter IProblem.EvaluatorParameter {
73      get { return EvaluatorParameter; }
74    }
[3048]75    public OptionalValueParameter<DoubleValue> BestKnownQualityParameter {
76      get { return (OptionalValueParameter<DoubleValue>)Parameters["BestKnownQuality"]; }
[2975]77    }
[3080]78    IParameter ISingleObjectiveProblem.BestKnownQualityParameter {
79      get { return BestKnownQualityParameter; }
80    }
[3151]81    public OptionalValueParameter<Permutation> BestKnownSolutionParameter {
82      get { return (OptionalValueParameter<Permutation>)Parameters["BestKnownSolution"]; }
83    }
[2975]84    #endregion
[2805]85
[2975]86    #region Properties
[3048]87    public DoubleMatrix Coordinates {
[2975]88      get { return CoordinatesParameter.Value; }
89      set { CoordinatesParameter.Value = value; }
[2865]90    }
[3066]91    public DoubleMatrix DistanceMatrix {
92      get { return DistanceMatrixParameter.Value; }
93      set { DistanceMatrixParameter.Value = value; }
94    }
95    public BoolValue UseDistanceMatrix {
96      get { return UseDistanceMatrixParameter.Value; }
97      set { UseDistanceMatrixParameter.Value = value; }
98    }
[2975]99    public IPermutationCreator SolutionCreator {
[2865]100      get { return SolutionCreatorParameter.Value; }
[2975]101      set { SolutionCreatorParameter.Value = value; }
[2865]102    }
[2975]103    ISolutionCreator IProblem.SolutionCreator {
104      get { return SolutionCreatorParameter.Value; }
105    }
106    public ITSPEvaluator Evaluator {
[2865]107      get { return EvaluatorParameter.Value; }
[2975]108      set { EvaluatorParameter.Value = value; }
[2865]109    }
[2975]110    ISingleObjectiveEvaluator ISingleObjectiveProblem.Evaluator {
111      get { return EvaluatorParameter.Value; }
112    }
[2865]113    IEvaluator IProblem.Evaluator {
114      get { return EvaluatorParameter.Value; }
115    }
[3048]116    public DoubleValue BestKnownQuality {
[2975]117      get { return BestKnownQualityParameter.Value; }
118      set { BestKnownQualityParameter.Value = value; }
119    }
[3151]120    public Permutation BestKnownSolution {
121      get { return BestKnownSolutionParameter.Value; }
122      set { BestKnownSolutionParameter.Value = value; }
123    }
[2975]124    public IEnumerable<IOperator> Operators {
[3616]125      get { return operators; }
[2865]126    }
[3663]127    private BestTSPSolutionAnalyzer BestTSPSolutionAnalyzer {
128      get { return operators.OfType<BestTSPSolutionAnalyzer>().FirstOrDefault(); }
[3616]129    }
[4623]130    private TSPAlleleFrequencyAnalyzer TSPAlleleFrequencyAnalyzer {
131      get { return operators.OfType<TSPAlleleFrequencyAnalyzer>().FirstOrDefault(); }
132    }
[4703]133    private TSPPopulationDiversityAnalyzer TSPPopulationDiversityAnalyzer {
134      get { return operators.OfType<TSPPopulationDiversityAnalyzer>().FirstOrDefault(); }
135    }
[2975]136    #endregion
[2865]137
[4098]138    [Storable]
139    private List<IOperator> operators;
140
141    [StorableConstructor]
[4118]142    private TravelingSalesmanProblem(bool deserializing) : base(deserializing) { }
[4722]143    private TravelingSalesmanProblem(TravelingSalesmanProblem original, Cloner cloner)
144      : base(original, cloner) {
145      this.operators = original.operators.Select(x => (IOperator)cloner.Clone(x)).ToList();
146      this.DistanceMatrixParameter.Value = original.DistanceMatrixParameter.Value;
147      AttachEventHandlers();
148    }
149    public override IDeepCloneable Clone(Cloner cloner) {
150      return new TravelingSalesmanProblem(this, cloner);
151    }
[3159]152    public TravelingSalesmanProblem()
[2796]153      : base() {
[2891]154      RandomPermutationCreator creator = new RandomPermutationCreator();
155      TSPRoundedEuclideanPathEvaluator evaluator = new TSPRoundedEuclideanPathEvaluator();
156
[3048]157      Parameters.Add(new ValueParameter<BoolValue>("Maximization", "Set to false as the Traveling Salesman Problem is a minimization problem.", new BoolValue(false)));
[3504]158      Parameters.Add(new ValueParameter<DoubleMatrix>("Coordinates", "The x- and y-Coordinates of the cities."));
[3066]159      Parameters.Add(new OptionalValueParameter<DoubleMatrix>("DistanceMatrix", "The matrix which contains the distances between the cities."));
160      Parameters.Add(new ValueParameter<BoolValue>("UseDistanceMatrix", "True if a distance matrix should be calculated and used for evaluation, otherwise false.", new BoolValue(true)));
[2891]161      Parameters.Add(new ValueParameter<IPermutationCreator>("SolutionCreator", "The operator which should be used to create new TSP solutions.", creator));
162      Parameters.Add(new ValueParameter<ITSPEvaluator>("Evaluator", "The operator which should be used to evaluate TSP solutions.", evaluator));
[3048]163      Parameters.Add(new OptionalValueParameter<DoubleValue>("BestKnownQuality", "The quality of the best known solution of this TSP instance."));
[3151]164      Parameters.Add(new OptionalValueParameter<Permutation>("BestKnownSolution", "The best known solution of this TSP instance."));
[2865]165
[3504]166      Coordinates = new DoubleMatrix(new double[,] {
167        { 100, 100 }, { 100, 200 }, { 100, 300 }, { 100, 400 },
168        { 200, 100 }, { 200, 200 }, { 200, 300 }, { 200, 400 },
169        { 300, 100 }, { 300, 200 }, { 300, 300 }, { 300, 400 },
170        { 400, 100 }, { 400, 200 }, { 400, 300 }, { 400, 400 }
171      });
172
[2865]173      creator.PermutationParameter.ActualName = "TSPTour";
174      evaluator.QualityParameter.ActualName = "TSPTourLength";
[2975]175      ParameterizeSolutionCreator();
176      ParameterizeEvaluator();
[2865]177
[4098]178      InitializeOperators();
179      AttachEventHandlers();
[4787]180
181      AddBinding("BestTSPSolutionAnalyzer.QualityParameter.ActualName", "Evaluator.QualityParameter.ActualName");
182      AddBinding("BestTSPSolutionAnalyzer.CoordinatesParameter.ActualName", "CoordinatesParameter.Name");
183      AddBinding("BestTSPSolutionAnalyzer.PermutationParameter.ActualName", "SolutionCreator.PermutationParameter.ActualName");
184      AddBinding("BestTSPSolutionAnalyzer.BestKnownQualityParameter.ActualName", "BestKnownQualityParameter.Name");
185      AddBinding("BestTSPSolutionAnalyzer.BestKnownSolutionParameter.ActualName", "BestKnownSolutionParameter.Name");
186      AddBinding("BestTSPSolutionAnalyzer.MaximizationParameter.ActualName", "MaximizationParameter.Name");
187      BestTSPSolutionAnalyzer.ResultsParameter.ActualName = "Results";
[2975]188    }
[2891]189
[2975]190    #region Events
191    public event EventHandler SolutionCreatorChanged;
192    private void OnSolutionCreatorChanged() {
[3739]193      EventHandler handler = SolutionCreatorChanged;
194      if (handler != null) handler(this, EventArgs.Empty);
[2865]195    }
[2975]196    public event EventHandler EvaluatorChanged;
197    private void OnEvaluatorChanged() {
[3739]198      EventHandler handler = EvaluatorChanged;
199      if (handler != null) handler(this, EventArgs.Empty);
[2975]200    }
201    public event EventHandler OperatorsChanged;
202    private void OnOperatorsChanged() {
[3739]203      EventHandler handler = OperatorsChanged;
204      if (handler != null) handler(this, EventArgs.Empty);
[2975]205    }
[3739]206    public event EventHandler Reset;
207    private void OnReset() {
208      EventHandler handler = Reset;
209      if (handler != null) handler(this, EventArgs.Empty);
210    }
[2975]211
212    private void CoordinatesParameter_ValueChanged(object sender, EventArgs e) {
213      Coordinates.ItemChanged += new EventHandler<EventArgs<int, int>>(Coordinates_ItemChanged);
214      Coordinates.Reset += new EventHandler(Coordinates_Reset);
215      ParameterizeSolutionCreator();
[3066]216      ClearDistanceMatrix();
[2975]217    }
218    private void Coordinates_ItemChanged(object sender, EventArgs<int, int> e) {
[3066]219      ClearDistanceMatrix();
[2975]220    }
221    private void Coordinates_Reset(object sender, EventArgs e) {
222      ParameterizeSolutionCreator();
[3066]223      ClearDistanceMatrix();
[2975]224    }
[2865]225    private void SolutionCreatorParameter_ValueChanged(object sender, EventArgs e) {
[2975]226      SolutionCreator.PermutationParameter.ActualNameChanged += new EventHandler(SolutionCreator_PermutationParameter_ActualNameChanged);
227      ParameterizeSolutionCreator();
228      ParameterizeEvaluator();
[4623]229      ParameterizeAnalyzers();
[2975]230      ParameterizeOperators();
[2865]231      OnSolutionCreatorChanged();
232    }
[2975]233    private void SolutionCreator_PermutationParameter_ActualNameChanged(object sender, EventArgs e) {
234      ParameterizeEvaluator();
[4623]235      ParameterizeAnalyzers();
[2975]236      ParameterizeOperators();
237    }
[2865]238    private void EvaluatorParameter_ValueChanged(object sender, EventArgs e) {
[3139]239      Evaluator.QualityParameter.ActualNameChanged += new EventHandler(Evaluator_QualityParameter_ActualNameChanged);
[2975]240      ParameterizeEvaluator();
[3209]241      UpdateMoveEvaluators();
[4623]242      ParameterizeAnalyzers();
[3066]243      ClearDistanceMatrix();
[2865]244      OnEvaluatorChanged();
245    }
[3139]246    private void Evaluator_QualityParameter_ActualNameChanged(object sender, EventArgs e) {
[4623]247      ParameterizeAnalyzers();
[3139]248    }
[4770]249    private void MoveGenerator_InversionMoveParameter_ActualNameChanged(object sender, EventArgs e) {
250      string name = ((ILookupParameter<InversionMove>)sender).ActualName;
251      foreach (IPermutationInversionMoveOperator op in Operators.OfType<IPermutationInversionMoveOperator>()) {
252        op.InversionMoveParameter.ActualName = name;
253      }
254    }
[3232]255    private void MoveGenerator_TranslocationMoveParameter_ActualNameChanged(object sender, EventArgs e) {
256      string name = ((ILookupParameter<TranslocationMove>)sender).ActualName;
257      foreach (IPermutationTranslocationMoveOperator op in Operators.OfType<IPermutationTranslocationMoveOperator>()) {
258        op.TranslocationMoveParameter.ActualName = name;
[3074]259      }
260    }
[2975]261    #endregion
[2865]262
[2975]263    #region Helpers
[2986]264    [StorableHook(HookType.AfterDeserialization)]
[4722]265    private void AfterDeserialization() {
[4118]266      // BackwardsCompatibility3.3
267      #region Backwards compatible code (remove with 3.4)
268      if (operators == null) InitializeOperators();
269      #endregion
270      AttachEventHandlers();
271    }
272
[4098]273    private void AttachEventHandlers() {
[2975]274      CoordinatesParameter.ValueChanged += new EventHandler(CoordinatesParameter_ValueChanged);
275      Coordinates.ItemChanged += new EventHandler<EventArgs<int, int>>(Coordinates_ItemChanged);
276      Coordinates.Reset += new EventHandler(Coordinates_Reset);
277      SolutionCreatorParameter.ValueChanged += new EventHandler(SolutionCreatorParameter_ValueChanged);
278      SolutionCreator.PermutationParameter.ActualNameChanged += new EventHandler(SolutionCreator_PermutationParameter_ActualNameChanged);
279      EvaluatorParameter.ValueChanged += new EventHandler(EvaluatorParameter_ValueChanged);
[3139]280      Evaluator.QualityParameter.ActualNameChanged += new EventHandler(Evaluator_QualityParameter_ActualNameChanged);
[2865]281    }
[3139]282
[3099]283    private void InitializeOperators() {
[3616]284      operators = new List<IOperator>();
[3663]285      operators.Add(new BestTSPSolutionAnalyzer());
[4623]286      operators.Add(new TSPAlleleFrequencyAnalyzer());
[4703]287      operators.Add(new TSPPopulationDiversityAnalyzer());
[4623]288      ParameterizeAnalyzers();
[3616]289      operators.AddRange(ApplicationManager.Manager.GetInstances<IPermutationOperator>().Cast<IOperator>());
[3199]290      ParameterizeOperators();
[3209]291      UpdateMoveEvaluators();
[3099]292      InitializeMoveGenerators();
293    }
294    private void InitializeMoveGenerators() {
[4770]295      foreach (IPermutationInversionMoveOperator op in Operators.OfType<IPermutationInversionMoveOperator>()) {
296        if (op is IMoveGenerator) {
297          op.InversionMoveParameter.ActualNameChanged += new EventHandler(MoveGenerator_InversionMoveParameter_ActualNameChanged);
[3099]298        }
299      }
[4770]300      foreach (IPermutationTranslocationMoveOperator op in Operators.OfType<IPermutationTranslocationMoveOperator>()) {
301        if (op is IMoveGenerator) {
302          op.TranslocationMoveParameter.ActualNameChanged += new EventHandler(MoveGenerator_TranslocationMoveParameter_ActualNameChanged);
[3099]303        }
304      }
305    }
[3209]306    private void UpdateMoveEvaluators() {
[4047]307      operators.RemoveAll(x => x is ISingleObjectiveMoveEvaluator);
[3303]308      foreach (ITSPPathMoveEvaluator op in ApplicationManager.Manager.GetInstances<ITSPPathMoveEvaluator>())
309        if (op.EvaluatorType == Evaluator.GetType()) {
310          operators.Add(op);
311        }
312      ParameterizeOperators();
313      OnOperatorsChanged();
[3209]314    }
[2975]315    private void ParameterizeSolutionCreator() {
[3048]316      SolutionCreator.LengthParameter.Value = new IntValue(Coordinates.Rows);
[3231]317      SolutionCreator.PermutationTypeParameter.Value = new PermutationType(PermutationTypes.RelativeUndirected);
[2865]318    }
[2975]319    private void ParameterizeEvaluator() {
320      if (Evaluator is ITSPPathEvaluator)
321        ((ITSPPathEvaluator)Evaluator).PermutationParameter.ActualName = SolutionCreator.PermutationParameter.ActualName;
[3066]322      if (Evaluator is ITSPCoordinatesPathEvaluator) {
323        ITSPCoordinatesPathEvaluator evaluator = (ITSPCoordinatesPathEvaluator)Evaluator;
324        evaluator.CoordinatesParameter.ActualName = CoordinatesParameter.Name;
325        evaluator.DistanceMatrixParameter.ActualName = DistanceMatrixParameter.Name;
326        evaluator.UseDistanceMatrixParameter.ActualName = UseDistanceMatrixParameter.Name;
327      }
[2865]328    }
[4623]329    private void ParameterizeAnalyzers() {
[4787]330      /*if (BestTSPSolutionAnalyzer != null) {
[4641]331        BestTSPSolutionAnalyzer.QualityParameter.ActualName = Evaluator.QualityParameter.ActualName;
332        BestTSPSolutionAnalyzer.CoordinatesParameter.ActualName = CoordinatesParameter.Name;
333        BestTSPSolutionAnalyzer.PermutationParameter.ActualName = SolutionCreator.PermutationParameter.ActualName;
334        BestTSPSolutionAnalyzer.ResultsParameter.ActualName = "Results";
335        BestTSPSolutionAnalyzer.BestKnownQualityParameter.ActualName = BestKnownQualityParameter.Name;
336        BestTSPSolutionAnalyzer.BestKnownSolutionParameter.ActualName = BestKnownSolutionParameter.Name;
337        BestTSPSolutionAnalyzer.MaximizationParameter.ActualName = MaximizationParameter.Name;
[4787]338      }*/
[4623]339
[4641]340      if (TSPAlleleFrequencyAnalyzer != null) {
341        TSPAlleleFrequencyAnalyzer.MaximizationParameter.ActualName = MaximizationParameter.Name;
342        TSPAlleleFrequencyAnalyzer.CoordinatesParameter.ActualName = CoordinatesParameter.Name;
343        TSPAlleleFrequencyAnalyzer.SolutionParameter.ActualName = SolutionCreator.PermutationParameter.ActualName;
344        TSPAlleleFrequencyAnalyzer.QualityParameter.ActualName = Evaluator.QualityParameter.ActualName;
345        TSPAlleleFrequencyAnalyzer.BestKnownSolutionParameter.ActualName = BestKnownSolutionParameter.Name;
346        TSPAlleleFrequencyAnalyzer.ResultsParameter.ActualName = "Results";
347      }
[4703]348
349      if (TSPPopulationDiversityAnalyzer != null) {
350        TSPPopulationDiversityAnalyzer.MaximizationParameter.ActualName = MaximizationParameter.Name;
351        TSPPopulationDiversityAnalyzer.SolutionParameter.ActualName = SolutionCreator.PermutationParameter.ActualName;
352        TSPPopulationDiversityAnalyzer.QualityParameter.ActualName = Evaluator.QualityParameter.ActualName;
353        TSPPopulationDiversityAnalyzer.ResultsParameter.ActualName = "Results";
354      }
[3107]355    }
[2975]356    private void ParameterizeOperators() {
357      foreach (IPermutationCrossover op in Operators.OfType<IPermutationCrossover>()) {
358        op.ParentsParameter.ActualName = SolutionCreator.PermutationParameter.ActualName;
359        op.ChildParameter.ActualName = SolutionCreator.PermutationParameter.ActualName;
360      }
361      foreach (IPermutationManipulator op in Operators.OfType<IPermutationManipulator>()) {
362        op.PermutationParameter.ActualName = SolutionCreator.PermutationParameter.ActualName;
363      }
[3074]364      foreach (IPermutationMoveOperator op in Operators.OfType<IPermutationMoveOperator>()) {
365        op.PermutationParameter.ActualName = SolutionCreator.PermutationParameter.ActualName;
366      }
367      foreach (ITSPPathMoveEvaluator op in Operators.OfType<ITSPPathMoveEvaluator>()) {
368        op.CoordinatesParameter.ActualName = CoordinatesParameter.Name;
369        op.DistanceMatrixParameter.ActualName = DistanceMatrixParameter.Name;
370        op.UseDistanceMatrixParameter.ActualName = UseDistanceMatrixParameter.Name;
[3209]371        op.QualityParameter.ActualName = Evaluator.QualityParameter.ActualName;
372        op.PermutationParameter.ActualName = SolutionCreator.PermutationParameter.ActualName;
[3074]373      }
[3340]374      string inversionMove = Operators.OfType<IMoveGenerator>().OfType<IPermutationInversionMoveOperator>().First().InversionMoveParameter.ActualName;
375      foreach (IPermutationInversionMoveOperator op in Operators.OfType<IPermutationInversionMoveOperator>())
376        op.InversionMoveParameter.ActualName = inversionMove;
377      string translocationMove = Operators.OfType<IMoveGenerator>().OfType<IPermutationTranslocationMoveOperator>().First().TranslocationMoveParameter.ActualName;
378      foreach (IPermutationTranslocationMoveOperator op in Operators.OfType<IPermutationTranslocationMoveOperator>())
379        op.TranslocationMoveParameter.ActualName = translocationMove;
[2975]380    }
[3074]381
[3066]382    private void ClearDistanceMatrix() {
383      DistanceMatrixParameter.Value = null;
384    }
[2975]385    #endregion
[4098]386
387    public void ImportFromTSPLIB(string tspFileName, string optimalTourFileName) {
388      TSPLIBParser tspParser = new TSPLIBParser(tspFileName);
389      tspParser.Parse();
390      Name = tspParser.Name + " TSP (imported from TSPLIB)";
391      if (!string.IsNullOrEmpty(tspParser.Comment)) Description = tspParser.Comment;
392      Coordinates = new DoubleMatrix(tspParser.Vertices);
393      if (tspParser.WeightType == TSPLIBParser.TSPLIBEdgeWeightType.EUC_2D) {
394        TSPRoundedEuclideanPathEvaluator evaluator = new TSPRoundedEuclideanPathEvaluator();
395        evaluator.QualityParameter.ActualName = "TSPTourLength";
396        Evaluator = evaluator;
397      } else if (tspParser.WeightType == TSPLIBParser.TSPLIBEdgeWeightType.GEO) {
398        TSPGeoPathEvaluator evaluator = new TSPGeoPathEvaluator();
399        evaluator.QualityParameter.ActualName = "TSPTourLength";
400        Evaluator = evaluator;
401      }
402      BestKnownQuality = null;
403      BestKnownSolution = null;
404
405      if (!string.IsNullOrEmpty(optimalTourFileName)) {
406        TSPLIBTourParser tourParser = new TSPLIBTourParser(optimalTourFileName);
407        tourParser.Parse();
408        if (tourParser.Tour.Length != Coordinates.Rows) throw new InvalidDataException("Length of optimal tour is not equal to number of cities.");
409        BestKnownSolution = new Permutation(PermutationTypes.RelativeUndirected, tourParser.Tour);
410      }
411      OnReset();
412    }
413    public void ImportFromTSPLIB(string tspFileName, string optimalTourFileName, double bestKnownQuality) {
414      ImportFromTSPLIB(tspFileName, optimalTourFileName);
415      BestKnownQuality = new DoubleValue(bestKnownQuality);
416    }
[2796]417  }
418}
Note: See TracBrowser for help on using the repository browser.