[14678] | 1 | using System;
|
---|
| 2 | using System.Collections.Generic;
|
---|
| 3 | using System.Linq;
|
---|
| 4 | using System.Threading.Tasks;
|
---|
| 5 | using HeuristicLab.PluginInfrastructure;
|
---|
| 6 | using HeuristicLab.Problems.Instances;
|
---|
| 7 | using HeuristicLab.Problems.Instances.QAPLIB;
|
---|
| 8 | using HeuristicLab.Problems.QuadraticAssignment;
|
---|
| 9 |
|
---|
| 10 | namespace ProblemInstanceIdentifier {
|
---|
| 11 | class Program {
|
---|
| 12 | static void Main(string[] args) {
|
---|
| 13 | var sync = new object();
|
---|
| 14 |
|
---|
| 15 | var qapProviders = ApplicationManager.Manager.GetInstances<ProblemInstanceProvider<QAPData>>().ToList();
|
---|
| 16 | var instances = new List<QuadraticAssignmentProblem>();
|
---|
| 17 | foreach (var provider in qapProviders) {
|
---|
| 18 | if (provider is TaillardQAPInstanceProvider) continue;
|
---|
| 19 | Parallel.ForEach(provider.GetDataDescriptors(), desc => {
|
---|
| 20 | if (desc.Name == "esc16f") return;
|
---|
| 21 | var qapData = provider.LoadData(desc);
|
---|
| 22 | if (qapData.Dimension < 15 || qapData.Dimension > 150) return;
|
---|
| 23 | var qap = new QuadraticAssignmentProblem();
|
---|
| 24 | qap.Load(qapData);
|
---|
| 25 | lock (sync) {
|
---|
| 26 | instances.Add(qap);
|
---|
| 27 | }
|
---|
| 28 | });
|
---|
| 29 | }
|
---|
| 30 |
|
---|
| 31 | Console.WriteLine("{0}\t{1}\t{2}\t{3}\t{4}\t{5}\t{6:F2}\t{7:F2}", "Repetition", "KB-Paths", "Exp-Paths", "Cls-Hits", "Exact-Hits", "No-Hits", "Cls-Rank", "Exact-Rank");
|
---|
| 32 | var paths = new[] { 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 20, 30, 40, 50 };
|
---|
| 33 | for (var r = 0; r < 20; r++) {
|
---|
| 34 | Parallel.ForEach(paths, kbPaths => {
|
---|
| 35 | foreach (var expPaths in paths) {
|
---|
| 36 | if (expPaths > kbPaths) continue;
|
---|
| 37 | var kb = new List<InstanceDescriptor>();
|
---|
| 38 | var exp = new List<InstanceDescriptor>();
|
---|
| 39 | foreach (var qap in instances) {
|
---|
| 40 | kb.Add(InstanceDescriptor.FromPathRelinkingAnalysis(qap, kbPaths, null));
|
---|
| 41 | exp.Add(InstanceDescriptor.FromPathRelinkingAnalysis(qap, expPaths, null));
|
---|
| 42 | }
|
---|
| 43 | int exactCount = 0, clsCount = 0, missedCount = 0;
|
---|
| 44 | int exactRank = 0, clsRank = 0;
|
---|
| 45 | foreach (var e in exp) {
|
---|
| 46 | var ordered = kb.OrderBy(x => x.CalculateSimilarity(e)).ToList();
|
---|
| 47 | var bestMatch = ordered.First();
|
---|
| 48 | if (bestMatch.Cls == e.Cls) {
|
---|
| 49 | clsCount++;
|
---|
| 50 | if (bestMatch.Name == e.Name) exactCount++;
|
---|
| 51 | } else missedCount++;
|
---|
| 52 | clsRank += ordered.FindIndex((id) => id.Cls == e.Cls) + 1;
|
---|
| 53 | exactRank += ordered.FindIndex((id) => id.Name == e.Name) + 1;
|
---|
| 54 | }
|
---|
| 55 | lock (sync) {
|
---|
| 56 | Console.WriteLine("{0}\t{1}\t{2}\t{3}\t{4}\t{5}\t{6:F2}\t{7:F2}", r, kbPaths, expPaths, clsCount, exactCount, missedCount, clsRank / (double)exp.Count, exactRank / (double)exp.Count);
|
---|
| 57 | }
|
---|
| 58 | }
|
---|
| 59 | });
|
---|
| 60 | }
|
---|
| 61 | }
|
---|
| 62 | }
|
---|
| 63 | }
|
---|