Free cookie consent management tool by TermsFeed Policy Generator

source: branches/QAPGenerators/HeuristicLab.Problems.Instances.QAPGenerator/3.3/Generators/TaillardQAPInstanceGenerator.cs @ 14704

Last change on this file since 14704 was 14704, checked in by abeham, 7 years ago

#2738: added branch

File size: 5.4 KB
Line 
1#region License Information
2/* HeuristicLab
3 * Copyright (C) 2002-2013 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 System;
23using HeuristicLab.Core;
24
25namespace HeuristicLab.Problems.Instances.QAPGenerator {
26  public static class TaillardQAPInstanceGenerator {
27    /// <summary>
28    /// Generates two random symmetric matrices with independent uniformly distributed elements in the range [0;100[.
29    /// The generated instances are referred to as Tai-a or taiXXa instances published in the literature.
30    /// The instance generator is described in E. Taillard. 1991. Robust Taboo Search for the Quadratic Assignment Problem. Parallel Computing, Vol 17, pp. 443-455.
31    /// </summary>
32    /// <param name="N">The width and height of the matrices to generate, i.e. the size of the problem instance.</param>
33    /// <param name="A">The flow matrix.</param>
34    /// <param name="B">The distance matrix.</param>
35    /// <param name="random">The random number generator to use, in case this is omitted Taillard's default PRNG and seed will be used.</param>
36    public static void GenerateTaia(int N, out double[,] A, out double[,] B, IRandom random = null) {
37      if (random == null) random = new Bratley(123456789);
38      A = new double[N, N];
39      B = new double[N, N];
40      for (var i = 0; i < N - 1; i++) {
41        for (var j = i + 1; j < N; j++) {
42          A[i, j] = Math.Floor(100.0 * random.NextDouble());
43          A[j, i] = A[i, j];
44        }
45      }
46      for (var i = 0; i < N - 1; i++) {
47        for (var j = i + 1; j < N; j++) {
48          B[i, j] = Math.Floor(100.0 * random.NextDouble());
49          B[j, i] = B[i, j];
50        }
51      }
52    }
53
54    /// <summary>
55    /// The generated instances are referred to as Tai-b or taiXXb instances published in the literature.
56    /// The instance generator is described in E. Taillard. 1995. Comparison of iterative searches for the quadratic assignment problem. Location Science, Vol 3, No. 2, pp. 87-105.
57    /// </summary>
58    /// <param name="N">The width and height of the matrices to generate, i.e. the size of the problem instance.</param>
59    /// <param name="maxClusterDistance">The maximum radius of the disc that contains the clusters.</param>
60    /// <param name="maxClusterSize">The maximum size of clustered locations.</param>
61    /// <param name="maxClusterRadius">The maximum radius of the disc that contains the clustered locations.</param>
62    /// <param name="minFlowExponent">The minimum exponent that determines the flows to other facilities.</param>
63    /// <param name="maxFlowExponent">The maximum exponent that determines the flows to other facilities.</param>
64    /// <param name="A">The flow matrix.</param>
65    /// <param name="B">The distance matrix.</param>
66    /// <param name="random">The random number generator to use, in case this is omitted Taillard's default PRNG and seed will be used.</param>
67    public static void GenerateTaib(int N, int maxClusterDistance, int maxClusterSize, int maxClusterRadius, int minFlowExponent, int maxFlowExponent, out double[,] A, out double[,] B, IRandom random = null) {
68      if (random == null) random = new Bratley(123456789);
69      var locations = new double[N, 2];
70      var loc = 0;
71      while (loc < N) {
72        var clusterDirection = random.NextDouble() * 2 * Math.PI;
73        var clusterDistance = random.NextDouble() * maxClusterDistance;
74        var clusterSize = random.Next(1, maxClusterSize);
75        for (var i = 0; i < clusterSize; i++) {
76          var locationDirection = random.NextDouble() * 2 * Math.PI;
77          var locationDistance = random.NextDouble() * maxClusterRadius;
78          locations[loc, 0] = clusterDistance * Math.Cos(clusterDirection) +
79                              locationDistance * Math.Cos(locationDirection);
80          locations[loc, 1] = clusterDistance * Math.Sin(clusterDirection) +
81                              locationDistance * Math.Sin(locationDirection);
82          loc++;
83          if (loc == N) break;
84        }
85      }
86
87      A = new double[N, N];
88      for (var i = 0; i < N - 1; i++) {
89        for (var j = i + 1; j < N; j++) {
90          A[i, j] = Math.Sqrt((locations[i, 0] - locations[j, 0]) * (locations[i, 0] - locations[j, 0])
91                              + (locations[i, 1] - locations[j, 1]) * (locations[i, 1] - locations[j, 1]));
92          A[j, i] = A[i, j];
93        }
94      }
95
96      B = new double[N, N];
97      for (var i = 0; i < N - 1; i++) {
98        for (var j = i + 1; j < N; j++) {
99          B[i, j] = Math.Floor(Math.Pow(10, (maxFlowExponent - minFlowExponent) * random.NextDouble() + minFlowExponent));
100          B[j, i] = B[i, j];
101        }
102      }
103    }
104  }
105}
Note: See TracBrowser for help on using the repository browser.