Free cookie consent management tool by TermsFeed Policy Generator

source: branches/MPI/HeuristicLab.Operators.MPISupport/3.3/BinaryTransport/VRP/VRPTransfer.cs @ 7544

Last change on this file since 7544 was 7544, checked in by svonolfe, 12 years ago

Improved performance, added MPISolutionsCreator (#1542)

File size: 2.6 KB
Line 
1using System;
2using System.Collections.Generic;
3using System.Linq;
4using System.Text;
5using HeuristicLab.Problems.VehicleRouting.Interfaces;
6using HeuristicLab.Problems.VehicleRouting.Encodings.Potvin;
7using HeuristicLab.Problems.VehicleRouting.Encodings.Alba;
8using HeuristicLab.Core;
9using HeuristicLab.Problems.VehicleRouting.Encodings.GVR;
10using HeuristicLab.Encodings.PermutationEncoding;
11using HeuristicLab.Problems.VehicleRouting.Encodings.Prins;
12using HeuristicLab.Problems.VehicleRouting.Encodings.Zhu;
13using HeuristicLab.Problems.VehicleRouting;
14
15namespace 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}
Note: See TracBrowser for help on using the repository browser.