Free cookie consent management tool by TermsFeed Policy Generator

source: trunk/sources/HeuristicLab.Routing.TSP/3.3/TSP.cs @ 2856

Last change on this file since 2856 was 2852, checked in by swagner, 15 years ago

Operator architecture refactoring (#95)

  • worked on algorithms
File size: 2.7 KB
Line 
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
22using HeuristicLab.Core;
23using HeuristicLab.Data;
24using HeuristicLab.Optimization;
25using HeuristicLab.Parameters;
26using HeuristicLab.Permutation;
27using HeuristicLab.Persistence.Default.CompositeSerializers.Storable;
28
29namespace HeuristicLab.Routing.TSP {
30  [Item("TSP", "Represents a symmetric Traveling Salesman Problem.")]
31  [Creatable("Problems")]
32  [EmptyStorableClass]
33  public sealed class TSP : SingleObjectiveProblem {
34    private ValueParameter<DoubleMatrixData> CoordinatesParameter {
35      get { return (ValueParameter<DoubleMatrixData>)Parameters["Coordinates"]; }
36    }
37
38    public DoubleMatrixData Coordinates {
39      get { return CoordinatesParameter.Value; }
40      set { CoordinatesParameter.Value = value; }
41    }
42
43    public TSP()
44      : base() {
45      Maximization = new BoolData(false);
46      Parameters.Add(new ValueParameter<DoubleMatrixData>("Coordinates", "The x- and y-Coordinates of the cities.", new DoubleMatrixData(0, 0)));
47      Parameters.Add(new ValueParameter<DoubleData>("BestKnownQuality", "The quality of the best known solution of this TSP instance."));
48      RandomPermutationCreator creator = new RandomPermutationCreator();
49      creator.LengthParameter.Value = new IntData(0);
50      SolutionCreator = creator;
51      Evaluator = new TSPRoundedEuclideanPathEvaluator();
52    }
53
54    public void ImportFromTSPLIB(string filename) {
55      TSPLIBParser parser = new TSPLIBParser(filename);
56      parser.Parse();
57      Coordinates = new DoubleMatrixData(parser.Vertices);
58      int cities = Coordinates.Rows;
59      RandomPermutationCreator creator = new RandomPermutationCreator();
60      creator.LengthParameter.Value = new IntData(cities);
61      SolutionCreator = creator;
62      TSPRoundedEuclideanPathEvaluator evaluator = new TSPRoundedEuclideanPathEvaluator();
63      Evaluator = evaluator;
64    }
65  }
66}
Note: See TracBrowser for help on using the repository browser.