- Timestamp:
- 10/13/14 10:22:05 (10 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/sources/HeuristicLab.Problems.Instances.VehicleRouting/3.4/SolomonFormat/SolomonFormatInstanceProvider.cs
r11286 r11455 20 20 #endregion 21 21 22 using System; 23 using System.Collections.Generic; 22 24 using System.IO; 25 using System.Linq; 23 26 24 27 namespace HeuristicLab.Problems.Instances.VehicleRouting { … … 54 57 return instance; 55 58 } 59 60 protected override void LoadSolution(Stream stream, CVRPTWData instance) { 61 using (var reader = new StreamReader(stream)) { 62 string instanceName = ExtractValue(reader.ReadLine()); 63 string authors = ExtractValue(reader.ReadLine()); 64 string date = ExtractValue(reader.ReadLine()); 65 string reference = ExtractValue(reader.ReadLine()); 66 reader.ReadLine(); // Solution 67 68 var routesQuery = 69 from line in ReadAllLines(reader) 70 where !string.IsNullOrEmpty(line) 71 let tokens = ExtractValue(line).Split(new[] { ' ' }, StringSplitOptions.RemoveEmptyEntries) 72 let stops = tokens.Select(int.Parse).Select(s => s - 1) 73 select stops; 74 75 var routes = routesQuery.Select(s => s.ToArray()).ToArray(); 76 77 instance.BestKnownTour = routes; 78 } 79 } 80 81 private static string ExtractValue(string line) { 82 return line.Split(new[] { ':' }, StringSplitOptions.RemoveEmptyEntries).Last().Trim(); 83 } 84 private IEnumerable<string> ReadAllLines(StreamReader reader) { 85 while (!reader.EndOfStream) 86 yield return reader.ReadLine(); 87 } 56 88 } 57 89 }
Note: See TracChangeset
for help on using the changeset viewer.