[12166] | 1 | #region License Information
|
---|
| 2 | /* HeuristicLab
|
---|
| 3 | * Copyright (C) 2002-2015 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 |
|
---|
| 22 | using System;
|
---|
| 23 | using System.Collections.Generic;
|
---|
| 24 | using System.Linq;
|
---|
| 25 | using System.Text;
|
---|
| 26 | using System.Threading.Tasks;
|
---|
| 27 | using HeuristicLab.Optimization;
|
---|
| 28 | using HeuristicLab.PluginInfrastructure;
|
---|
| 29 | using HeuristicLab.Core;
|
---|
| 30 | using HeuristicLab.Persistence.Default.CompositeSerializers.Storable;
|
---|
| 31 | using HeuristicLab.Problems.Instances;
|
---|
| 32 | using HeuristicLab.Encodings.PermutationEncoding;
|
---|
| 33 | using HeuristicLab.Common;
|
---|
| 34 | using HeuristicLab.Parameters;
|
---|
| 35 | using HeuristicLab.Data;
|
---|
| 36 |
|
---|
| 37 | namespace HeuristicLab.Problems.PTSP {
|
---|
| 38 | [Item("Probabilistic Traveling Salesman Problem", "Represents a Probabilistic Traveling Salesman Problem.")]
|
---|
| 39 | [StorableClass]
|
---|
[12191] | 40 | public abstract class ProbabilisticTravelingSalesmanProblem : SingleObjectiveBasicProblem<PermutationEncoding>, IStorableContent,
|
---|
[12166] | 41 | IProblemInstanceConsumer<TSPData> {
|
---|
[12183] | 42 | #region Parameter Properties
|
---|
| 43 | public OptionalValueParameter<DoubleMatrix> CoordinatesParameter {
|
---|
| 44 | get { return (OptionalValueParameter<DoubleMatrix>)Parameters["Coordinates"]; }
|
---|
| 45 | }
|
---|
| 46 | public OptionalValueParameter<DistanceMatrix> DistanceMatrixParameter {
|
---|
| 47 | get { return (OptionalValueParameter<DistanceMatrix>)Parameters["DistanceMatrix"]; }
|
---|
| 48 | }
|
---|
| 49 | public ValueParameter<BoolValue> UseDistanceMatrixParameter {
|
---|
| 50 | get { return (ValueParameter<BoolValue>)Parameters["UseDistanceMatrix"]; }
|
---|
| 51 | }
|
---|
| 52 | public OptionalValueParameter<Permutation> BestKnownSolutionParameter {
|
---|
| 53 | get { return (OptionalValueParameter<Permutation>)Parameters["BestKnownSolution"]; }
|
---|
| 54 | }
|
---|
[12219] | 55 | public OptionalValueParameter<ItemList<DoubleValue>> ProbabilityMatrixParameter {
|
---|
| 56 | get { return (OptionalValueParameter<ItemList<DoubleValue>>)Parameters["ProbabilityMatrix"]; }
|
---|
[12183] | 57 | }
|
---|
| 58 | public ValueParameter<IntValue> SampleSizeParameter {
|
---|
| 59 | get { return (ValueParameter<IntValue>)Parameters["SampleSize"]; }
|
---|
| 60 | }
|
---|
| 61 |
|
---|
| 62 | #endregion
|
---|
| 63 |
|
---|
| 64 | #region Properties
|
---|
| 65 | public DoubleMatrix Coordinates {
|
---|
| 66 | get { return CoordinatesParameter.Value; }
|
---|
| 67 | set { CoordinatesParameter.Value = value; }
|
---|
| 68 | }
|
---|
| 69 | public DistanceMatrix DistanceMatrix {
|
---|
| 70 | get { return DistanceMatrixParameter.Value; }
|
---|
| 71 | set { DistanceMatrixParameter.Value = value; }
|
---|
| 72 | }
|
---|
| 73 | public BoolValue UseDistanceMatrix {
|
---|
| 74 | get { return UseDistanceMatrixParameter.Value; }
|
---|
| 75 | set { UseDistanceMatrixParameter.Value = value; }
|
---|
| 76 | }
|
---|
| 77 | public Permutation BestKnownSolution {
|
---|
| 78 | get { return BestKnownSolutionParameter.Value; }
|
---|
| 79 | set { BestKnownSolutionParameter.Value = value; }
|
---|
| 80 | }
|
---|
[12219] | 81 | public ItemList<DoubleValue> ProbabilityMatrix {
|
---|
[12183] | 82 | get { return ProbabilityMatrixParameter.Value; }
|
---|
| 83 | set { ProbabilityMatrixParameter.Value = value; }
|
---|
| 84 | }
|
---|
| 85 | public IntValue SampleSize {
|
---|
| 86 | get { return SampleSizeParameter.Value; }
|
---|
| 87 | set { SampleSizeParameter.Value = value; }
|
---|
| 88 | }
|
---|
| 89 | #endregion
|
---|
[12191] | 90 |
|
---|
[12166] | 91 |
|
---|
| 92 | public override bool Maximization {
|
---|
| 93 | get { return false; }
|
---|
| 94 | }
|
---|
| 95 |
|
---|
| 96 | [StorableConstructor]
|
---|
[12191] | 97 | protected ProbabilisticTravelingSalesmanProblem(bool deserializing) : base(deserializing) { }
|
---|
| 98 | protected ProbabilisticTravelingSalesmanProblem(ProbabilisticTravelingSalesmanProblem original, Cloner cloner)
|
---|
[12166] | 99 | : base(original, cloner) {
|
---|
| 100 | }
|
---|
[12191] | 101 |
|
---|
[12166] | 102 | public ProbabilisticTravelingSalesmanProblem() {
|
---|
[12183] | 103 | Parameters.Add(new OptionalValueParameter<DoubleMatrix>("Coordinates", "The x- and y-Coordinates of the cities."));
|
---|
| 104 | Parameters.Add(new OptionalValueParameter<DistanceMatrix>("DistanceMatrix", "The matrix which contains the distances between the cities."));
|
---|
| 105 | 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)));
|
---|
| 106 | Parameters.Add(new OptionalValueParameter<Permutation>("BestKnownSolution", "The best known solution of this TSP instance."));
|
---|
[12219] | 107 | Parameters.Add(new OptionalValueParameter<ItemList<DoubleValue>>("ProbabilityMatrix", "The matrix which contains the probabilities of each of the cities."));
|
---|
[12191] | 108 |
|
---|
[12166] | 109 | }
|
---|
| 110 |
|
---|
[12191] | 111 | public virtual void Load(TSPData data) {
|
---|
[12183] | 112 | DistanceMatrix = new DistanceMatrix(data.GetDistanceMatrix());
|
---|
| 113 | // Get Probabilities of cities using random with seed from hash function on the Name of the instance
|
---|
[12219] | 114 | ProbabilityMatrix = new ItemList<DoubleValue>(data.Dimension);
|
---|
[12183] | 115 | Random r = new Random(data.Name.GetHashCode());
|
---|
| 116 | for (int i = 0; i < data.Dimension; i++) {
|
---|
[12219] | 117 | ProbabilityMatrix.Add(new DoubleValue(r.NextDouble()));
|
---|
[12183] | 118 | }
|
---|
| 119 | Encoding.Length = data.Dimension;
|
---|
[12166] | 120 | }
|
---|
| 121 | }
|
---|
| 122 | }
|
---|