Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 3 additions & 2 deletions Makefile
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
OR_TOOLS_TOP=../or-tools

TUTORIAL=resources
TUTORIAL=./resources

# -isystem prevents most of the warnings rooted in or-tools library appearing in our compilation
CFLAGS := -std=c++14 -isystem$(OR_TOOLS_TOP)/include
Expand All @@ -9,6 +9,7 @@ CFLAGS := -std=c++14 -isystem$(OR_TOOLS_TOP)/include
# DEVELOPMENT = true
ifeq ($(DEVELOPMENT), true)
CFLAGS := $(CFLAGS) -O0 -DDEBUG -ggdb3 -fsanitize=address -fkeep-inline-functions -fno-inline-small-functions
# CXX := ../callcatcher/build/scripts-3.6/callcatcher $(CXX) # comment out to check uncalled functions
CXX := LSAN_OPTION=verbosity=1:log_threads=1 $(CXX) # adress sanitizer works only if the executable launched without gdb
else
CFLAGS := $(CFLAGS) -O3 -DNDEBUG
Expand Down Expand Up @@ -44,7 +45,7 @@ tsp_simple.o: tsp_simple.cc ortools_vrp.pb.h \
tsptw_data_dt.h \
limits.h \
values.h
$(CXX) $(CFLAGS) -I $(TUTORIAL) -c ./tsp_simple.cc -o tsp_simple.o
$(CXX) $(CFLAGS) -isystem$(TUTORIAL) -c ./tsp_simple.cc -o tsp_simple.o

tsp_simple: $(ROUTING_DEPS) tsp_simple.o ortools_vrp.pb.o ortools_result.pb.o $(OR_TOOLS_TOP)/lib/libortools.so
$(CXX) $(CFLAGS) -fwhole-program tsp_simple.o ortools_vrp.pb.o ortools_result.pb.o $(OR_TOOLS_LD_FLAGS) \
Expand Down
Binary file modified data/test_ortools_single_route_with_route_order
Binary file not shown.
Binary file added data/test_with_cluster
Binary file not shown.
1 change: 1 addition & 0 deletions ortools_vrp.proto
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ package ortools_vrp;
option optimize_for = SPEED;

message Matrix {
uint32 size = 1;
repeated float time = 2 [ packed = true ];
repeated float distance = 3 [ packed = true ];
repeated float value = 4 [ packed = true ];
Expand Down
1 change: 1 addition & 0 deletions ortools_vrp_pb.rb

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

31 changes: 16 additions & 15 deletions tsp_simple.cc
Original file line number Diff line number Diff line change
Expand Up @@ -287,8 +287,8 @@ RestBuilder(const TSPTWDataDT& data, RoutingModel& routing, const int64 horizon)
const TSPTWDataDT::Vehicle& vehicle = data.Vehicles(vehicle_index);
for (const TSPTWDataDT::Rest& rest : vehicle.Rests()) {
IntervalVar* const rest_interval = solver->MakeFixedDurationIntervalVar(
std::max(rest.ready_time, vehicle.time_start),
std::min(rest.due_time, vehicle.time_end - rest.duration),
std::max<int64>(rest.ready_time, vehicle.time_start),
std::min<int64>(rest.due_time, vehicle.time_end - rest.duration),
rest.duration, // Currently only one timewindow
false, absl::StrCat("Rest/", rest.rest_id, "/", vehicle_index));
rest_array.push_back(rest_interval);
Expand Down Expand Up @@ -326,10 +326,6 @@ void RelationBuilder(const TSPTWDataDT& data, RoutingModel& routing,
return data.DayIndexToVehicleIndex(index);
};

// Solver::IndexEvaluator1 alternative_vehicle_evaluator = [&data](int64 index) {
// return data.VehicleDayAlt(index);
// };

std::vector<IntVar*> next_vars;
for (int i = 0; i < data.SizeMissions(); ++i) {
next_vars.push_back(routing.NextVar(i));
Expand Down Expand Up @@ -1121,11 +1117,18 @@ void AddValueDimensions(const TSPTWDataDT& data, RoutingModel& routing,
RoutingIndexManager& manager) {
std::vector<int> value_evaluators;
for (const TSPTWDataDT::Vehicle& vehicle : data.Vehicles()) {
value_evaluators.push_back(routing.RegisterTransitCallback(
[&vehicle, &manager](const int64 i, const int64 j) {
return vehicle.ValuePlusServiceValue(manager.IndexToNode(i),
manager.IndexToNode(j));
}));
if (vehicle.value_matrix->value().empty()) {
value_evaluators.push_back(
routing.RegisterTransitCallback([&data, &manager](const int64 i, const int64) {
return data.ServiceValue(manager.IndexToNode(i));
}));
} else {
value_evaluators.push_back(routing.RegisterTransitCallback(
[&vehicle, &data, &manager](const int64 i, const int64 j) {
return vehicle.Value(manager.IndexToNode(i), manager.IndexToNode(j)) +
data.ServiceValue(manager.IndexToNode(i));
}));
}
}
routing.AddDimensionWithVehicleTransits(value_evaluators, 0, LLONG_MAX, true, kValue);
int v = 0;
Expand Down Expand Up @@ -1234,11 +1237,9 @@ void AddVehicleDistanceConstraints(const TSPTWDataDT& data, RoutingModel& routin
routing.GetDimensionOrDie(kDistance);
for (const TSPTWDataDT::Vehicle& vehicle : data.Vehicles()) {
if (vehicle.distance > 0) {
const int64 end_index = routing.End(v);
// Vehicle maximum distance
IntVar* const dist_end_cumul_var = distance_dimension.CumulVar(end_index);
solver->AddConstraint(
solver->MakeLessOrEqual(dist_end_cumul_var, vehicle.distance));
solver->AddConstraint(solver->MakeLessOrEqual(
distance_dimension.CumulVar(routing.End(v)), vehicle.distance));
}
++v;
}
Expand Down
Loading