[13412] | 1 | #region License Information
|
---|
| 2 | /* HeuristicLab
|
---|
[17226] | 3 | * Copyright (C) Heuristic and Evolutionary Algorithms Laboratory (HEAL)
|
---|
[13412] | 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 |
|
---|
[17320] | 22 | using System.Threading;
|
---|
[17253] | 23 | using HEAL.Attic;
|
---|
[13412] | 24 | using HeuristicLab.Common;
|
---|
[12191] | 25 | using HeuristicLab.Core;
|
---|
[13412] | 26 | using HeuristicLab.Encodings.PermutationEncoding;
|
---|
[17382] | 27 | using HeuristicLab.Optimization;
|
---|
[12191] | 28 |
|
---|
| 29 | namespace HeuristicLab.Problems.PTSP {
|
---|
[17260] | 30 | [Item("Analytical Probabilistic TSP (pTSP)", "Represents a probabilistic traveling salesman problem where the expected tour length is calculated exactly.")]
|
---|
[13412] | 31 | [Creatable(CreatableAttribute.Categories.CombinatorialProblems)]
|
---|
[16723] | 32 | [StorableType("509B6AB5-F4DE-4144-A031-43EEBAD02CA6")]
|
---|
[17253] | 33 | public sealed class AnalyticalPTSP : ProbabilisticTSP {
|
---|
[12191] | 34 |
|
---|
| 35 | [StorableConstructor]
|
---|
[17253] | 36 | private AnalyticalPTSP(StorableConstructorFlag _) : base(_) { }
|
---|
| 37 | private AnalyticalPTSP(AnalyticalPTSP original, Cloner cloner) : base(original, cloner) { }
|
---|
| 38 | public AnalyticalPTSP() {
|
---|
[13470] | 39 | Operators.Add(new PTSPAnalyticalInversionMoveEvaluator());
|
---|
| 40 | Operators.Add(new PTSPAnalyticalInsertionMoveEvaluator());
|
---|
| 41 | Operators.Add(new PTSPAnalyticalInversionLocalImprovement());
|
---|
| 42 | Operators.Add(new PTSPAnalyticalInsertionLocalImprovement());
|
---|
| 43 | Operators.Add(new PTSPAnalyticalTwoPointFiveLocalImprovement());
|
---|
| 44 |
|
---|
| 45 | Operators.Add(new ExhaustiveTwoPointFiveMoveGenerator());
|
---|
| 46 | Operators.Add(new StochasticTwoPointFiveMultiMoveGenerator());
|
---|
| 47 | Operators.Add(new StochasticTwoPointFiveSingleMoveGenerator());
|
---|
| 48 | Operators.Add(new TwoPointFiveMoveMaker());
|
---|
| 49 | Operators.Add(new PTSPAnalyticalTwoPointFiveMoveEvaluator());
|
---|
| 50 |
|
---|
[17264] | 51 | Encoding.ConfigureOperators(Operators);
|
---|
[12191] | 52 | }
|
---|
| 53 |
|
---|
| 54 | public override IDeepCloneable Clone(Cloner cloner) {
|
---|
[17253] | 55 | return new AnalyticalPTSP(this, cloner);
|
---|
[12191] | 56 | }
|
---|
| 57 |
|
---|
[17382] | 58 | public override ISingleObjectiveEvaluationResult Evaluate(Permutation tour, IRandom random, CancellationToken cancellationToken) {
|
---|
| 59 | var quality = Evaluate(tour, ProbabilisticTSPData, cancellationToken);
|
---|
| 60 | return new SingleObjectiveEvaluationResult(quality);
|
---|
[12191] | 61 | }
|
---|
| 62 |
|
---|
[17320] | 63 | public static double Evaluate(Permutation tour, IProbabilisticTSPData data, CancellationToken cancellationToken) {
|
---|
[12269] | 64 | // Analytical evaluation
|
---|
[13412] | 65 | var firstSum = 0.0;
|
---|
[13470] | 66 | for (var i = 0; i < tour.Length - 1; i++) {
|
---|
[13412] | 67 | for (var j = i + 1; j < tour.Length; j++) {
|
---|
[17533] | 68 | var prod1 = data.GetDistance(tour[i], tour[j]) * data.GetProbability(tour[i]) * data.GetProbability(tour[j]);
|
---|
[13412] | 69 | for (var k = i + 1; k < j; k++) {
|
---|
[17253] | 70 | prod1 *= (1 - data.GetProbability(tour[k]));
|
---|
[12269] | 71 | }
|
---|
[13470] | 72 | firstSum += prod1;
|
---|
[12269] | 73 | }
|
---|
| 74 | }
|
---|
[13412] | 75 | var secondSum = 0.0;
|
---|
| 76 | for (var j = 0; j < tour.Length; j++) {
|
---|
| 77 | for (var i = 0; i < j; i++) {
|
---|
[17533] | 78 | var prod2 = data.GetDistance(tour[j], tour[i]) * data.GetProbability(tour[i]) * data.GetProbability(tour[j]);
|
---|
[13412] | 79 | for (var k = j + 1; k < tour.Length; k++) {
|
---|
[17253] | 80 | prod2 *= (1 - data.GetProbability(tour[k]));
|
---|
[12269] | 81 | }
|
---|
[13412] | 82 | for (var k = 0; k < i; k++) {
|
---|
[17253] | 83 | prod2 *= (1 - data.GetProbability(tour[k]));
|
---|
[12269] | 84 | }
|
---|
[13470] | 85 | secondSum += prod2;
|
---|
[12269] | 86 | }
|
---|
| 87 | }
|
---|
| 88 | return firstSum + secondSum;
|
---|
| 89 | }
|
---|
[12191] | 90 | }
|
---|
| 91 | }
|
---|