#region License Information /* HeuristicLab * Copyright (C) 2002-2010 Heuristic and Evolutionary Algorithms Laboratory (HEAL) * * This file is part of HeuristicLab. * * HeuristicLab is free software: you can redistribute it and/or modify * it under the terms of the GNU General Public License as published by * the Free Software Foundation, either version 3 of the License, or * (at your option) any later version. * * HeuristicLab is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * GNU General Public License for more details. * * You should have received a copy of the GNU General Public License * along with HeuristicLab. If not, see . */ #endregion using System.Collections.Generic; using System.IO; using System.Text.RegularExpressions; namespace HeuristicLab.PDPSimulation { class TSPLibDynPDPParser : DynPDPParser { public TSPLibDynPDPParser(string file) : base(file) { } public override void Parse() { string line; Regex reg = new Regex(@"-?(\d+\.\d+|\d+)"); MatchCollection m; using (var reader = new StreamReader(file)) { line = reader.ReadLine(); problemName = line.Split(':')[1].Remove(0, 1); line = reader.ReadLine(); string vehicleLine = problemName = line.Split(':')[1].Remove(0, 1); int vehicleCount = int.Parse(vehicleLine); line = reader.ReadLine(); string capacityLine = problemName = line.Split(':')[1].Remove(0, 1); int capacity = int.Parse(capacityLine); line = reader.ReadLine(); string dueTimeLine = problemName = line.Split(':')[1].Remove(0, 1); int dueTime = int.Parse(dueTimeLine); List xCoord = new List(); List yCoord = new List(); line = reader.ReadLine(); line = reader.ReadLine(); m = reg.Matches(line); while (m.Count == 3) { xCoord.Add(double.Parse(m[1].Value)); yCoord.Add(double.Parse(m[2].Value)); line = reader.ReadLine(); m = reg.Matches(line); } for (int i = 0; i < vehicleCount; i++) { Vehicle v = new Vehicle(); v.xCoord = xCoord[0]; v.yCoord = yCoord[0]; v.capacity = capacity; v.readyTime = 0; v.dueTime = dueTime; vehicles.Add(v); } line = reader.ReadLine(); m = reg.Matches(line); while (m.Count == 11) { Order o = new Order(); int pickupId = int.Parse(m[1].Value); int deliveryId = int.Parse(m[2].Value); double pickupTWOpen = double.Parse(m[3].Value); double pickupTWClose = double.Parse(m[4].Value); double pickupServiceTime = double.Parse(m[5].Value); double deliveryTWOpen = double.Parse(m[6].Value); double deliveryTWClose = double.Parse(m[7].Value); double deliveryServiceTime = double.Parse(m[8].Value); double demand = double.Parse(m[9].Value); double revealed = double.Parse(m[10].Value); o.revealedTime = revealed; o.pickupXCoord = xCoord[pickupId]; o.pickupYCoord = yCoord[pickupId]; o.deliveryXCoord = xCoord[deliveryId]; o.deliveryYCoord = yCoord[deliveryId]; o.demand = demand; o.pickupServiceTime = pickupServiceTime; o.pickupReadyTime = pickupTWOpen; o.pickupDueTime = pickupTWClose; o.deliveryServiceTime = deliveryServiceTime; o.deliveryReadyTime = deliveryTWOpen; o.deliveryDueTime = deliveryTWClose; orders.Add(o); line = reader.ReadLine(); m = reg.Matches(line); } } } } }