Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Update ruby version #56

Open
wants to merge 47 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
47 commits
Select commit Hold shift + click to select a range
2ee551d
Fix compiler warnings and uninitialized variables
senhalil Feb 3, 2022
a71c37d
Deactivate Warray-bounds until protobuf is updated
senhalil Feb 3, 2022
5166d9f
Merge pull request #38 from senhalil/fix_uninitialised_variables
Feb 4, 2022
647bd64
Fix: respect compatible vehicle list
senhalil Dec 2, 2021
ba818ce
Merge pull request 34 from senhalil/dev
senhalil Feb 15, 2022
ecc6c95
Setup_duration related to matrix index
Feb 28, 2022
423994f
Merge pull request 39 from braktar/setup-matrix-index
senhalil Feb 28, 2022
92a4de6
Fix IdIndex map
Mar 9, 2022
0d5b39d
Merge pull request 41 from braktar/fix-id-index
senhalil Mar 9, 2022
da1b9cd
Extand alternative to route position relations
Dec 17, 2021
b7d344d
Alternative for order/sequence/same_route relations
Apr 6, 2022
59e18d5
fix shipment relation
Apr 7, 2022
c337b15
Increase time+service time in case of relations
Apr 8, 2022
25e9feb
remove previous indices and alternatives from nextVar
Apr 22, 2022
2b55f8e
Merge pull request #35 from braktar/dev
Apr 22, 2022
b6ad387
Remove dead code
senhalil May 20, 2022
4003446
Merge pull request 43 from senhalil/dev
senhalil May 20, 2022
44ed54a
Fix Cost computation when kFakeTime is used
May 23, 2022
2448658
Shift internal timewindows to earliest possible
May 20, 2022
fcbd243
Merge pull request 45 from braktar/fix-kFakeTime
senhalil May 24, 2022
5e9f253
Throw an error if vehicle has no timewindow
May 24, 2022
475be29
Merge pull request 44 from braktar/min-start
senhalil May 24, 2022
f2c3135
Return depot doesn't need time shift
May 31, 2022
58297a7
Merge pull request 47 from braktar/unnecessary-shift
senhalil May 31, 2022
c0aed89
An infeasible timewindow doesn't have to generate its own node
May 31, 2022
1b52260
Merge pull request 46 from braktar/min-start
senhalil May 31, 2022
9baea94
fix initial route generation
Pierre-Graber Jun 8, 2022
8c3572a
Merge pull request 48 from Pierre-Graber/fix_initial_route_generation
senhalil Jun 8, 2022
e19d60d
Base setup_duration on point_id
Pierre-Graber Jul 8, 2022
20082b1
Merge pull request #49 from Pierre-Graber/dev
Jul 11, 2022
2d0c9bf
Remove dead code and fix small warnings
senhalil Dec 14, 2021
9526bf6
Fix variable naming issues
senhalil Dec 9, 2021
756f886
Simplify Time & Distance functions
senhalil Dec 13, 2021
84dea87
Fix: value evaluator should not call time function
senhalil Dec 14, 2021
f35e8ef
Respect variables type defined in protobuf
senhalil Feb 7, 2022
5fc2311
Matrix refacto: Use existing proto matrix
senhalil Feb 7, 2022
0fe6d3d
Merge pull request #50 from braktar/traffic_refacto
Jul 20, 2022
d920d24
Apply positions only for concerned activities
Pierre-Graber Aug 1, 2022
bfc135b
Merge pull request #51 from Pierre-Graber/OO_alternative_id_position_
Pierre-Graber Aug 2, 2022
2044a0a
Merge pull request #51 from Pierre-Graber/OO_alternative_id_position_
Pierre-Graber Aug 2, 2022
b586213
Merge branch 'dev' of https://github.com/Mapotempo/optimizer-ortools …
Aug 15, 2022
dfb796f
Remove debug output
Pierre-Graber Aug 1, 2022
be2880b
Merge pull request #52 from Pierre-Graber/OO_alternative_id_position_
alain-andre Sep 20, 2022
c005004
Use ruby as base instead of the monolithic passenger
alain-andre Dec 30, 2022
8f8a0bc
Fix github actions deprecation warning
alain-andre Jan 20, 2023
c3e1aaa
Set image name standard
alain-andre Jan 20, 2023
a63bc67
Update Ruby version
alain-andre Apr 18, 2023
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
3 changes: 3 additions & 0 deletions .env
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
ORTOOLS_URL="https://github.com/google/or-tools/releases/download/v7.8/or-tools_debian-10_v7.8.7959.tar.gz"
ORTOOLS_VERSION=v7.8 # select from https://github.com/google/or-tools/releases
RUBY_VERSION=2.7
4 changes: 2 additions & 2 deletions .github/actions/build.sh
Original file line number Diff line number Diff line change
Expand Up @@ -31,8 +31,8 @@ case $ORTOOLS_VERSION in
esac

