1 | using HeuristicLab.Common;
|
---|
2 | using HeuristicLab.Core;
|
---|
3 | using HeuristicLab.Data;
|
---|
4 | using HeuristicLab.Encodings.PermutationEncoding;
|
---|
5 | using HeuristicLab.Persistence.Default.CompositeSerializers.Storable;
|
---|
6 | using System;
|
---|
7 | using System.Collections.Generic;
|
---|
8 | using System.Linq;
|
---|
9 | using System.Text;
|
---|
10 | using System.Threading.Tasks;
|
---|
11 |
|
---|
12 | namespace HeuristicLab.Problems.LinearOrdering
|
---|
13 | { /// <summary>
|
---|
14 | /// An operator which evaluates LOP solutions given in matrix representation.
|
---|
15 | /// </summary>
|
---|
16 | [Item("AwesomeTriangulationEvaluator", "An operator which evaluates LOP solutions given in matrix representation.")]
|
---|
17 | [StorableClass]
|
---|
18 | public sealed class AwesomeTriangulationEvaluator : MatrixTriangulationEvaluator
|
---|
19 | {
|
---|
20 | [StorableConstructor]
|
---|
21 | private AwesomeTriangulationEvaluator(bool deserializing) : base(deserializing) { }
|
---|
22 | private AwesomeTriangulationEvaluator(AwesomeTriangulationEvaluator original, Cloner cloner) : base(original, cloner) { }
|
---|
23 | public AwesomeTriangulationEvaluator() : base() { }
|
---|
24 |
|
---|
25 | public override IDeepCloneable Clone(Cloner cloner)
|
---|
26 | {
|
---|
27 | return new AwesomeTriangulationEvaluator(this, cloner);
|
---|
28 | }
|
---|
29 |
|
---|
30 | /// <summary>
|
---|
31 | /// Calculates the distance between two points using the rounded Euclidean distance metric.
|
---|
32 | /// </summary>
|
---|
33 | /// <param name="x1">The x-coordinate of point 1.</param>
|
---|
34 | /// <param name="y1">The y-coordinate of point 1.</param>
|
---|
35 | /// <param name="x2">The x-coordinate of point 2.</param>
|
---|
36 | /// <param name="y2">The y-coordinate of point 2.</param>
|
---|
37 | /// <returns>The calculated distance.</returns>
|
---|
38 | protected override double CalculateUpperTriangle(DoubleMatrix m, Permutation p)
|
---|
39 | {
|
---|
40 | int[] permutation = p.ToArray();
|
---|
41 |
|
---|
42 | //reduce offset, real arrays start with 0
|
---|
43 | if (!permutation.Contains(0)) { permutation = permutation.Select(v => v - 1).ToArray(); }
|
---|
44 |
|
---|
45 | double sum = 0;
|
---|
46 | for (int i = 1; i < m.Columns; i++)
|
---|
47 | {
|
---|
48 | for (int j = 0; j < i; j++)
|
---|
49 | {
|
---|
50 | sum += m[p[j], p[i]];
|
---|
51 | }
|
---|
52 | }
|
---|
53 |
|
---|
54 | return sum;
|
---|
55 | }
|
---|
56 | }
|
---|
57 | }
|
---|