Changeset 12969 for branches/gteufl/HeuristicLab.Problems.Instances.VehicleRouting/3.4/CordeauFormat
- Timestamp:
- 09/25/15 14:39:59 (9 years ago)
- Location:
- branches/gteufl
- Files:
-
- 1 deleted
- 3 edited
- 2 copied
Legend:
- Unmodified
- Added
- Removed
-
branches/gteufl
- Property svn:ignore
-
old new 8 8 FxCopResults.txt 9 9 Google.ProtocolBuffers-0.9.1.dll 10 Google.ProtocolBuffers-2.4.1.473.dll 10 11 HeuristicLab 3.3.5.1.ReSharper.user 11 12 HeuristicLab 3.3.6.0.ReSharper.user 12 13 HeuristicLab.4.5.resharper.user 13 14 HeuristicLab.ExtLibs.6.0.ReSharper.user 15 HeuristicLab.Scripting.Development 14 16 HeuristicLab.resharper.user 15 17 ProtoGen.exe … … 17 19 _ReSharper.HeuristicLab 18 20 _ReSharper.HeuristicLab 3.3 21 _ReSharper.HeuristicLab 3.3 Tests 19 22 _ReSharper.HeuristicLab.ExtLibs 20 23 bin 21 24 protoc.exe 22 _ReSharper.HeuristicLab 3.3 Tests 23 Google.ProtocolBuffers-2.4.1.473.dll 25 obj
-
- Property svn:mergeinfo changed
-
Property
svn:global-ignores
set to
*.nuget
packages
- Property svn:ignore
-
branches/gteufl/HeuristicLab.Problems.Instances.VehicleRouting/3.4/CordeauFormat/CordeauFormatInstanceProvider.cs
r9456 r12969 1 1 #region License Information 2 2 /* HeuristicLab 3 * Copyright (C) 2002-201 3Heuristic and Evolutionary Algorithms Laboratory (HEAL)3 * Copyright (C) 2002-2015 Heuristic and Evolutionary Algorithms Laboratory (HEAL) 4 4 * 5 5 * This file is part of HeuristicLab. … … 20 20 #endregion 21 21 22 using System; 23 using System.Collections.Generic; 24 using System.Globalization; 22 25 using System.IO; 26 using System.Linq; 23 27 24 28 namespace HeuristicLab.Problems.Instances.VehicleRouting { 25 public abstract class CordeauFormatInstanceProvider : VRPInstanceProvider<MDCVRPTWData>{26 protected override MDCVRPTWData LoadData(Stream stream) {29 public abstract class CordeauFormatInstanceProvider<TData> : VRPInstanceProvider<TData> where TData : MDCVRPData { 30 protected override TData LoadData(Stream stream) { 27 31 return LoadInstance(new CordeauParser(stream)); 28 32 } … … 31 35 get { return true; } 32 36 } 33 public override MDCVRPTWData ImportData(string path) {37 public override TData ImportData(string path) { 34 38 return LoadInstance(new CordeauParser(path)); 35 39 } 36 40 37 private MDCVRPTWData LoadInstance(CordeauParser parser) { 38 parser.Parse(); 41 internal abstract TData LoadInstance(CordeauParser parser); 39 42 40 var instance = new MDCVRPTWData(); 41 instance.Dimension = parser.Cities + 1; 42 instance.Depots = parser.Depots; 43 instance.Coordinates = parser.Coordinates; 44 instance.Capacity = parser.Capacity; 45 instance.Demands = parser.Demands; 46 instance.DistanceMeasure = DistanceMeasure.Euclidean; 47 instance.ReadyTimes = parser.Readytimes; 48 instance.ServiceTimes = parser.Servicetimes; 49 instance.DueTimes = parser.Duetimes; 50 instance.MaximumVehicles = parser.Vehicles; 43 protected override void LoadSolution(Stream stream, TData instance) { 44 using (var reader = new StreamReader(stream)) { 45 double costs = double.Parse(reader.ReadLine(), CultureInfo.InvariantCulture); 51 46 52 int depots = parser.Depots; 53 int vehicles = parser.Vehicles / parser.Depots; 54 instance.VehicleDepotAssignment = new int[depots * vehicles]; 55 int index = 0; 47 var toursPerDepotQuery = 48 from line in reader.ReadAllLines() 49 where !string.IsNullOrEmpty(line) 50 let tokens = line.Split(new[] { ' ' }, StringSplitOptions.RemoveEmptyEntries) 51 let depot = int.Parse(tokens[0]) 52 //let vehicle = int.Parse(tokens[1]) 53 //let duration = double.Parse(tokens[2], CultureInfo.InvariantCulture) 54 //let load = double.Parse(tokens[3], new CultureInfo.InvariantCulture) 55 let customers = tokens.Skip(4).Where(t => !t.StartsWith("(")).Select(int.Parse) 56 let numberOfCustomers = customers.Count() 57 //let serviceTimes = tokens.Skip(5).Where(t => t.StartsWith("(")).Select(t => double.Parse(t.Trim('(', ')'), CultureInfo.InvariantCulture)) 58 let stops = customers.Skip(1).Take(numberOfCustomers - 2).Select(s => s - 1) 59 select new { depot, /*vehicle,*/ stops } into assignment 60 group assignment by assignment.depot; 56 61 57 for (int i = 0; i < depots; i++) 58 for (int j = 0; j < vehicles; j++) { 59 instance.VehicleDepotAssignment[index] = i; 60 index++; 61 } 62 var toursPerDepot = toursPerDepotQuery.Select(d => d.Select(v => v.stops.ToArray()).ToArray()).ToArray(); 62 63 63 instance.Name = parser.ProblemName;64 instance.BestKnownTour = toursPerDepot.SelectMany(depot => depot).ToArray(); 64 65 65 return instance; 66 instance.BestKnownTourVehicleAssignment = DetermineTourToVehicleAssignment(toursPerDepot, instance.VehicleDepotAssignment); 67 } 68 } 69 70 private static int[] DetermineTourToVehicleAssignment(int[][][] toursPerDepot, int[] vehicleDepotAssignments) { 71 var usedVehiclesPerDepot = toursPerDepot.Select((d, i) => new { i, d }).ToDictionary(k => k.i, v => v.d.Length); 72 var availableVehiclesPerDepot = vehicleDepotAssignments.GroupBy(a => a).ToDictionary(k => k.Key, v => v.Count()); 73 74 var tourToVehicle = new List<int>(vehicleDepotAssignments.Length); 75 var unusedVehicles = new List<int>(); 76 77 int vehicle = 0; 78 for (int depot = 0; depot < toursPerDepot.Length; depot++) { 79 int used = usedVehiclesPerDepot[depot]; 80 tourToVehicle.AddRange(Enumerable.Range(vehicle, used)); 81 vehicle += used; 82 83 int unused = availableVehiclesPerDepot[depot] - used; 84 unusedVehicles.AddRange(Enumerable.Range(vehicle, unused)); 85 vehicle += unused; 86 } 87 tourToVehicle.AddRange(unusedVehicles); 88 89 return tourToVehicle.ToArray(); 66 90 } 67 91 } -
branches/gteufl/HeuristicLab.Problems.Instances.VehicleRouting/3.4/CordeauFormat/CordeauParser.cs
r9456 r12969 1 1 #region License Information 2 2 /* HeuristicLab 3 * Copyright (C) 2002-201 3Heuristic and Evolutionary Algorithms Laboratory (HEAL)3 * Copyright (C) 2002-2015 Heuristic and Evolutionary Algorithms Laboratory (HEAL) 4 4 * 5 5 * This file is part of HeuristicLab.
Note: See TracChangeset
for help on using the changeset viewer.