echo "Download asset at ${ORTOOLS_URL}"
docker build --build-arg ORTOOLS_URL=${ORTOOLS_URL} -f ./Dockerfile -t "${IMAGE_NAME}" .
docker build --build-arg RUBY_VERSION="2.7" --build-arg ORTOOLS_URL=${ORTOOLS_URL} -f ./Dockerfile -t "${IMAGE_NAME}" .
docker run -d --name optimizer -t "${IMAGE_NAME}"
docker exec -i optimizer bash -c "LD_LIBRARY_PATH=/srv/or-tools/lib/ /srv/optimizer-ortools/tsp_simple -time_limit_in_ms 500 -intermediate_solutions -instance_file '/srv/optimizer-ortools/data/test_ortools_single_route_with_route_order' -solution_file '/tmp/optimize-or-tools-output'"

echo "::set-output name=image_name::${IMAGE_NAME}"
echo "name=image_name::${IMAGE_NAME}" >> $GITHUB_OUTPUT
21 changes: 5 additions & 16 deletions Dockerfile
Original file line number Diff line number Diff line change
@@ -1,25 +1,14 @@
# 1.0.13 is the latest version containing bundler 2 required for optimizer-api
FROM phusion/passenger-ruby25:1.0.13
ARG RUBY_VERSION
ARG ARCHITECTURE

FROM ${ARCHITECTURE}ruby:${RUBY_VERSION}

ARG ORTOOLS_URL=${ORTOOLS_URL}

LABEL maintainer="Mapotempo <[email protected]>"

WORKDIR /srv/

# Trick to install passenger-docker on Ruby 2.5. Othwerwise `apt-get update` fails with a
# certificate error. See following links for explanantion:
# https://issueexplorer.com/issue/phusion/passenger-docker/325
# and
# https://issueexplorer.com/issue/phusion/passenger-docker/322
# Basically, DST Root CA X3 certificates are expired on Setember 2021 and apt-get cannot validate
# with the old certificates and the certification correction is only done for Ruby 2.6+ on the
# passenger-docker repo because Ruby 2.5 is EOL.
RUN mv /etc/apt/sources.list.d /etc/apt/sources.list.d.bak
RUN apt update && apt install -y ca-certificates
RUN mv /etc/apt/sources.list.d.bak /etc/apt/sources.list.d
# The above trick can be removed after Ruby version is increased.

RUN apt-get update > /dev/null && \
apt-get -y install git wget pkg-config build-essential cmake autoconf libtool zlib1g-dev lsb-release > /dev/null

Expand All @@ -30,4 +19,4 @@ RUN wget -qO- $ORTOOLS_URL | tar xz --strip-components=1 -C /srv/or-tools
ADD . /srv/optimizer-ortools

WORKDIR /srv/optimizer-ortools
RUN make -j3 tsp_simple
RUN make tsp_simple
23 changes: 17 additions & 6 deletions Makefile
Original file line number Diff line number Diff line change
@@ -1,19 +1,30 @@
OR_TOOLS_TOP=../or-tools

TUTORIAL=resources
TUTORIAL=./resources

CFLAGS := -std=c++14 -I $(OR_TOOLS_TOP)/include
# -isystem prevents most of the warnings rooted in or-tools library appearing in our compilation
CFLAGS := -std=c++14 -isystem$(OR_TOOLS_TOP)/include

# During development uncomment the next line to have debug checks and other verifications
# DEVELOPMENT = true
ifeq ($(DEVELOPMENT), true)
# -isystem prevents warnings rooted in or-tools library appearing in our compilation
CFLAGS := $(CFLAGS) -O0 -DDEBUG -ggdb3 -fsanitize=address -fkeep-inline-functions -fno-inline-small-functions -Wall -Wextra -Wshadow -Wunreachable-code -Winit-self -Wmissing-include-dirs -Wswitch-enum -Wfloat-equal -Wundef -isystem$(OR_TOOLS_TOP)/. -isystem$(OR_TOOLS_TOP)/include
CXX := LSAN_OPTION=verbosity=1:log_threads=1 $(CXX)
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
endif

