1 | using System;
|
---|
2 | using System.Collections.Generic;
|
---|
3 | using System.Linq;
|
---|
4 | using System.Text;
|
---|
5 | using HeuristicLab.Problems.VehicleRouting.Interfaces;
|
---|
6 | using HeuristicLab.Problems.VehicleRouting.Encodings.Potvin;
|
---|
7 | using HeuristicLab.Problems.VehicleRouting.Encodings.Alba;
|
---|
8 | using HeuristicLab.Core;
|
---|
9 | using HeuristicLab.Problems.VehicleRouting.Encodings.GVR;
|
---|
10 | using HeuristicLab.Encodings.PermutationEncoding;
|
---|
11 | using HeuristicLab.Problems.VehicleRouting.Encodings.Prins;
|
---|
12 | using HeuristicLab.Problems.VehicleRouting.Encodings.Zhu;
|
---|
13 | using HeuristicLab.Problems.VehicleRouting;
|
---|
14 |
|
---|
15 | namespace HeuristicLab.Operators.MPISupport.BinaryTransport {
|
---|
16 | enum VRPEncodingTypes { Alba, GVR, Potvin, Prins, Zhu }
|
---|
17 |
|
---|
18 | [Serializable]
|
---|
19 | class VRPTransfer {
|
---|
20 | public VRPEncodingTypes VRPEncodingType { get; set; }
|
---|
21 |
|
---|
22 | public List<int> Route { get; set; }
|
---|
23 |
|
---|
24 | public static VRPTransfer Convert(IVRPEncoding item) {
|
---|
25 | VRPTransfer result = new VRPTransfer();
|
---|
26 |
|
---|
27 | if (item is AlbaEncoding)
|
---|
28 | result.VRPEncodingType = VRPEncodingTypes.Alba;
|
---|
29 | else if (item is GVREncoding)
|
---|
30 | result.VRPEncodingType = VRPEncodingTypes.GVR;
|
---|
31 | else if (item is PotvinEncoding)
|
---|
32 | result.VRPEncodingType = VRPEncodingTypes.Potvin;
|
---|
33 | else if (item is PrinsEncoding)
|
---|
34 | result.VRPEncodingType = VRPEncodingTypes.Prins;
|
---|
35 | else if (item is ZhuEncoding)
|
---|
36 | result.VRPEncodingType = VRPEncodingTypes.Zhu;
|
---|
37 |
|
---|
38 | int tourIdx = 0;
|
---|
39 | result.Route = new List<int>();
|
---|
40 | foreach (Tour tour in item.GetTours()) {
|
---|
41 | foreach (int stop in tour.Stops) {
|
---|
42 | result.Route.Add(stop);
|
---|
43 | }
|
---|
44 | result.Route.Add(-item.GetVehicleAssignment(tourIdx));
|
---|
45 | tourIdx++;
|
---|
46 | }
|
---|
47 |
|
---|
48 | return result;
|
---|
49 | }
|
---|
50 |
|
---|
51 | public static IVRPEncoding Convert(VRPTransfer item, IExecutionContext globalScope) {
|
---|
52 | IVRPEncoding result = null;
|
---|
53 |
|
---|
54 | IVRPProblemInstance instance = (globalScope.Parameters["ProblemInstance"] as IValueParameter).Value as IVRPProblemInstance;
|
---|
55 |
|
---|
56 | if (item.VRPEncodingType == VRPEncodingTypes.Alba)
|
---|
57 | result = AlbaEncoding.ConvertFrom(item.Route, instance);
|
---|
58 | else if (item.VRPEncodingType == VRPEncodingTypes.GVR)
|
---|
59 | result = GVREncoding.ConvertFrom(item.Route, instance);
|
---|
60 | else if (item.VRPEncodingType == VRPEncodingTypes.Potvin)
|
---|
61 | result = PotvinEncoding.ConvertFrom(item.Route, instance);
|
---|
62 | else if (item.VRPEncodingType == VRPEncodingTypes.Prins)
|
---|
63 | result = PrinsEncoding.ConvertFrom(item.Route, instance);
|
---|
64 | else if (item.VRPEncodingType == VRPEncodingTypes.Zhu)
|
---|
65 | result = ZhuEncoding.ConvertFrom(item.Route, instance);
|
---|
66 |
|
---|
67 | return result;
|
---|
68 | }
|
---|
69 | }
|
---|
70 | }
|
---|