- Timestamp:
- 06/19/12 13:17:29 (13 years ago)
- Location:
- trunk/sources/HeuristicLab.Problems.Instances.VehicleRouting/3.4
- Files:
-
- 5 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 } -
trunk/sources/HeuristicLab.Problems.Instances.VehicleRouting/3.4/GoldenFormat/GoldenParser.cs
r7887 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. … … 21 21 22 22 using System; 23 using System.Globalization;24 23 using System.IO; 25 24 … … 29 28 private Stream stream; 30 29 private string problemName; 31 30 32 31 #region Inner Enum TSPLIBEdgeWeightType 33 32 public enum GoldenEdgeWeightType { … … 125 124 } 126 125 127 public GoldenParser(string file): this() { 126 public GoldenParser(string file) 127 : this() { 128 128 this.file = file; 129 129 } 130 130 131 131 public GoldenParser(Stream stream) 132 132 : this() { 133 133 this.stream = stream; 134 134 } -
trunk/sources/HeuristicLab.Problems.Instances.VehicleRouting/3.4/LiLimFormat/LiLimParser.cs
r7882 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 LiLimParser(string file): this() { 120 public LiLimParser(string file) 121 : this() { 121 122 this.file = file; 122 123 } 123 124 124 public LiLimParser(Stream stream): this() { 125 public LiLimParser(Stream stream) 126 : this() { 125 127 this.stream = stream; 126 128 } 127 129 128 129 130 131 130 public void Parse() { 131 string line; 132 Regex reg = new Regex(@"-?\d+"); 133 MatchCollection m; 132 134 133 StreamReader reader; 134 if (stream != null) { 135 reader = new StreamReader(stream); 136 } 137 else { 138 reader = new StreamReader(file); 139 problemName = Path.GetFileNameWithoutExtension(file); 140 } 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 } 141 142 142 143 143 using (reader) { 144 line = reader.ReadLine(); 144 145 145 146 147 146 m = reg.Matches(line); 147 if (m.Count != 3) 148 throw new InvalidDataException("File has wrong format!"); 148 149 149 150 150 vehicles = int.Parse(m[0].Value); 151 capacity = double.Parse(m[1].Value); 151 152 152 153 154 155 156 157 158 159 160 161 162 153 line = reader.ReadLine(); 154 while ((line != null) && (line.Length > 5)) { 155 m = reg.Matches(line); 156 if (m.Count != 9) { continue; } 157 xCoord.Add((double)int.Parse(m[1].Value)); 158 yCoord.Add((double)int.Parse(m[2].Value)); 159 demand.Add((double)int.Parse(m[3].Value)); 160 readyTime.Add((double)int.Parse(m[4].Value)); 161 double st = (double)int.Parse(m[6].Value); 162 dueTime.Add((double)int.Parse(m[5].Value)); 163 serviceTime.Add(st); 163 164 164 165 166 167 165 int location = int.Parse(m[7].Value); 166 if (location == 0) 167 location = int.Parse(m[8].Value); 168 pickipDeliveryLocation.Add(location); 168 169 169 170 171 172 173 170 line = reader.ReadLine(); 171 } 172 cities = serviceTime.Count; 173 } 174 } 174 175 } 175 176 } -
trunk/sources/HeuristicLab.Problems.Instances.VehicleRouting/3.4/SolomonFormat/SolomonParser.cs
r7882 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. … … 110 110 } 111 111 112 public SolomonParser(string file): this() { 112 public SolomonParser(string file) 113 : this() { 113 114 this.file = file; 114 115 } 115 116 116 public SolomonParser(Stream stream): this() { 117 public SolomonParser(Stream stream) 118 : this() { 117 119 this.stream = stream; 118 120 } -
trunk/sources/HeuristicLab.Problems.Instances.VehicleRouting/3.4/TaillardFormat/TaillardParser.cs
r7888 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. … … 79 79 } 80 80 81 public TaillardParser(string file): this() { 81 public TaillardParser(string file) 82 : this() { 82 83 this.file = file; 83 84 }
Note: See TracChangeset
for help on using the changeset viewer.