#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.IO; using System.Text.RegularExpressions; namespace HeuristicLab.PDPSimulation { class DefaultDynPDPParser : DynPDPParser { public DefaultDynPDPParser(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; line = reader.ReadLine(); int vehicleCount = int.Parse(line); for (int i = 0; i < vehicleCount; i++) { line = reader.ReadLine(); m = reg.Matches(line); Vehicle v = new Vehicle(); v.xCoord = double.Parse(m[0].Value, System.Globalization.CultureInfo.InvariantCulture); v.yCoord = double.Parse(m[1].Value, System.Globalization.CultureInfo.InvariantCulture); v.capacity = double.Parse(m[2].Value, System.Globalization.CultureInfo.InvariantCulture); v.readyTime = double.Parse(m[3].Value, System.Globalization.CultureInfo.InvariantCulture); v.dueTime = double.Parse(m[4].Value, System.Globalization.CultureInfo.InvariantCulture); vehicles.Add(v); } line = reader.ReadLine(); int orderCount = int.Parse(line); m = reg.Matches(line); for (int i = 0; i < orderCount; i++) { line = reader.ReadLine(); m = reg.Matches(line); Order o = new Order(); o.revealedTime = double.Parse(m[0].Value, System.Globalization.CultureInfo.InvariantCulture); o.pickupXCoord = double.Parse(m[1].Value, System.Globalization.CultureInfo.InvariantCulture); o.pickupYCoord = double.Parse(m[2].Value, System.Globalization.CultureInfo.InvariantCulture); o.deliveryXCoord = double.Parse(m[3].Value, System.Globalization.CultureInfo.InvariantCulture); o.deliveryYCoord = double.Parse(m[4].Value, System.Globalization.CultureInfo.InvariantCulture); o.demand = double.Parse(m[5].Value, System.Globalization.CultureInfo.InvariantCulture); o.pickupServiceTime = double.Parse(m[6].Value, System.Globalization.CultureInfo.InvariantCulture); o.pickupReadyTime = double.Parse(m[7].Value, System.Globalization.CultureInfo.InvariantCulture); o.pickupDueTime = double.Parse(m[8].Value, System.Globalization.CultureInfo.InvariantCulture); o.deliveryServiceTime = double.Parse(m[9].Value, System.Globalization.CultureInfo.InvariantCulture); o.deliveryReadyTime = double.Parse(m[10].Value, System.Globalization.CultureInfo.InvariantCulture); o.deliveryDueTime = double.Parse(m[11].Value, System.Globalization.CultureInfo.InvariantCulture); orders.Add(o); } } } } }