Changeset 12395 for branches/HiveStatistics/sources/HeuristicLab.Problems.Instances.VehicleRouting/3.4/SolomonFormat/SolomonFormatInstanceProvider.cs
- Timestamp:
- 05/20/15 16:41:14 (10 years ago)
- Location:
- branches/HiveStatistics/sources
- Files:
-
- 2 edited
Legend:
- Unmodified
- Added
- Removed
-
branches/HiveStatistics/sources
- Property svn:mergeinfo changed
-
branches/HiveStatistics/sources/HeuristicLab.Problems.Instances.VehicleRouting/3.4/SolomonFormat/SolomonFormatInstanceProvider.cs
r11205 r12395 1 1 #region License Information 2 2 /* HeuristicLab 3 * Copyright (C) 2002-201 4Heuristic and Evolutionary Algorithms Laboratory (HEAL)3 * Copyright (C) 2002-2015 Heuristic and Evolutionary Algorithms Laboratory (HEAL) 4 4 * 5 5 * This file is part of HeuristicLab. … … 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 { 25 public abstract class SolomonFormatInstanceProvider : VRPInstanceProvider {26 protected override VRPData LoadData(Stream stream) {28 public abstract class SolomonFormatInstanceProvider : VRPInstanceProvider<CVRPTWData> { 29 protected override CVRPTWData LoadData(Stream stream) { 27 30 return LoadInstance(new SolomonParser(stream)); 28 31 } … … 31 34 get { return true; } 32 35 } 33 public override VRPData ImportData(string path) {36 public override CVRPTWData ImportData(string path) { 34 37 return LoadInstance(new SolomonParser(path)); 35 38 } … … 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 reader.ReadAllLines() 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 } 56 84 } 57 85 }
Note: See TracChangeset
for help on using the changeset viewer.