Changeset 7842 for branches/HeuristicLab.TimeSeries/HeuristicLab.Problems.Instances.TSPLIB/3.3/TSPLIBCVRPInstanceProvider.cs
- Timestamp:
- 05/16/12 16:28:49 (12 years ago)
- Location:
- branches/HeuristicLab.TimeSeries
- Files:
-
- 2 edited
Legend:
- Unmodified
- Added
- Removed
-
branches/HeuristicLab.TimeSeries
- Property svn:mergeinfo changed
-
branches/HeuristicLab.TimeSeries/HeuristicLab.Problems.Instances.TSPLIB/3.3/TSPLIBCVRPInstanceProvider.cs
r7548 r7842 21 21 22 22 using System; 23 using System.Collections.Generic;24 23 using System.IO; 25 using System.Linq;26 using System.Reflection;27 using System.Text.RegularExpressions;28 24 29 25 namespace HeuristicLab.Problems.Instances.TSPLIB { 30 public class TSPLIBCVRPInstanceProvider : ProblemInstanceProvider<CVRPData> {26 public class TSPLIBCVRPInstanceProvider : TSPLIBInstanceProvider<CVRPData> { 31 27 32 28 public override string Name { … … 38 34 } 39 35 40 public override Uri WebLink { 41 get { return new Uri("http://comopt.ifi.uni-heidelberg.de/software/TSPLIB95/"); } 42 } 36 protected override string FileExtension { get { return "vrp"; } } 43 37 44 public override string ReferencePublication { 45 get { 46 return @"G. Reinelt. 1991. 47 TSPLIB - A Traveling Salesman Problem Library. 48 ORSA Journal on Computing, 3, pp. 376-384."; 49 } 50 } 51 52 public override IEnumerable<IDataDescriptor> GetDataDescriptors() { 53 var solutions = Assembly.GetExecutingAssembly() 54 .GetManifestResourceNames() 55 .Where(x => Regex.Match(x, @".*\.Data\.CVRP\..*").Success) 56 .Where(x => x.EndsWith(".opt.tour")) 57 .ToDictionary(x => x.Substring(0, x.Length - ".opt.tour".Length) + ".vrp", x => x); 58 59 return Assembly.GetExecutingAssembly() 60 .GetManifestResourceNames() 61 .Where(x => Regex.Match(x, @".*\.Data\.CVRP\..*").Success) 62 .OrderBy(x => x) 63 .Select(x => new TSPLIBDataDescriptor(GetPrettyName(x), GetDescription(), x, solutions.ContainsKey(x) ? solutions[x] : String.Empty)); 64 } 65 66 public override CVRPData LoadData(IDataDescriptor id) { 67 var descriptor = (TSPLIBDataDescriptor)id; 68 using (var stream = Assembly.GetExecutingAssembly() 69 .GetManifestResourceStream(descriptor.InstanceIdentifier)) { 70 var instance = Load(new TSPLIBParser(stream)); 71 72 if (!String.IsNullOrEmpty(descriptor.SolutionIdentifier)) { 73 using (Stream solStream = Assembly.GetExecutingAssembly() 74 .GetManifestResourceStream(descriptor.SolutionIdentifier)) { 75 var slnParser = new TSPLIBParser(solStream); 76 slnParser.Parse(); 77 instance.BestKnownTour = slnParser.Tour; 78 } 79 } 80 return instance; 81 } 82 } 83 84 public override CVRPData LoadData(string path) { 85 return Load(new TSPLIBParser(path)); 86 } 87 88 public override void SaveData(CVRPData instance, string path) { 89 throw new NotSupportedException(); 90 } 91 92 private CVRPData Load(TSPLIBParser parser) { 38 protected override CVRPData LoadInstance(TSPLIBParser parser) { 93 39 parser.Parse(); 94 40 var instance = new CVRPData(); … … 123 69 instance.Description = parser.Comment 124 70 + Environment.NewLine + Environment.NewLine 125 + Get Description();71 + GetInstanceDescription(); 126 72 127 73 return instance; 128 74 } 129 75 130 private string GetPrettyName(string instanceIdentifier) { 131 return Regex.Match(instanceIdentifier, GetType().Namespace + @"\.Data\.CVRP\.(.*)\.vrp").Groups[1].Captures[0].Value; 132 } 133 134 private string GetDescription() { 135 return "Embedded instance of plugin version " + Assembly.GetExecutingAssembly().GetCustomAttributes(typeof(AssemblyFileVersionAttribute), true).Cast<AssemblyFileVersionAttribute>().First().Version + "."; 76 protected override void LoadSolution(TSPLIBParser parser, CVRPData instance) { 77 parser.Parse(); 78 instance.BestKnownTour = parser.Tour; 136 79 } 137 80 }
Note: See TracChangeset
for help on using the changeset viewer.