1 | using System;
|
---|
2 | using System.Collections.Generic;
|
---|
3 | using System.Linq;
|
---|
4 | using System.Text;
|
---|
5 | using System.Threading.Tasks;
|
---|
6 | using HeuristicLab.Optimization;
|
---|
7 | using HeuristicLab.PluginInfrastructure;
|
---|
8 | using HeuristicLab.Core;
|
---|
9 | using HeuristicLab.Persistence.Default.CompositeSerializers.Storable;
|
---|
10 | using HeuristicLab.Problems.Instances;
|
---|
11 | using HeuristicLab.Encodings.PermutationEncoding;
|
---|
12 | using HeuristicLab.Common;
|
---|
13 | using HeuristicLab.Parameters;
|
---|
14 | using HeuristicLab.Data;
|
---|
15 |
|
---|
16 | namespace HeuristicLab.Problems.PTSP {
|
---|
17 | [Item("Analytical Probabilistic Traveling Salesman Problem", "Represents an analytical Probabilistic Traveling Salesman Problem.")]
|
---|
18 | [Creatable("Problems")]
|
---|
19 | [StorableClass]
|
---|
20 | public sealed class AnalyticalProbabilisticTravelingSalesmanProblem : ProbabilisticTravelingSalesmanProblem, IStorableContent,
|
---|
21 | IProblemInstanceConsumer<TSPData> {
|
---|
22 |
|
---|
23 | [StorableConstructor]
|
---|
24 | private AnalyticalProbabilisticTravelingSalesmanProblem(bool deserializing) : base(deserializing) { }
|
---|
25 | private AnalyticalProbabilisticTravelingSalesmanProblem(AnalyticalProbabilisticTravelingSalesmanProblem original, Cloner cloner)
|
---|
26 | : base(original, cloner) {
|
---|
27 | }
|
---|
28 |
|
---|
29 | public override IDeepCloneable Clone(Cloner cloner) {
|
---|
30 | return new AnalyticalProbabilisticTravelingSalesmanProblem(this, cloner);
|
---|
31 | }
|
---|
32 |
|
---|
33 | public override double Evaluate(Individual individual, IRandom random) {
|
---|
34 | Permutation p = individual.Permutation();
|
---|
35 | // Analytical evaluation
|
---|
36 | double firstSum = 0;
|
---|
37 | for (int i = 0; i < p.Length - 1; i++) {
|
---|
38 | for (int j = i + 1; j < p.Length - 1; j++) {
|
---|
39 | double sum1 = DistanceMatrix[p[i], p[j]] * ProbabilityMatrix[0, p[i]] * ProbabilityMatrix[0, p[j]];
|
---|
40 | for (int k = i + 1; k < j; k++) {
|
---|
41 | sum1 = sum1 * (1 - ProbabilityMatrix[0, p[k]]);
|
---|
42 | }
|
---|
43 | firstSum += sum1;
|
---|
44 | }
|
---|
45 | }
|
---|
46 | double secondSum = 0;
|
---|
47 | for (int j = 0; j < p.Length - 1; j++) {
|
---|
48 | for (int i = 0; i < j; i++) {
|
---|
49 | double sum2 = DistanceMatrix[p[j], p[i]] * ProbabilityMatrix[0, p[i]] * ProbabilityMatrix[0, p[j]];
|
---|
50 | for (int k = j + 1; k < p.Length - 1; k++) {
|
---|
51 | sum2 = sum2 * (1 - ProbabilityMatrix[0, p[k]]);
|
---|
52 | }
|
---|
53 | for (int k = 1; k < i; k++) {
|
---|
54 | sum2 = sum2 * (1 - ProbabilityMatrix[0, p[k]]);
|
---|
55 | }
|
---|
56 | secondSum += sum2;
|
---|
57 | }
|
---|
58 | }
|
---|
59 | return firstSum + secondSum;
|
---|
60 | }
|
---|
61 |
|
---|
62 | public AnalyticalProbabilisticTravelingSalesmanProblem() {
|
---|
63 | Operators.Add(new PTSPInversionMovePathEvaluator());
|
---|
64 | }
|
---|
65 |
|
---|
66 | public override void Load(TSPData data) {
|
---|
67 | base.Load(data);
|
---|
68 | // Compute A and B matrices
|
---|
69 | }
|
---|
70 |
|
---|
71 | }
|
---|
72 | }
|
---|