Free cookie consent management tool by TermsFeed Policy Generator

source: branches/2457_ExpertSystem/HeuristicLab.Problems.Instances.QAPLIB/3.3/OneSizeInstanceProvider.cs @ 18242

Last change on this file since 18242 was 16096, checked in by abeham, 6 years ago

#2457:

  • Changed calculation of correlation length (using limit introduced Hordijk 1996)
  • Changed RuggednessCalculator (no more a HL item)
  • Added additional, information-analysis-based features for directed walks
  • Added generic DirectedWalk algorithm (as described in thesis)
  • Made OneSizeInstanceProvider parametrizable
  • Adapted program for analyzing problem instance reidentification
File size: 5.0 KB
Line 
1using System;
2using System.Collections.Generic;
3using System.Linq;
4using System.Text.RegularExpressions;
5using HeuristicLab.Common;
6
7namespace HeuristicLab.Problems.Instances.QAPLIB {
8  public class OneSize10InstanceProvider : OneSizeInstanceProvider {
9    public OneSize10InstanceProvider() : base(10) { }
10  }
11  public class OneSize25InstanceProvider : OneSizeInstanceProvider {
12    public OneSize25InstanceProvider() : base(25) { }
13  }
14  public class OneSize50InstanceProvider : OneSizeInstanceProvider {
15    public OneSize50InstanceProvider() : base(50) { }
16  }
17  public class OneSize100InstanceProvider : OneSizeInstanceProvider {
18    public OneSize100InstanceProvider() : base(100) { }
19  }
20
21  public class OneSizeInstanceProvider : ProblemInstanceProvider<QAPData> {
22    public override string Name { get { return "One Size (n = " + Dimension + ")"; } }
23    public override string Description { get { return "Instances from various libraries reduced to a dimension of " + Dimension + "."; } }
24    public override Uri WebLink { get { return null; } }
25    public override string ReferencePublication {
26      get {
27        return
28@"A. Beham, E. Pitzer, S. Wagner, M. Affenzeller. 2017.
29Integrating Exploratory Landscape Analysis into Metaheuristic Algorithms.
30Lecture Notes in Computer Science 10671, Las Palmas de Gran Canaria, Spanien, pp. 473-480";
31      }
32    }
33
34    public int Dimension { get; private set; }
35
36    public OneSizeInstanceProvider(int dimension) {
37      Dimension = dimension;
38    }
39
40    public override IEnumerable<IDataDescriptor> GetDataDescriptors() {
41      var drezner = new DreznerQAPInstanceProvider();
42      foreach (var desc in drezner.GetDataDescriptors()) {
43        var dim = int.Parse(Regex.Match(desc.Name, "dre(?<g>\\d+)").Groups["g"].Value);
44        if (dim < Dimension) continue;
45        yield return new OneSizeDataDescriptor(desc.Name + (dim == Dimension ? "" : "-" + Dimension), desc.Description, drezner, desc);
46      }
47      // Microarray instances are all greater than 25 dimensions
48      var microarray = new MicroarrayQAPInstanceProvider();
49      foreach (var desc in microarray.GetDataDescriptors()) {
50        var instance = microarray.LoadData(desc);
51        if (instance.Dimension < Dimension) continue;
52        yield return new OneSizeDataDescriptor(desc.Name + (instance.Dimension == Dimension ? "" : "-" + Dimension), desc.Description, microarray, desc);
53      }
54      var qaplib = new QAPLIBInstanceProvider();
55      foreach (var desc in qaplib.GetDataDescriptors()) {
56        var instance = qaplib.LoadData(desc);
57        if (instance.Dimension < Dimension) continue;
58        yield return new OneSizeDataDescriptor(desc.Name + (instance.Dimension == Dimension ? "" : "-" + Dimension), desc.Description, qaplib, desc);
59      }
60      // Taillard's instances are basically from the same distribution
61      // to avoid over-representation in the set only the tai27e are taken and reduced to 25 dimension
62      var taillard = new TaillardQAPInstanceProvider();
63      var count = 0;
64      foreach (var desc in taillard.GetDataDescriptors().OrderBy(x => x.Name, new NaturalStringComparer())) {
65        var dim = int.Parse(Regex.Match(desc.Name, "tai(?<g>\\d+)e").Groups["g"].Value);
66        if (dim < Dimension) continue;
67        yield return new OneSizeDataDescriptor(desc.Name + (dim == Dimension ? "" : "-" + Dimension), desc.Description, taillard, desc);
68        if (++count == 10) break;
69      }
70    }
71
72    public override QAPData LoadData(IDataDescriptor descriptor) {
73      var desc = (OneSizeDataDescriptor)descriptor;
74      var data = desc.ActualProvider.LoadData(desc.ActualDescriptor);
75
76      if (data.Dimension <= Dimension) {
77        return data;
78      }
79      var rand = new Random(data.Dimension);
80
81      var tmp = Enumerable.Range(0, data.Dimension).ToArray();
82      Shuffle(tmp, rand);
83      var throwAway = new bool[data.Dimension];
84      foreach (var t in tmp.Take(data.Dimension - Dimension))
85        throwAway[t] = true;
86
87      var weights = new double[Dimension, Dimension];
88      var distances = new double[Dimension, Dimension];
89      var k = 0;
90      for (var i = 0; i < data.Dimension; i++) {
91        if (throwAway[i]) continue;
92        var h = 0;
93        for (var j = 0; j < data.Dimension; j++) {
94          if (throwAway[j]) continue;
95          weights[k, h] = data.Weights[i, j];
96          distances[k, h] = data.Distances[i, j];
97          h++;
98        }
99        k++;
100      }
101
102      data.Weights = weights;
103      data.Distances = distances;
104      data.BestKnownAssignment = null;
105      data.BestKnownQuality = null;
106      data.Dimension = Dimension;
107      data.Name += "-" + Dimension;
108      data.Description += " (reduced to " + Dimension + " dimensions)";
109
110      return data;
111    }
112   
113    private static void Shuffle(int[] p, Random random) {
114      for (var i = p.Length - 1; i > 0; i--) {
115        var swapIndex = random.Next(i + 1);
116        var h = p[swapIndex];
117        p[swapIndex] = p[i];
118        p[i] = h;
119      }
120    }
121  }
122}
Note: See TracBrowser for help on using the repository browser.