[8670] | 1 | #region License Information
|
---|
| 2 | /* HeuristicLab
|
---|
| 3 | * Copyright (C) 2002-2010 Heuristic and Evolutionary Algorithms Laboratory (HEAL)
|
---|
| 4 | *
|
---|
| 5 | * This file is part of HeuristicLab.
|
---|
| 6 | *
|
---|
| 7 | * HeuristicLab is free software: you can redistribute it and/or modify
|
---|
| 8 | * it under the terms of the GNU General Public License as published by
|
---|
| 9 | * the Free Software Foundation, either version 3 of the License, or
|
---|
| 10 | * (at your option) any later version.
|
---|
| 11 | *
|
---|
| 12 | * HeuristicLab is distributed in the hope that it will be useful,
|
---|
| 13 | * but WITHOUT ANY WARRANTY; without even the implied warranty of
|
---|
| 14 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
---|
| 15 | * GNU General Public License for more details.
|
---|
| 16 | *
|
---|
| 17 | * You should have received a copy of the GNU General Public License
|
---|
| 18 | * along with HeuristicLab. If not, see <http://www.gnu.org/licenses/>.
|
---|
| 19 | */
|
---|
| 20 | #endregion
|
---|
| 21 |
|
---|
| 22 | using System;
|
---|
| 23 | using System.Collections.Generic;
|
---|
| 24 | using System.IO;
|
---|
| 25 | using System.Text.RegularExpressions;
|
---|
| 26 |
|
---|
| 27 | namespace HeuristicLab.PDPSimulation {
|
---|
| 28 | class TSPLibDynPDPParser: DynPDPParser {
|
---|
| 29 | public TSPLibDynPDPParser(string file): base(file) {
|
---|
| 30 | }
|
---|
| 31 |
|
---|
| 32 | public override void Parse() {
|
---|
| 33 | string line;
|
---|
| 34 | Regex reg = new Regex(@"-?\d+");
|
---|
| 35 | MatchCollection m;
|
---|
| 36 |
|
---|
| 37 | StreamReader reader = new StreamReader(file);
|
---|
| 38 |
|
---|
| 39 | line = reader.ReadLine();
|
---|
| 40 | problemName = line.Split(':')[1].Remove(0, 1);
|
---|
| 41 |
|
---|
| 42 | line = reader.ReadLine();
|
---|
| 43 | string vehicleLine = problemName = line.Split(':')[1].Remove(0, 1);
|
---|
| 44 | int vehicleCount = int.Parse(vehicleLine);
|
---|
| 45 |
|
---|
| 46 | line = reader.ReadLine();
|
---|
| 47 | string capacityLine = problemName = line.Split(':')[1].Remove(0, 1);
|
---|
| 48 | int capacity = int.Parse(capacityLine);
|
---|
| 49 |
|
---|
| 50 | line = reader.ReadLine();
|
---|
| 51 | string dueTimeLine = problemName = line.Split(':')[1].Remove(0, 1);
|
---|
| 52 | int dueTime = int.Parse(dueTimeLine);
|
---|
| 53 |
|
---|
| 54 | List<double> xCoord = new List<double>();
|
---|
| 55 | List<double> yCoord = new List<double>();
|
---|
| 56 |
|
---|
| 57 | line = reader.ReadLine();
|
---|
| 58 | line = reader.ReadLine();
|
---|
| 59 | m = reg.Matches(line);
|
---|
| 60 | while (m.Count == 3) {
|
---|
| 61 | xCoord.Add(double.Parse(m[1].Value));
|
---|
| 62 | yCoord.Add(double.Parse(m[2].Value));
|
---|
| 63 |
|
---|
| 64 | line = reader.ReadLine();
|
---|
| 65 | m = reg.Matches(line);
|
---|
| 66 | }
|
---|
| 67 |
|
---|
| 68 | for (int i = 0; i < vehicleCount; i++) {
|
---|
| 69 | Vehicle v = new Vehicle();
|
---|
| 70 |
|
---|
| 71 | v.xCoord = xCoord[0];
|
---|
| 72 | v.yCoord = yCoord[0];
|
---|
| 73 | v.capacity = capacity;
|
---|
| 74 | v.readyTime = 0;
|
---|
| 75 | v.dueTime = dueTime;
|
---|
| 76 |
|
---|
| 77 | vehicles.Add(v);
|
---|
| 78 | }
|
---|
| 79 |
|
---|
| 80 | line = reader.ReadLine();
|
---|
| 81 | m = reg.Matches(line);
|
---|
| 82 |
|
---|
| 83 | while (m.Count == 11) {
|
---|
| 84 | Order o = new Order();
|
---|
| 85 |
|
---|
| 86 | int pickupId = int.Parse(m[1].Value);
|
---|
| 87 | int deliveryId = int.Parse(m[2].Value);
|
---|
| 88 | double pickupTWOpen = double.Parse(m[3].Value);
|
---|
| 89 | double pickupTWClose = double.Parse(m[4].Value);
|
---|
| 90 | double pickupServiceTime = double.Parse(m[5].Value);
|
---|
| 91 | double deliveryTWOpen = double.Parse(m[6].Value);
|
---|
| 92 | double deliveryTWClose = double.Parse(m[7].Value);
|
---|
| 93 | double deliveryServiceTime = double.Parse(m[8].Value);
|
---|
| 94 | double demand = double.Parse(m[9].Value);
|
---|
| 95 | double revealed = double.Parse(m[10].Value);
|
---|
| 96 |
|
---|
| 97 | o.revealedTime = revealed;
|
---|
| 98 | o.pickupXCoord = xCoord[pickupId];
|
---|
| 99 | o.pickupYCoord = yCoord[pickupId];
|
---|
| 100 | o.deliveryXCoord = xCoord[deliveryId];
|
---|
| 101 | o.deliveryYCoord = yCoord[deliveryId];
|
---|
| 102 | o.demand = demand;
|
---|
| 103 | o.pickupServiceTime = pickupServiceTime;
|
---|
| 104 | o.pickupReadyTime = pickupTWOpen;
|
---|
| 105 | o.pickupDueTime = pickupTWClose;
|
---|
| 106 | o.deliveryServiceTime = deliveryServiceTime;
|
---|
| 107 | o.deliveryReadyTime = deliveryTWOpen;
|
---|
| 108 | o.deliveryDueTime = deliveryTWClose;
|
---|
| 109 |
|
---|
| 110 | orders.Add(o);
|
---|
| 111 |
|
---|
| 112 | line = reader.ReadLine();
|
---|
| 113 | m = reg.Matches(line);
|
---|
| 114 | }
|
---|
| 115 | }
|
---|
| 116 | }
|
---|
| 117 | }
|
---|