10
10
11
11
// Convenience types. Sshould be good enough for most of TSP / VRP related problems.
12
12
13
- // Newtype via phantom type scheme. Allows type system to distinguish between tagged types.
14
- // Note: NewType<T, struct Tag0>::Type != NewType<T, struct Tag1>::Type
15
- template <typename T, typename Tag> struct NewType {
16
- struct Type : T {
17
- using T::T;
18
- };
19
- };
20
-
21
- using CostMatrix = NewType<Matrix<std::int32_t >, struct CostMatrixTag >::Type;
22
- using DurationMatrix = NewType<Matrix<std::int32_t >, struct DurationMatrixTag >::Type;
23
- using DemandMatrix = NewType<Matrix<std::int32_t >, struct DemandMatrixTag >::Type;
13
+ using CostMatrix = Matrix<std::int32_t >;
14
+ using DurationMatrix = Matrix<std::int32_t >;
15
+ using DemandMatrix = Matrix<std::int32_t >;
24
16
25
17
struct Interval {
26
18
Interval () : start{0 }, stop{0 } {}
@@ -34,7 +26,7 @@ struct Interval {
34
26
std::int32_t stop;
35
27
};
36
28
37
- using TimeWindows = NewType< Vector<Interval>, struct TimeWindowsTag >::Type ;
29
+ using TimeWindows = Vector<Interval>;
38
30
39
31
namespace ort = operations_research;
40
32
@@ -66,48 +58,7 @@ using RouteLocks = std::vector<LockChain>;
66
58
// e.g. pickups: [1, 2], deliveries: [5, 6] means
67
59
// - pick up at node 1 and deliver to node 5
68
60
// - pick up at node 2 and deliver to node 6
69
- using Pickups = NewType<Vector<NodeIndex>, struct PickupsTag >::Type;
70
- using Deliveries = NewType<Vector<NodeIndex>, struct DeliveriesTag >::Type;
71
-
72
- // Bytes in our type used for internal caching
73
-
74
- template <typename T> struct Bytes ;
75
-
76
- template <> struct Bytes <CostMatrix> {
77
- std::int32_t operator ()(const CostMatrix& v) const { return v.size () * sizeof (CostMatrix::Value); }
78
- };
79
-
80
- template <> struct Bytes <DurationMatrix> {
81
- std::int32_t operator ()(const DurationMatrix& v) const { return v.size () * sizeof (DurationMatrix::Value); }
82
- };
83
-
84
- template <> struct Bytes <DemandMatrix> {
85
- std::int32_t operator ()(const DemandMatrix& v) const { return v.size () * sizeof (DemandMatrix::Value); }
86
- };
87
-
88
- template <> struct Bytes <TimeWindows> {
89
- std::int32_t operator ()(const TimeWindows& v) const { return v.size () * sizeof (TimeWindows::Value); }
90
- };
91
-
92
- template <> struct Bytes <RouteLocks> {
93
- std::int32_t operator ()(const RouteLocks& v) const {
94
- std::int32_t bytes = 0 ;
95
-
96
- for (const auto & lockChain : v)
97
- bytes += lockChain.size () * sizeof (LockChain::value_type);
98
-
99
- return bytes;
100
- }
101
- };
102
-
103
- template <> struct Bytes <Pickups> {
104
- std::int32_t operator ()(const Pickups& v) const { return v.size () * sizeof (Pickups::Value); }
105
- };
106
-
107
- template <> struct Bytes <Deliveries> {
108
- std::int32_t operator ()(const Deliveries& v) const { return v.size () * sizeof (Deliveries::Value); }
109
- };
110
-
111
- template <typename T> std::int32_t getBytes (const T& v) { return Bytes<T>{}(v); }
61
+ using Pickups = Vector<NodeIndex>;
62
+ using Deliveries = Vector<NodeIndex>;
112
63
113
64
#endif
0 commit comments