# Activate warnings
CFLAGS := $(CFLAGS) -Wall -Wextra -Wshadow -Wmissing-include-dirs -Wswitch-enum -Wfloat-equal -Wundef

# The following is to supress a warning due to a protobuf that is fixed at v3.14.
# It can be removed when or-tools is upgraded to v8.1+ (where the protobuf dependency is upgraded to v3.14).
PROTOBUF_VERSION := $(shell $(OR_TOOLS_TOP)/bin/protoc --version | cut -d" " -f2)
ifeq ($(shell dpkg --compare-versions $(PROTOBUF_VERSION) 'lt' '3.14' && echo true), true)
CFLAGS := $(CFLAGS) -Wno-array-bounds
endif

.PHONY: all local_clean

all: $(EXE)
Expand All @@ -34,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.
23 changes: 23 additions & 0 deletions docker-compose.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
version: '3.7'
x-app-args: &app-args
ARCHITECTURE: ${ARCHITECTURE}
ORTOOLS_URL: ${ORTOOLS_URL}
ORTOOLS_VERSION: ${ORTOOLS_VERSION}
RUBY_VERSION: ${RUBY_VERSION}

x-app: &default-app
volumes:
- ./:/srv/app/
env_file:
- ./.env

services:
main:
<<: *default-app
build:
args:
<<: *app-args
context: .
dockerfile: Dockerfile
image: dev.example.com/mapotempo-ce/optimizer-ortools
tty: true
40 changes: 18 additions & 22 deletions limits.h
Original file line number Diff line number Diff line change
Expand Up @@ -90,8 +90,7 @@ class NoImprovementLimit : public SearchLimit {
best_result_ = kint64min;
}

DCHECK_NOTNULL(objective_var);
prototype_->AddObjective(objective_var);
prototype_->AddObjective(DCHECK_NOTNULL(objective_var));
}

