- Timestamp:
- 09/21/12 10:11:15 (12 years ago)
- Location:
- branches/DynamicVehicleRouting/HeuristicLab.PDPSimulation/3.3/Parsers
- Files:
-
- 2 edited
Legend:
- Unmodified
- Added
- Removed
-
branches/DynamicVehicleRouting/HeuristicLab.PDPSimulation/3.3/Parsers/DefaultDynPDPParser.cs
r8670 r8675 20 20 #endregion 21 21 22 using System;23 using System.Collections.Generic;24 22 using System.IO; 25 23 using System.Text.RegularExpressions; 26 24 27 25 namespace HeuristicLab.PDPSimulation { 28 class DefaultDynPDPParser: DynPDPParser { 29 public DefaultDynPDPParser(string file): base(file) { 26 class DefaultDynPDPParser : DynPDPParser { 27 public DefaultDynPDPParser(string file) 28 : base(file) { 30 29 } 31 30 32 31 public override void Parse() { 33 32 string line; 34 Regex reg = new Regex(@"-? \d+");33 Regex reg = new Regex(@"-?(\d+\.\d+|\d+)"); 35 34 MatchCollection m; 36 35 37 StreamReader reader = new StreamReader(file);36 using (var reader = new StreamReader(file)) { 38 37 39 line = reader.ReadLine();40 problemName = line;38 line = reader.ReadLine(); 39 problemName = line; 41 40 42 line = reader.ReadLine();43 int vehicleCount = int.Parse(line);41 line = reader.ReadLine(); 42 int vehicleCount = int.Parse(line); 44 43 45 for (int i = 0; i < vehicleCount; i++) { 44 for (int i = 0; i < vehicleCount; i++) { 45 line = reader.ReadLine(); 46 m = reg.Matches(line); 47 Vehicle v = new Vehicle(); 48 49 v.xCoord = double.Parse(m[0].Value); 50 v.yCoord = double.Parse(m[1].Value); 51 v.capacity = double.Parse(m[2].Value); 52 v.readyTime = double.Parse(m[3].Value); 53 v.dueTime = double.Parse(m[4].Value); 54 55 vehicles.Add(v); 56 } 57 46 58 line = reader.ReadLine(); 59 int orderCount = int.Parse(line); 47 60 m = reg.Matches(line); 48 Vehicle v = new Vehicle(); 61 for (int i = 0; i < orderCount; i++) { 62 line = reader.ReadLine(); 63 m = reg.Matches(line); 64 Order o = new Order(); 49 65 50 v.xCoord = double.Parse(m[0].Value); 51 v.yCoord = double.Parse(m[1].Value); 52 v.capacity = double.Parse(m[2].Value); 53 v.readyTime = double.Parse(m[3].Value); 54 v.dueTime = double.Parse(m[4].Value); 66 o.revealedTime = double.Parse(m[0].Value); 67 o.pickupXCoord = double.Parse(m[1].Value); 68 o.pickupYCoord = double.Parse(m[2].Value); 69 o.deliveryXCoord = double.Parse(m[3].Value); 70 o.deliveryYCoord = double.Parse(m[4].Value); 71 o.demand = double.Parse(m[5].Value); 72 o.pickupServiceTime = double.Parse(m[6].Value); 73 o.pickupReadyTime = double.Parse(m[7].Value); 74 o.pickupDueTime = double.Parse(m[8].Value); 75 o.deliveryServiceTime = double.Parse(m[9].Value); 76 o.deliveryReadyTime = double.Parse(m[10].Value); 77 o.deliveryDueTime = double.Parse(m[11].Value); 55 78 56 vehicles.Add(v); 57 } 58 59 line = reader.ReadLine(); 60 int orderCount = int.Parse(line); 61 m = reg.Matches(line); 62 for (int i = 0; i < orderCount; i++) { 63 line = reader.ReadLine(); 64 m = reg.Matches(line); 65 Order o = new Order(); 66 67 o.revealedTime = double.Parse(m[0].Value); 68 o.pickupXCoord = double.Parse(m[1].Value); 69 o.pickupYCoord = double.Parse(m[2].Value); 70 o.deliveryXCoord = double.Parse(m[3].Value); 71 o.deliveryYCoord = double.Parse(m[4].Value); 72 o.demand = double.Parse(m[5].Value); 73 o.pickupServiceTime = double.Parse(m[6].Value); 74 o.pickupReadyTime = double.Parse(m[7].Value); 75 o.pickupDueTime = double.Parse(m[8].Value); 76 o.deliveryServiceTime = double.Parse(m[9].Value); 77 o.deliveryReadyTime = double.Parse(m[10].Value); 78 o.deliveryDueTime = double.Parse(m[11].Value); 79 80 orders.Add(o); 79 orders.Add(o); 80 } 81 81 } 82 82 } -
branches/DynamicVehicleRouting/HeuristicLab.PDPSimulation/3.3/Parsers/TSPLibDynPDPParser.cs
r8670 r8675 20 20 #endregion 21 21 22 using System;23 22 using System.Collections.Generic; 24 23 using System.IO; … … 26 25 27 26 namespace HeuristicLab.PDPSimulation { 28 class TSPLibDynPDPParser: DynPDPParser { 29 public TSPLibDynPDPParser(string file): base(file) { 27 class TSPLibDynPDPParser : DynPDPParser { 28 public TSPLibDynPDPParser(string file) 29 : base(file) { 30 30 } 31 31 32 32 public override void Parse() { 33 33 string line; 34 Regex reg = new Regex(@"-? \d+");34 Regex reg = new Regex(@"-?(\d+\.\d+|\d+)"); 35 35 MatchCollection m; 36 36 37 StreamReader reader = new StreamReader(file);37 using (var reader = new StreamReader(file)) { 38 38 39 line = reader.ReadLine();40 problemName = line.Split(':')[1].Remove(0, 1);39 line = reader.ReadLine(); 40 problemName = line.Split(':')[1].Remove(0, 1); 41 41 42 line = reader.ReadLine();43 string vehicleLine = problemName = line.Split(':')[1].Remove(0, 1);44 int vehicleCount = int.Parse(vehicleLine);42 line = reader.ReadLine(); 43 string vehicleLine = problemName = line.Split(':')[1].Remove(0, 1); 44 int vehicleCount = int.Parse(vehicleLine); 45 45 46 line = reader.ReadLine();47 string capacityLine = problemName = line.Split(':')[1].Remove(0, 1);48 int capacity = int.Parse(capacityLine);46 line = reader.ReadLine(); 47 string capacityLine = problemName = line.Split(':')[1].Remove(0, 1); 48 int capacity = int.Parse(capacityLine); 49 49 50 line = reader.ReadLine();51 string dueTimeLine = problemName = line.Split(':')[1].Remove(0, 1);52 int dueTime = int.Parse(dueTimeLine);50 line = reader.ReadLine(); 51 string dueTimeLine = problemName = line.Split(':')[1].Remove(0, 1); 52 int dueTime = int.Parse(dueTimeLine); 53 53 54 List<double> xCoord = new List<double>();55 List<double> yCoord = new List<double>();54 List<double> xCoord = new List<double>(); 55 List<double> yCoord = new List<double>(); 56 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)); 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 } 63 79 64 80 line = reader.ReadLine(); 65 81 m = reg.Matches(line); 66 }67 82 68 for (int i = 0; i < vehicleCount; i++) {69 Vehicle v = new Vehicle();83 while (m.Count == 11) { 84 Order o = new Order(); 70 85 71 v.xCoord = xCoord[0]; 72 v.yCoord = yCoord[0]; 73 v.capacity = capacity; 74 v.readyTime = 0; 75 v.dueTime = dueTime; 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); 76 96 77 vehicles.Add(v); 78 } 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; 79 109 80 line = reader.ReadLine(); 81 m = reg.Matches(line); 110 orders.Add(o); 82 111 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); 112 line = reader.ReadLine(); 113 m = reg.Matches(line); 114 } 114 115 } 115 116 }
Note: See TracChangeset
for help on using the changeset viewer.