Free cookie consent management tool by TermsFeed Policy Generator

source: branches/GeneralizedQAP/HeuristicLab.Problems.Instances.ElloumiCTAP/3.3/ElloumiCTAPInstanceProvider.cs @ 7482

Last change on this file since 7482 was 7482, checked in by abeham, 12 years ago

#1614

  • Added a property ReferencePublication
  • Added a custom combobox that can display a tooltip for each item
  • Added tooltip for the different providers stating link and reference publication
File size: 4.3 KB
Line 
1#region License Information
2/* HeuristicLab
3 * Copyright (C) 2002-2012 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 System.Collections.Generic;
24using System.IO;
25using System.Linq;
26using System.Reflection;
27using System.Text.RegularExpressions;
28
29namespace HeuristicLab.Problems.Instances.ElloumiCTAP {
30  public class ElloumiCTAPInstanceProvider : ProblemInstanceProvider<ICTAPInstance> {
31    public override string Name {
32      get { return "Elloumi's CTAP instances"; }
33    }
34
35    public override string Description {
36      get { return "CTAP instances published by Sourour Elloumi"; }
37    }
38
39    public override Uri WebLink {
40      get { return new Uri("http://cedric.cnam.fr/oc/TAP/TAP.html"); }
41    }
42
43    public override string ReferencePublication {
44      get {
45        return @"Elloumi, S. 1991.
46Contribution for solving non linear programs with o-1 variables, application to task assignment problems in distributed systems.
47PhD Thesis. Conservatoire National des Arts et Métiers, Paris.";
48      }
49    }
50
51    public override IEnumerable<IInstanceDescriptor> GetInstanceDescriptors() {
52      var solutions = Assembly.GetExecutingAssembly()
53        .GetManifestResourceNames()
54        .Where(x => x.EndsWith(".sol"))
55        .ToDictionary(x => Path.GetFileNameWithoutExtension(x) + ".dat", x => x);
56
57      return Assembly.GetExecutingAssembly()
58          .GetManifestResourceNames()
59          .Where(x => x.EndsWith(".dat"))
60          .OrderBy(x => x)
61          .Select(x => new ElloumiCTAPInstanceDescriptor(GetPrettyName(x), GetDescription(), x, solutions.ContainsKey(x) ? solutions[x] : String.Empty));
62    }
63
64    public override ICTAPInstance GetInstance(IInstanceDescriptor id) {
65      var descriptor = (ElloumiCTAPInstanceDescriptor)id;
66      var instance = new ElloumiCTAPInstance();
67      using (var stream = Assembly.GetExecutingAssembly()
68        .GetManifestResourceStream(descriptor.InstanceIdentifier)) {
69        ElloumiCTAPParser datParser = new ElloumiCTAPParser();
70        datParser.Parse(stream);
71        if (datParser.Error != null) throw datParser.Error;
72        instance.Processors = datParser.Processors;
73        instance.Tasks = datParser.Tasks;
74        instance.ExecutionCosts = datParser.ExecutionCosts;
75        instance.CommunicationCosts = datParser.CommunicationCosts;
76        instance.MemoryRequirements = datParser.MemoryRequirements;
77        instance.MemoryCapacities = datParser.MemoryCapacities;
78
79        instance.Name = id.Name;
80        instance.Description = id.Description;
81
82        if (!String.IsNullOrEmpty(descriptor.SolutionIdentifier)) {
83          using (Stream solStream = Assembly.GetExecutingAssembly()
84            .GetManifestResourceStream(descriptor.SolutionIdentifier)) {
85            ElloumiCTAPSolutionParser slnParser = new ElloumiCTAPSolutionParser();
86            slnParser.Parse(solStream, instance.MemoryRequirements.Length);
87            if (slnParser.Error != null) throw slnParser.Error;
88
89            instance.BestKnownAssignment = slnParser.Assignment;
90            instance.BestKnownQuality = slnParser.Quality;
91          }
92        }
93      }
94      return instance;
95    }
96
97    private string GetPrettyName(string instanceIdentifier) {
98      return Regex.Match(instanceIdentifier, GetType().Namespace + @"\.Data\.(.*)\.dat").Groups[1].Captures[0].Value;
99    }
100
101    private string GetDescription() {
102      return "Embedded instance of plugin version " + Assembly.GetExecutingAssembly().GetCustomAttributes(typeof(AssemblyFileVersionAttribute), true).Cast<AssemblyFileVersionAttribute>().First().Version + ".";
103    }
104  }
105}
Note: See TracBrowser for help on using the repository browser.