virtual void Init() {
Expand Down Expand Up @@ -145,7 +144,7 @@ class NoImprovementLimit : public SearchLimit {

virtual void Copy(const SearchLimit* const limit) {
const NoImprovementLimit* const copy_limit =
reinterpret_cast<const NoImprovementLimit* const>(limit);
reinterpret_cast<const NoImprovementLimit*>(limit);

best_result_ = copy_limit->best_result_;
solution_nbr_tolerance_ = copy_limit->solution_nbr_tolerance_;
Expand Down Expand Up @@ -206,8 +205,8 @@ namespace {
class LoggerMonitor : public SearchMonitor {
public:
LoggerMonitor(const TSPTWDataDT& data, RoutingModel* routing,
RoutingIndexManager* manager, int64 min_start, int64 size_matrix,
bool debug, bool intermediate, ortools_result::Result* result,
RoutingIndexManager* manager, int64 size_matrix, bool debug,
bool intermediate, ortools_result::Result* result,
std::vector<std::vector<IntervalVar*>> stored_rests, std::string filename,
const bool minimize = true)
: SearchMonitor(routing->solver())
Expand All @@ -216,7 +215,6 @@ class LoggerMonitor : public SearchMonitor {
, manager_(manager)
, solver_(routing->solver())
, start_time_(absl::GetCurrentTimeNanos())
, min_start_(min_start)
, size_matrix_(size_matrix)
, minimize_(minimize)
, limit_reached_(false)
Expand Down Expand Up @@ -320,6 +318,7 @@ class LoggerMonitor : public SearchMonitor {
int64 lateness_cost = 0;
int64 overload_cost = 0;
bool vehicle_used = false;
const int64 earliest_start = data_.EarliestStart();
for (int64 index = routing_->Start(route_nbr); !routing_->IsEnd(index);
index = routing_->NextVar(index)->Value()) {
for (std::vector<IntervalVar*>::iterator it = rests.begin();
Expand All @@ -339,7 +338,7 @@ class LoggerMonitor : public SearchMonitor {
ortools_result::Activity* rest = route->add_activities();
rest->set_type("break");
rest->set_id(parsed_name[1]);
rest->set_start_time(rest_start_time);
rest->set_start_time(rest_start_time + earliest_start);
it = rests.erase(it);
} else {
++it;
Expand All @@ -351,7 +350,7 @@ class LoggerMonitor : public SearchMonitor {
activity->set_index(data_.ProblemIndex(nodeIndex));
const int64 start_time =
routing_->GetMutableDimension(kTime)->CumulVar(index)->Min();
activity->set_start_time(start_time);
activity->set_start_time(start_time + earliest_start);
const int64 upper_bound =
routing_->GetMutableDimension(kTime)->GetCumulVarSoftUpperBound(index);
const int64 lateness = std::max<int64>(start_time - upper_bound, 0);
Expand Down Expand Up @@ -408,7 +407,7 @@ class LoggerMonitor : public SearchMonitor {

const int64 start_time =
routing_->GetMutableDimension(kTime)->CumulVar(end_index)->Min();
end_activity->set_start_time(start_time);
end_activity->set_start_time(start_time + earliest_start);
const int64 upper_bound =
routing_->GetMutableDimension(kTime)->GetCumulVarSoftUpperBound(end_index);
const int64 lateness = std::max<int64>(start_time - upper_bound, 0);
Expand Down Expand Up @@ -560,7 +559,6 @@ class LoggerMonitor : public SearchMonitor {
}

if (debug_ && new_best) {
std::cout << "min start : " << min_start_ << std::endl;
for (RoutingIndexManager::NodeIndex i(0); i < data_.SizeMatrix() - 1; ++i) {
const int64 index = manager_->NodeToIndex(i);
const IntVar* cumul_var = routing_->GetMutableDimension(kTime)->CumulVar(index);
Expand All @@ -572,8 +570,8 @@ class LoggerMonitor : public SearchMonitor {
slack_var->Bound()) {
std::cout << "Node " << i << " index " << index << " [" << vehicle_var->Value()
<< "] |";
std::cout << (cumul_var->Value() - min_start_) << " + " << transit_var->Value()
<< " -> " << slack_var->Value() << std::endl;
std::cout << (cumul_var->Value()) << " + " << transit_var->Value() << " -> "
<< slack_var->Value() << std::endl;
}
}
std::cout << "-----------" << std::endl;
Expand All @@ -597,8 +595,7 @@ class LoggerMonitor : public SearchMonitor {
}

virtual void Copy(const SearchLimit* const limit) {
const LoggerMonitor* const copy_limit =
reinterpret_cast<const LoggerMonitor* const>(limit);
const LoggerMonitor* const copy_limit = reinterpret_cast<const LoggerMonitor*>(limit);

best_result_ = copy_limit->best_result_;
cleaned_cost_ = copy_limit->cleaned_cost_;
Expand All @@ -615,9 +612,9 @@ class LoggerMonitor : public SearchMonitor {
// Allocates a clone of the limit
virtual SearchMonitor* MakeClone() const {
// we don't to copy the variables
return solver_->RevAlloc(
new LoggerMonitor(data_, routing_, manager_, min_start_, size_matrix_, debug_,
intermediate_, result_, stored_rests_, filename_, minimize_));
return solver_->RevAlloc(new LoggerMonitor(data_, routing_, manager_, size_matrix_,
debug_, intermediate_, result_,
stored_rests_, filename_, minimize_));
}

virtual std::string DebugString() const {
Expand All @@ -644,7 +641,6 @@ class LoggerMonitor : public SearchMonitor {
int64 best_result_;
double cleaned_cost_;
double start_time_;
int64 min_start_;
int64 size_matrix_;
bool minimize_;
bool limit_reached_;
Expand All @@ -661,14 +657,14 @@ class LoggerMonitor : public SearchMonitor {
} // namespace

LoggerMonitor* MakeLoggerMonitor(const TSPTWDataDT& data, RoutingModel* routing,
RoutingIndexManager* manager, int64 min_start,
int64 size_matrix, bool debug, bool intermediate,
RoutingIndexManager* manager, int64 size_matrix,
bool debug, bool intermediate,
ortools_result::Result* result,
std::vector<std::vector<IntervalVar*>> stored_rests,
std::string filename, const bool minimize = true) {
return routing->solver()->RevAlloc(
new LoggerMonitor(data, routing, manager, min_start, size_matrix, debug,
intermediate, result, stored_rests, filename, minimize));
new LoggerMonitor(data, routing, manager, size_matrix, debug, intermediate, result,
stored_rests, filename, minimize));
}
} // namespace operations_research

Expand Down
4 changes: 4 additions & 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 All @@ -30,6 +31,8 @@ message Service {
float exclusion_cost = 13;
repeated bool refill_quantities = 14;
uint32 problem_index = 15;
string point_id = 16;
uint32 alternative_index = 17;
}

message Rest {
Expand Down Expand Up @@ -75,6 +78,7 @@ message Vehicle {
uint32 additional_setup = 26;
bool free_approach = 27;
bool free_return = 28;
string start_point_id = 29;
}

message Relation {
Expand Down
4 changes: 4 additions & 0 deletions ortools_vrp_pb.rb

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

Loading