- Timestamp:
- 06/19/12 13:17:29 (12 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/sources/HeuristicLab.Problems.Instances.VehicleRouting/3.4/CordeauFormat/CordeauParser.cs
r7891 r8053 1 1 #region License Information 2 2 /* HeuristicLab 3 * Copyright (C) 2002-201 0Heuristic and Evolutionary Algorithms Laboratory (HEAL)3 * Copyright (C) 2002-2012 Heuristic and Evolutionary Algorithms Laboratory (HEAL) 4 4 * 5 5 * This file is part of HeuristicLab. … … 118 118 } 119 119 120 public CordeauParser(string file): this() { 120 public CordeauParser(string file) 121 : this() { 121 122 this.file = file; 122 123 } 123 124 124 125 125 public CordeauParser(Stream stream) 126 : this() { 126 127 this.stream = stream; 127 128 } 128 129 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 if(type != 2 && type != 6)158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 130 public void Parse() { 131 string line; 132 Regex reg = new Regex(@"-?\d+(\.\d+)?"); 133 MatchCollection m; 134 135 StreamReader reader; 136 if (stream != null) { 137 reader = new StreamReader(stream); 138 } else { 139 reader = new StreamReader(file); 140 problemName = Path.GetFileNameWithoutExtension(file); 141 } 142 143 using (reader) { 144 List<double> depotXcoord = new List<double>(); 145 List<double> depotYcoord = new List<double>(); 146 List<double> depotReadyTime = new List<double>(); 147 List<double> depotDueTime = new List<double>(); 148 149 List<double> routeDueTime = new List<double>(); 150 151 line = reader.ReadLine(); 152 153 m = reg.Matches(line); 154 if (m.Count != 4) 155 throw new InvalidDataException("File has wrong format!"); 156 157 int type = int.Parse(m[0].Value); 158 if (type != 2 && type != 6) 159 throw new InvalidDataException("Unsupported instance type"); 160 161 bool timeWindows = type == 6; 162 vehicles = int.Parse(m[1].Value); 163 cities = int.Parse(m[2].Value); 164 depots = int.Parse(m[3].Value); 165 line = reader.ReadLine(); 166 167 for (int i = 0; i < depots; i++) { 168 m = reg.Matches(line); 169 if (m.Count != 2) { continue; } 170 171 routeDueTime.Add(double.Parse(m[0].Value, System.Globalization.CultureInfo.InvariantCulture)); 172 capacity.Add(double.Parse(m[1].Value, System.Globalization.CultureInfo.InvariantCulture)); 173 174 line = reader.ReadLine(); 175 } 176 177 while ((line != null)) { 178 m = reg.Matches(line); 179 180 if (demand.Count < cities) { 181 xCoord.Add(double.Parse(m[1].Value, System.Globalization.CultureInfo.InvariantCulture)); 182 yCoord.Add(double.Parse(m[2].Value, System.Globalization.CultureInfo.InvariantCulture)); 183 demand.Add((double)int.Parse(m[4].Value, System.Globalization.CultureInfo.InvariantCulture)); 184 serviceTime.Add(int.Parse(m[3].Value)); 185 186 if (timeWindows) { 187 readyTime.Add(int.Parse(m[m.Count - 2].Value)); 188 dueTime.Add(int.Parse(m[m.Count - 1].Value)); 189 } else { 190 readyTime.Add(0); 191 dueTime.Add(double.MaxValue); 192 } 193 } else { 194 depotXcoord.Add(double.Parse(m[1].Value, System.Globalization.CultureInfo.InvariantCulture)); 195 depotYcoord.Add(double.Parse(m[2].Value, System.Globalization.CultureInfo.InvariantCulture)); 196 197 if (timeWindows) { 198 depotReadyTime.Add(int.Parse(m[m.Count - 2].Value)); 199 depotDueTime.Add(int.Parse(m[m.Count - 1].Value)); 200 } else { 201 depotReadyTime.Add(0); 202 depotDueTime.Add(double.MaxValue); 203 } 204 } 205 206 line = reader.ReadLine(); 207 } 208 209 for (int i = 0; i < depotDueTime.Count; i++) { 210 if (!timeWindows) { 211 depotDueTime[i] = routeDueTime[i]; 212 } 213 if (depotDueTime[i] < double.Epsilon) 214 depotDueTime[i] = double.MaxValue; 215 } 216 217 xCoord.InsertRange(0, depotXcoord); 218 yCoord.InsertRange(0, depotYcoord); 219 readyTime.InsertRange(0, depotReadyTime); 220 dueTime.InsertRange(0, depotDueTime); 221 222 List<double> originalCapacities = new List<double>(capacity); 223 capacity.Clear(); 224 for (int i = 0; i < depots; i++) { 225 for (int j = 0; j < vehicles; j++) { 226 capacity.Add(originalCapacities[i]); 227 } 228 } 229 vehicles *= depots; 230 } 231 } 231 232 } 232 233 }
Note: See TracChangeset
for help on using the changeset viewer.