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

Lognex vroom custom #1150

Open
wants to merge 15 commits into
base: master
Choose a base branch
from
Open
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
3 changes: 2 additions & 1 deletion .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -3,4 +3,5 @@
bin/
lib/
build/
.vscode
.vscode
.idea
7 changes: 6 additions & 1 deletion CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
# Changelog

## [Unreleased]
## [v1.14.0] - 2024-01-16

### Added

Expand Down Expand Up @@ -48,6 +48,10 @@
- Remove unused `tw_length` member from `Job` and associated code
- Scale `TimeWindow::length` from `UserDuration` to `Duration` (#1015)

#### Routing

- ORS: (previously) hard-coded `/ors/v2` slug now has to be added to the path using `-a` (#1036)

#### Dependencies

- Submodule and update Rapidjson (#929)
Expand All @@ -72,6 +76,7 @@
- `max_travel_time` not accounted for with vehicle steps in solving mode (#954)
- `max_travel_time` not accounted for in `RouteSplit` (#941)
- Wrong capacity checks in `RouteSplit` (#981)
- Overflow related to scaling default time windows (#1020)

#### Internals

Expand Down
6 changes: 3 additions & 3 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -134,10 +134,10 @@ solution quality and computing times.
To cite VROOM in publications, please use:

```bibtex
@manual{vroom_v1.13,
title = {{VROOM v1.13, Vehicle Routing Open-source Optimization Machine}},
@manual{vroom_v1.14,
title = {{VROOM v1.14, Vehicle Routing Open-source Optimization Machine}},
author = {Coupey, Julien and Nicod, Jean-Marc and Varnier, Christophe},
year = 2023,
year = 2024,
organization = {Verso (\url{https://verso-optim.com/})},
address = {Besançon, France},
note = {\url{http://vroom-project.org/}}
Expand Down
3 changes: 2 additions & 1 deletion docs/API.md
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ Contents:
- all distances are in meters
- a `time_window` object is a pair of timestamps in the form `[start, end]`
- deprecated keys are crossed out
- `cost` values in output are the one used in the optimization objective (currently equal to `duration`)
- `cost` values in output are the one used internally in the optimization objective
- a "task" is either a job, a pickup or a delivery

# Solving mode
Expand Down Expand Up @@ -420,6 +420,7 @@ Possible violation causes are:
- "precedence" if a `shipment` precedence constraint is not met (`pickup` without matching `delivery`, `delivery` before/without matching `pickup`)
- "missing_break" if a vehicle break has been omitted in its custom route
- "max_travel_time" if the vehicle has more travel time than its `max_travel_time` value
- "max_distance" if the vehicle has a longer travel distance than its `max_distance` value
- "max_load" if the load during a break exceed its `max_load` value

Note on violations: reporting only really makes sense when using `-c`
Expand Down
2 changes: 1 addition & 1 deletion src/makefile
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
# Variables.
CXX ?= g++
USE_ROUTING ?= true
CXXFLAGS = -MMD -MP -I. -std=c++20 -Wextra -Wpedantic -Wall -O3 -DASIO_STANDALONE -DUSE_ROUTING=$(USE_ROUTING)
CXXFLAGS = -MMD -MP -I. -std=c++20 -Wextra -Wpedantic -Wall -O3 -DASIO_STANDALONE -DUSE_ROUTING=$(USE_ROUTING) -DNDEBUG
LDLIBS = -lpthread

# Using all cpp files in current directory.
Expand Down
6 changes: 4 additions & 2 deletions src/problems/cvrp/operators/priority_replace.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -138,7 +138,8 @@ bool PriorityReplace::is_valid() {
// portion is empty or with a single job (that would be an
// UnassignedExchange move).
replace_start_valid =
(s_rank > 0) && (_best_known_priority_gain <= _start_priority_gain) &&
(0 < _start_priority_gain) &&
(_best_known_priority_gain <= _start_priority_gain) && (s_rank > 0) &&
source.is_valid_addition_for_capacity_margins(_input,
j.pickup,
j.delivery,
Expand All @@ -148,8 +149,9 @@ bool PriorityReplace::is_valid() {
// Don't bother if the candidate end portion is empty or with a
// single job (that would be an UnassignedExchange move).
replace_end_valid =
(t_rank < s_route.size() - 1) &&
(0 < _end_priority_gain) &&
(_best_known_priority_gain <= _end_priority_gain) &&
(t_rank < s_route.size() - 1) &&
source.is_valid_addition_for_capacity_margins(_input,
j.pickup,
j.delivery,
Expand Down
9 changes: 8 additions & 1 deletion src/routing/http_wrapper.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,9 @@ All rights reserved (see LICENSE).

#include <asio.hpp>
#include <asio/ssl.hpp>

#include <fstream>
#include <iostream>
#include <sstream>
#include "routing/http_wrapper.h"

using asio::ip::tcp;
Expand Down Expand Up @@ -228,6 +230,11 @@ void HttpWrapper::add_geometry(Route& route) const {
assert(get_legs_number(json_result) == non_break_locations.size() - 1);

route.geometry = get_geometry(json_result);

rapidjson::Document::AllocatorType& allocator = json_result.GetAllocator();
route.legs = get_legs(json_result, allocator);

}


} // namespace vroom::routing
2 changes: 2 additions & 0 deletions src/routing/http_wrapper.h
Original file line number Diff line number Diff line change
Expand Up @@ -70,6 +70,8 @@ class HttpWrapper : public Wrapper {

virtual std::string get_geometry(rapidjson::Value& result) const = 0;

virtual rapidjson::Value get_legs(rapidjson::Value& result, rapidjson::Document::AllocatorType& allocator) const = 0;

void add_geometry(Route& route) const override;
};

Expand Down
10 changes: 8 additions & 2 deletions src/routing/ors_wrapper.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -48,8 +48,7 @@ std::string OrsWrapper::build_query(const std::vector<Location>& locations,
body += "}";

// Building query for ORS
std::string query =
"POST /" + _server.path + "ors/v2/" + service + "/" + profile;
std::string query = "POST /" + _server.path + service + "/" + profile;

query += " HTTP/1.0\r\n";
query += "Accept: */*\r\n";
Expand Down Expand Up @@ -98,5 +97,12 @@ unsigned OrsWrapper::get_legs_number(const rapidjson::Value& result) const {
std::string OrsWrapper::get_geometry(rapidjson::Value& result) const {
return result["routes"][0]["geometry"].GetString();
}

rapidjson::Value OrsWrapper::get_legs(rapidjson::Value& result, rapidjson::Document::AllocatorType& allocator) const {
rapidjson::Value legs(rapidjson::kArrayType);
legs.CopyFrom(result["routes"][0]["segments"], allocator);
return legs;
}


} // namespace vroom::routing
3 changes: 3 additions & 0 deletions src/routing/ors_wrapper.h
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,9 @@ class OrsWrapper : public HttpWrapper {
unsigned get_legs_number(const rapidjson::Value& result) const override;

std::string get_geometry(rapidjson::Value& result) const override;

rapidjson::Value get_legs(rapidjson::Value& result, rapidjson::Document::AllocatorType& allocator) const override;


public:
OrsWrapper(const std::string& profile, const Server& server);
Expand Down
9 changes: 8 additions & 1 deletion src/routing/osrm_routed_wrapper.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ OsrmRoutedWrapper::OsrmRoutedWrapper(const std::string& profile,
"durations",
"distances",
"route",
"alternatives=false&steps=false&overview=full&continue_"
"alternatives=false&steps=true&overview=full&continue_"
"straight=false") {
}

Expand Down Expand Up @@ -116,5 +116,12 @@ OsrmRoutedWrapper::get_legs_number(const rapidjson::Value& result) const {
std::string OsrmRoutedWrapper::get_geometry(rapidjson::Value& result) const {
return result["routes"][0]["geometry"].GetString();
}

rapidjson::Value OsrmRoutedWrapper::get_legs(rapidjson::Value& result, rapidjson::Document::AllocatorType& allocator) const {
rapidjson::Value legs(rapidjson::kArrayType);
legs.CopyFrom(result["routes"][0]["legs"], allocator);
return legs;
}


} // namespace vroom::routing
4 changes: 4 additions & 0 deletions src/routing/osrm_routed_wrapper.h
Original file line number Diff line number Diff line change
Expand Up @@ -38,8 +38,12 @@ class OsrmRoutedWrapper : public HttpWrapper {
unsigned get_legs_number(const rapidjson::Value& result) const override;

std::string get_geometry(rapidjson::Value& result) const override;

rapidjson::Value get_legs(rapidjson::Value& result, rapidjson::Document::AllocatorType& allocator) const override;


public:

OsrmRoutedWrapper(const std::string& profile, const Server& server);
};

Expand Down
7 changes: 7 additions & 0 deletions src/routing/valhalla_wrapper.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -185,5 +185,12 @@ std::string ValhallaWrapper::get_geometry(rapidjson::Value& result) const {

return encoder.encode();
}

rapidjson::Value ValhallaWrapper::get_legs(rapidjson::Value& result, rapidjson::Document::AllocatorType& allocator) const {
rapidjson::Value legs(rapidjson::kArrayType);
legs.CopyFrom(result["trip"]["legs"], allocator);
return legs;
}


} // namespace vroom::routing
2 changes: 2 additions & 0 deletions src/routing/valhalla_wrapper.h
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,8 @@ class ValhallaWrapper : public HttpWrapper {

std::string get_geometry(rapidjson::Value& result) const override;

rapidjson::Value get_legs(rapidjson::Value& result, rapidjson::Document::AllocatorType& allocator) const override;

public:
ValhallaWrapper(const std::string& profile, const Server& server);
};
Expand Down
11 changes: 7 additions & 4 deletions src/structures/typedefs.h
Original file line number Diff line number Diff line change
Expand Up @@ -190,19 +190,22 @@ struct StringHash {
};

namespace utils {
inline Duration scale_from_user_duration(UserDuration d) {
constexpr inline Duration scale_from_user_duration(UserDuration d) {
return DURATION_FACTOR * static_cast<Duration>(d);
}

inline UserDuration scale_to_user_duration(Duration d) {
constexpr inline UserDuration scale_to_user_duration(Duration d) {
assert(d <=
scale_from_user_duration(std::numeric_limits<UserDuration>::max()));
return static_cast<UserDuration>(d / DURATION_FACTOR);
}

inline Cost scale_from_user_cost(UserCost c) {
constexpr inline Cost scale_from_user_cost(UserCost c) {
return DURATION_FACTOR * COST_FACTOR * static_cast<Cost>(c);
}

inline UserCost scale_to_user_cost(Cost c) {
constexpr inline UserCost scale_to_user_cost(Cost c) {
assert(c <= scale_from_user_cost(std::numeric_limits<UserCost>::max()));
return static_cast<UserCost>(c / (DURATION_FACTOR * COST_FACTOR));
}
} // namespace utils
Expand Down
3 changes: 2 additions & 1 deletion src/structures/vroom/solution/route.h
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ All rights reserved (see LICENSE).

#include "structures/vroom/solution/step.h"
#include "structures/vroom/solution/violations.h"

#include "../include/rapidjson/include/rapidjson/document.h"
namespace vroom {

struct Route {
Expand All @@ -34,6 +34,7 @@ struct Route {
Violations violations;

std::string geometry;
rapidjson::Value legs;

Route();

Expand Down
7 changes: 5 additions & 2 deletions src/structures/vroom/time_window.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -13,10 +13,13 @@ All rights reserved (see LICENSE).
namespace vroom {

constexpr Duration TimeWindow::default_length =
std::numeric_limits<Duration>::max();
utils::scale_from_user_duration(std::numeric_limits<UserDuration>::max());

TimeWindow::TimeWindow()
: start(0), end(std::numeric_limits<Duration>::max()), length(end - start) {
: start(0),
end(utils::scale_from_user_duration(
std::numeric_limits<UserDuration>::max())),
length(end - start) {
}

TimeWindow::TimeWindow(UserDuration start, UserDuration end)
Expand Down
3 changes: 2 additions & 1 deletion src/structures/vroom/vehicle.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,8 @@ Vehicle::Vehicle(Id id,
max_travel_time(max_travel_time.has_value()
? utils::scale_from_user_duration(max_travel_time.value())
: DEFAULT_MAX_TRAVEL_TIME),
max_distance(max_distance.value_or(DEFAULT_MAX_DISTANCE)),
max_distance(max_distance.has_value() ? max_distance.value()
: DEFAULT_MAX_DISTANCE),
has_break_max_load(std::ranges::any_of(breaks, [](const auto& b) {
return b.max_load.has_value();
})) {
Expand Down
7 changes: 7 additions & 0 deletions src/utils/output_json.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -263,6 +263,13 @@ rapidjson::Value to_json(const Route& route,
route.geometry.size());
}


if (!route.legs.Empty()) {
rapidjson::Value legs(rapidjson::kArrayType);
legs.CopyFrom(route.legs, allocator);
json_route.AddMember("legs", legs, allocator);
}

return json_route;
}

Expand Down
2 changes: 1 addition & 1 deletion src/utils/version.h
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ All rights reserved (see LICENSE).
constexpr unsigned MAJOR = 1;
constexpr unsigned MINOR = 14;
constexpr unsigned PATCH = 0;
constexpr bool DEV = true;
constexpr bool DEV = false;
constexpr unsigned RC = 0;

namespace vroom {
Expand Down