Free cookie consent management tool by TermsFeed Policy Generator

Ignore:
Timestamp:
10/13/14 10:22:05 (10 years ago)
Author:
pfleck
Message:

#2229

  • Added Homberger known solutions.
  • Implemented solution parser in SolomonFormatInstanceProvider.
  • Updated Homberger instances to match the original file names.
  • Changed ordering of VRP instances to natural string ordering.
File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/sources/HeuristicLab.Problems.Instances.VehicleRouting/3.4/SolomonFormat/SolomonFormatInstanceProvider.cs

    r11286 r11455  
    2020#endregion
    2121
     22using System;
     23using System.Collections.Generic;
    2224using System.IO;
     25using System.Linq;
    2326
    2427namespace HeuristicLab.Problems.Instances.VehicleRouting {
     
    5457      return instance;
    5558    }
     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    }
    5688  }
    5789}
Note: See TracChangeset for help on using the changeset viewer.