Skip to content

Commit a5e005d

Browse files
committed
Simplify segfaulting code
1 parent c4b36e8 commit a5e005d

File tree

5 files changed

+10
-80
lines changed

5 files changed

+10
-80
lines changed

example/index.js

Lines changed: 1 addition & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -92,25 +92,15 @@ MbxClient.getDistances(locations, {profile: profile}, function(err, results) {
9292
var demands = new Array(results.durations.length);
9393

9494
// made up values that trigger segfault
95-
var Pickups = [ 6, 5, 5, 1, 0, 6, 5];
95+
var Pickups = [ 6, 5, 5, 1, 5, 6, 5];
9696
var Deliveries = [ 4, 4, 3, 2, 2, 4, 7];
9797

9898
for (let from = 0; from < results.durations.length; ++from) {
9999
demands[from] = new Array(results.durations.length);
100-
if (Pickups && Deliveries) {
101-
demands[from].fill(0);
102-
for (let it = 0; it < Pickups.length; ++it) {
103-
if (Pickups[it] === from) {
104-
let to = Deliveries[it];
105-
demands[from][to] = demands[from][to] ? demands[from][to] + 1 : 1;
106-
}
107-
}
108-
} else {
109100
// Dummy demands of one except at the depot
110101
for (var to = 0; to < results.durations.length; ++to) {
111102
demands[from][to] = (from === depotIndex) ? 0 : 1;
112103
}
113-
}
114104
}
115105

116106
// No route locks per vehicle, let solver decide freely

package.json

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -30,7 +30,9 @@
3030
"tap": "^10.3",
3131
"mapbox-sdk-js": "git://github.com/mapbox/mapbox-sdk-js.git#758572e9d5287023451f91a4b76e7e85c785189d"
3232
},
33-
"bundledDependencies": ["node-pre-gyp"],
33+
"bundledDependencies": [
34+
"node-pre-gyp"
35+
],
3436
"binary": {
3537
"module_name": "node_or_tools",
3638
"module_path": "./lib/binding/",

src/tsp.cc

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -34,9 +34,6 @@ NAN_METHOD(TSP::New) try {
3434

3535
TSPSolverParams userParams{info};
3636

37-
const auto bytesChange = getBytes(userParams.costs);
38-
Nan::AdjustExternalMemory(bytesChange);
39-
4037
auto* self = new TSP{std::move(userParams.costs)};
4138

4239
self->Wrap(info.This());

src/types.h

Lines changed: 6 additions & 55 deletions
Original file line numberDiff line numberDiff line change
@@ -10,17 +10,9 @@
1010

1111
// Convenience types. Sshould be good enough for most of TSP / VRP related problems.
1212

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>;
2416

2517
struct Interval {
2618
Interval() : start{0}, stop{0} {}
@@ -34,7 +26,7 @@ struct Interval {
3426
std::int32_t stop;
3527
};
3628

37-
using TimeWindows = NewType<Vector<Interval>, struct TimeWindowsTag>::Type;
29+
using TimeWindows = Vector<Interval>;
3830

3931
namespace ort = operations_research;
4032

@@ -66,48 +58,7 @@ using RouteLocks = std::vector<LockChain>;
6658
// e.g. pickups: [1, 2], deliveries: [5, 6] means
6759
// - pick up at node 1 and deliver to node 5
6860
// - 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>;
11263

11364
#endif

src/vrp.cc

Lines changed: 0 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -33,13 +33,6 @@ NAN_METHOD(VRP::New) try {
3333

3434
VRPSolverParams userParams{info};
3535

36-
const auto bytesChange = getBytes(userParams.costs) //
37-
+ getBytes(userParams.durations) //
38-
+ getBytes(userParams.timeWindows) //
39-
+ getBytes(userParams.demands); //
40-
41-
Nan::AdjustExternalMemory(bytesChange);
42-
4336
auto* self = new VRP{std::move(userParams.costs), //
4437
std::move(userParams.durations), //
4538
std::move(userParams.timeWindows), //
@@ -58,9 +51,6 @@ NAN_METHOD(VRP::Solve) try {
5851

5952
VRPSearchParams userParams(info);
6053

61-
const auto bytesChange = getBytes(userParams.routeLocks);
62-
Nan::AdjustExternalMemory(bytesChange);
63-
6454
// See routing_parameters.proto and routing_enums.proto
6555
auto modelParams = RoutingModel::DefaultModelParameters();
6656
auto searchParams = RoutingModel::DefaultSearchParameters();

0 commit comments

Comments
 (0)