Free cookie consent management tool by TermsFeed Policy Generator

Ignore:
Timestamp:
10/17/14 11:43:40 (10 years ago)
Author:
pfleck
Message:

#2229:

  • Added fall-back for solution parsing to try the own .opt-Format.
  • Parsing uses InvariantCulture instead of a specific one.
  • Small refactoring.
Location:
trunk/sources/HeuristicLab.Problems.Instances.VehicleRouting/3.4
Files:
1 added
4 edited

Legend:

Unmodified
Added
Removed
  • trunk/sources/HeuristicLab.Problems.Instances.VehicleRouting/3.4/CordeauFormat/CordeauFormatInstanceProvider.cs

    r11442 r11478  
    4343    protected override void LoadSolution(Stream stream, TData instance) {
    4444      using (var reader = new StreamReader(stream)) {
    45         double costs = double.Parse(reader.ReadLine(), new CultureInfo("en-US"));
     45        double costs = double.Parse(reader.ReadLine(), CultureInfo.InvariantCulture);
    4646
    4747        var toursPerDepotQuery =
    48           from line in ReadAllLines(reader)
     48          from line in reader.ReadAllLines()
    4949          where !string.IsNullOrEmpty(line)
    5050          let tokens = line.Split(new[] { ' ' }, StringSplitOptions.RemoveEmptyEntries)
    5151          let depot = int.Parse(tokens[0])
    5252          //let vehicle = int.Parse(tokens[1])
    53           //let duration = double.Parse(tokens[2], new CultureInfo("en-US"))
    54           //let load = double.Parse(tokens[3], new CultureInfo("en-US"))
     53          //let duration = double.Parse(tokens[2], CultureInfo.InvariantCulture)
     54          //let load = double.Parse(tokens[3], new CultureInfo.InvariantCulture)
    5555          let customers = tokens.Skip(4).Where(t => !t.StartsWith("(")).Select(int.Parse)
    5656          let numberOfCustomers = customers.Count()
    57           //let serviceTimes = tokens.Skip(5).Where(t => t.StartsWith("(")).Select(t => double.Parse(t.Trim('(', ')'), new CultureInfo("en-US")))
     57          //let serviceTimes = tokens.Skip(5).Where(t => t.StartsWith("(")).Select(t => double.Parse(t.Trim('(', ')'), CultureInfo.InvariantCulture))
    5858          let stops = customers.Skip(1).Take(numberOfCustomers - 2).Select(s => s - 1)
    5959          select new { depot, /*vehicle,*/ stops } into assignment
     
    8989      return tourToVehicle.ToArray();
    9090    }
    91 
    92     private IEnumerable<string> ReadAllLines(StreamReader reader) {
    93       while (!reader.EndOfStream)
    94         yield return reader.ReadLine();
    95     }
    9691  }
    9792}
  • trunk/sources/HeuristicLab.Problems.Instances.VehicleRouting/3.4/HeuristicLab.Problems.Instances.VehicleRouting-3.4.csproj

    r11455 r11478  
    118118    <Compile Include="GoldenFormat\GoldenFormatInstanceProvider.cs" />
    119119    <Compile Include="IVRPInstanceProvider.cs" />
     120    <Compile Include="StreamReaderHelper.cs" />
    120121    <Compile Include="TaillardFormat\TaillardInstanceProvider.cs" />
    121122    <Compile Include="TaillardFormat\TaillardParser.cs" />
  • trunk/sources/HeuristicLab.Problems.Instances.VehicleRouting/3.4/SolomonFormat/SolomonFormatInstanceProvider.cs

    r11455 r11478  
    6767
    6868        var routesQuery =
    69           from line in ReadAllLines(reader)
     69          from line in reader.ReadAllLines()
    7070          where !string.IsNullOrEmpty(line)
    7171          let tokens = ExtractValue(line).Split(new[] { ' ' }, StringSplitOptions.RemoveEmptyEntries)
     
    8282      return line.Split(new[] { ':' }, StringSplitOptions.RemoveEmptyEntries).Last().Trim();
    8383    }
    84     private IEnumerable<string> ReadAllLines(StreamReader reader) {
    85       while (!reader.EndOfStream)
    86         yield return reader.ReadLine();
    87     }
    8884  }
    8985}
  • trunk/sources/HeuristicLab.Problems.Instances.VehicleRouting/3.4/VRPInstanceProvider.cs

    r11455 r11478  
    9292
    9393    protected virtual void LoadSolution(Stream stream, TData instance) {
     94      LoadOptFile(stream, instance);
     95    }
     96
     97    private void LoadOptFile(Stream stream, TData instance) {
    9498      List<List<int>> routes = new List<List<int>>();
    9599
     
    122126
    123127    public void LoadSolution(string path, TData instance) {
    124       using (FileStream stream = new FileStream(path, FileMode.Open)) {
    125         LoadSolution(stream, instance);
     128      try {
     129        using (var stream = new FileStream(path, FileMode.Open)) {
     130          LoadSolution(stream, instance);
     131        }
     132      } catch (Exception) {
     133        // new stream necessary because first try already read from stream
     134        using (var stream = new FileStream(path, FileMode.Open)) {
     135          LoadOptFile(stream, instance); // Fallback to .opt-Format
     136        }
    126137      }
    127138    }
Note: See TracChangeset for help on using the changeset viewer.