Skip to content

Commit

Permalink
wip
Browse files Browse the repository at this point in the history
  • Loading branch information
felixguendling committed Jan 18, 2022
1 parent 8f27967 commit b025374
Show file tree
Hide file tree
Showing 97 changed files with 6,662 additions and 166 deletions.
6 changes: 6 additions & 0 deletions base/core/include/motis/core/journey/journey.h
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,8 @@

#include "cista/reflection/comparable.h"

#include "geo/latlng.h"

#include "motis/core/schedule/attribute.h"
#include "motis/core/schedule/free_text.h"
#include "motis/core/schedule/timestamp_reason.h"
Expand Down Expand Up @@ -46,6 +48,10 @@ struct journey {
unsigned mumo_price_{0};
unsigned mumo_accessibility_{0};
std::string mumo_type_;
uint16_t from_leg_{100};
uint16_t to_leg_{100};
geo::latlng from_loc_{};
geo::latlng to_loc_{};
};

struct trip {
Expand Down
20 changes: 20 additions & 0 deletions base/core/include/motis/core/schedule/connection.h
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,26 @@ inline service_class& operator++(service_class& c) {
return c = static_cast<service_class>(static_cast<service_class_t>(c) + 1);
}

inline bool operator<(service_class const a, service_class const b) {
return static_cast<std::underlying_type_t<service_class>>(a) <
static_cast<std::underlying_type_t<service_class>>(b);
}

inline bool operator<=(service_class const a, service_class const b) {
return static_cast<std::underlying_type_t<service_class>>(a) <=
static_cast<std::underlying_type_t<service_class>>(b);
}

inline bool operator>(service_class const a, service_class const b) {
return static_cast<std::underlying_type_t<service_class>>(a) >
static_cast<std::underlying_type_t<service_class>>(b);
}

inline bool operator>=(service_class const a, service_class const b) {
return static_cast<std::underlying_type_t<service_class>>(a) >=
static_cast<std::underlying_type_t<service_class>>(b);
}

struct connection_info {
CISTA_COMPARABLE();

Expand Down
18 changes: 10 additions & 8 deletions base/core/include/motis/core/schedule/edges.h
Original file line number Diff line number Diff line change
Expand Up @@ -18,30 +18,30 @@ struct edge_cost {
: connection_(nullptr),
time_(INVALID_TIME),
price_(0),
transfer_(false),
transfers_(0),
accessibility_(0) {}

edge_cost(duration time, light_connection const* c)
edge_cost(duration time, light_connection const* c, uint16_t price = 0)
: connection_(c),
time_(time),
price_(0),
transfer_(false),
price_(price),
transfers_(0u),
accessibility_(0) {}

explicit edge_cost(duration time, bool transfer = false, uint16_t price = 0,
uint16_t accessibility = 0)
: connection_(nullptr),
time_(time),
price_(price),
transfer_(transfer),
transfers_(static_cast<uint8_t>(transfer)),
accessibility_(accessibility) {}

bool is_valid() const { return time_ != INVALID_TIME; }

light_connection const* connection_;
duration time_;
uint16_t price_;
bool transfer_;
uint8_t transfers_;
uint16_t accessibility_;
};

Expand Down Expand Up @@ -113,6 +113,7 @@ class edge {
template <search_dir Dir = search_dir::FWD>
edge_cost get_edge_cost(time start_time,
light_connection const* last_con) const {

switch (m_.type_) {
case ROUTE_EDGE: return get_route_edge_cost<Dir>(start_time);

Expand All @@ -125,7 +126,8 @@ class edge {

case EXIT_EDGE:
if (Dir == search_dir::FWD) {
return last_con == nullptr ? NO_EDGE : get_foot_edge_cost();
return last_con == nullptr ? get_foot_edge_no_cost()
: get_foot_edge_cost();
} else {
return get_foot_edge_no_cost();
}
Expand Down Expand Up @@ -300,7 +302,7 @@ class edge {
? NO_EDGE
: edge_cost((Dir == search_dir::FWD) ? c->a_time_ - start_time
: start_time - c->d_time_,
c);
c, c->full_con_->price_);
}

template <search_dir Dir = search_dir::FWD>
Expand Down
7 changes: 5 additions & 2 deletions base/core/src/journeys_to_message.cc
Original file line number Diff line number Diff line change
Expand Up @@ -67,10 +67,13 @@ std::vector<Offset<MoveWrapper>> convert_moves(
for (auto const& t : transports) {
Range r(t.from_, t.to_);
if (t.is_walk_) {
Position from_loc{t.from_loc_.lat_, t.from_loc_.lng_};
Position to_loc{t.to_loc_.lat_, t.to_loc_.lng_};
moves.push_back(CreateMoveWrapper(
b, Move_Walk,
CreateWalk(b, &r, t.mumo_id_, t.mumo_price_, t.mumo_accessibility_,
b.CreateString(t.mumo_type_))
b.CreateString(t.mumo_type_), b.CreateString(t.provider_),
t.from_leg_, t.to_leg_, &from_loc, &to_loc)
.Union()));
} else {
moves.push_back(CreateMoveWrapper(
Expand Down Expand Up @@ -146,7 +149,7 @@ Offset<Connection> to_connection(FlatBufferBuilder& b, journey const& j) {
b.CreateVector(convert_attributes(b, j.attributes_)),
b.CreateVector(convert_free_texts(b, j.free_texts_)),
b.CreateVector(convert_problems(b, j.problems_)),
j.night_penalty_, j.db_costs_,
j.night_penalty_, j.db_costs_, j.price_,
status_to_fbs(j.status_));
}

Expand Down
5 changes: 5 additions & 0 deletions base/core/src/message_to_journeys.cc
Original file line number Diff line number Diff line change
Expand Up @@ -47,6 +47,11 @@ journey::transport to_transport(Walk const& walk, uint16_t duration) {
t.mumo_price_ = walk.price();
t.mumo_accessibility_ = walk.accessibility();
t.mumo_type_ = walk.mumo_type()->c_str();
t.provider_ = walk.lift_key()->c_str();
t.from_leg_ = walk.from_leg();
t.to_leg_ = walk.to_leg();
t.from_loc_ = {walk.from_loc()->lat(), walk.from_loc()->lng()};
t.to_loc_ = {walk.to_loc()->lat(), walk.to_loc()->lng()};
return t;
}

Expand Down
1 change: 1 addition & 0 deletions base/module/include/motis/module/context/motis_spawn.h
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
#include "ctx/ctx.h"

#include "motis/module/ctx_data.h"
#include "motis/module/dispatcher.h"

namespace motis::module {

Expand Down
3 changes: 2 additions & 1 deletion modules/intermodal/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,8 @@ target_link_libraries(motis-intermodal
motis-module
motis-core
motis-bootstrap
motis-ridesharing
geo
ppr-routing
)
target_compile_options(motis-intermodal PRIVATE ${MOTIS_CXX_FLAGS})
target_compile_options(motis-intermodal PRIVATE ${MOTIS_CXX_FLAGS})
22 changes: 18 additions & 4 deletions modules/intermodal/include/motis/intermodal/direct_connections.h
Original file line number Diff line number Diff line change
Expand Up @@ -11,26 +11,40 @@
#include "motis/intermodal/mumo_edge.h"
#include "motis/intermodal/ppr_profiles.h"
#include "motis/intermodal/query_bounds.h"
#include "motis/intermodal/ridesharing_edges.h"

namespace motis::intermodal {

struct direct_connection {
direct_connection() = default;
direct_connection(mumo_type type, unsigned duration, unsigned accessibility)
: type_(type), duration_(duration), accessibility_(accessibility) {}
direct_connection(mumo_type type, unsigned duration, unsigned accessibility,
uint16_t const price, std::time_t const dep_time,
ridesharing_edge rs_data)
: type_(type),
duration_(duration),
accessibility_(accessibility),
price_{price},
dep_time_{dep_time},
rs_data_{std::move(rs_data)} {}

mumo_type type_{mumo_type::FOOT};
unsigned duration_{}; // minutes
unsigned accessibility_{};
unsigned duration_{0U}; // minutes
unsigned accessibility_{0U};
uint16_t price_{0U};
std::time_t dep_time_{0U}; // zero if not time-dependent,then use query start
std::optional<ridesharing_edge> rs_data_;
};

std::vector<direct_connection> get_direct_connections(
query_start const& q_start, query_dest const& q_dest,
IntermodalRoutingRequest const* req, ppr_profiles const& profiles);
IntermodalRoutingRequest const* req, ppr_profiles const& profiles,
std::vector<direct_connection> const& ridesharing_direct_edges);

std::size_t remove_dominated_journeys(
std::vector<journey>& journeys,
std::vector<direct_connection> const& direct);
std::vector<direct_connection> const& direct, query_start const& q_start);

void add_direct_connections(std::vector<journey>& journeys,
std::vector<direct_connection> const& direct,
Expand Down
5 changes: 3 additions & 2 deletions modules/intermodal/include/motis/intermodal/intermodal.h
Original file line number Diff line number Diff line change
@@ -1,10 +1,11 @@
#pragma once

#include <string>

#include "motis/module/module.h"

#include "motis/intermodal/ppr_profiles.h"

#include <string>

namespace motis::intermodal {

struct intermodal : public motis::module::module {
Expand Down
30 changes: 19 additions & 11 deletions modules/intermodal/include/motis/intermodal/mumo_edge.h
Original file line number Diff line number Diff line change
Expand Up @@ -8,22 +8,13 @@

#include "motis/core/schedule/time.h"
#include "motis/core/statistics/statistics.h"
#include "motis/intermodal/mumo_type.h"
#include "motis/intermodal/ppr_profiles.h"
#include "motis/intermodal/ridesharing_edges.h"
#include "motis/protocol/Message_generated.h"

namespace motis::intermodal {

enum class mumo_type : int { FOOT, BIKE, CAR, CAR_PARKING };

inline int to_int(mumo_type const type) {
return static_cast<typename std::underlying_type<mumo_type>::type>(type);
}

inline std::string to_string(mumo_type const type) {
static char const* strs[] = {"foot", "bike", "car", "car_parking"};
return strs[to_int(type)]; // NOLINT
}

struct car_parking_edge {
int32_t parking_id_{};
geo::latlng parking_pos_{};
Expand All @@ -34,6 +25,16 @@ struct car_parking_edge {
bool uses_car_{};
};

struct ridesharing_edge {
std::string lift_key_{};
std::time_t t_{};
uint16_t price_{};
uint16_t from_leg_{};
uint16_t to_leg_{};
geo::latlng from_loc_{};
geo::latlng to_loc_{};
};

struct mumo_edge {
mumo_edge(std::string from, std::string to, geo::latlng const& from_pos,
geo::latlng const& to_pos, duration const d, uint16_t accessibility,
Expand All @@ -53,6 +54,7 @@ struct mumo_edge {
uint16_t accessibility_;
mumo_type type_;
int id_;
std::optional<ridesharing_edge> ridesharing_;
std::optional<car_parking_edge> car_parking_;
};

Expand All @@ -62,6 +64,11 @@ using appender_fun = std::function<mumo_edge&(

using mumo_stats_appender_fun = std::function<void(stats_category&&)>;

void make_ridesharing_request(
ridesharing_edges& rs_edges, geo::latlng const& start,
geo::latlng const& dest, bool start_is_intermodal, bool dest_is_intermodal,
std::time_t t,
std::pair<uint16_t, motis::ppr::SearchOptions const*> mode_data);
void make_starts(IntermodalRoutingRequest const*, geo::latlng const&,
appender_fun const&, mumo_stats_appender_fun const&,
ppr_profiles const&);
Expand All @@ -79,6 +86,7 @@ std::vector<flatbuffers::Offset<routing::AdditionalEdgeWrapper>> write_edges(
flatbuffers::FlatBufferBuilder& fbb, //
std::vector<mumo_edge> const& starts,
std::vector<mumo_edge> const& destinations,
ridesharing_edges const& rs_edges,
std::vector<mumo_edge const*>& edge_mapping);

} // namespace motis::intermodal
13 changes: 13 additions & 0 deletions modules/intermodal/include/motis/intermodal/mumo_type.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
#pragma once

enum class mumo_type : int { FOOT, BIKE, CAR, CAR_PARKING, RIDESHARING };

inline int to_int(mumo_type const type) {
return static_cast<typename std::underlying_type<mumo_type>::type>(type);
}

inline std::string to_string(mumo_type const type) {
static char const* strs[] = {"foot", "bike", "car", "car_parking",
"ridesharing"};
return strs[to_int(type)]; // NOLINT
}
7 changes: 4 additions & 3 deletions modules/intermodal/include/motis/intermodal/ppr_profiles.h
Original file line number Diff line number Diff line change
@@ -1,12 +1,13 @@
#pragma once

#include <map>
#include <string>

#include "motis/core/common/logging.h"

#include "motis/module/context/motis_call.h"
#include "motis/module/message.h"

#include <map>
#include <string>

namespace motis::intermodal {

struct ppr_profiles {
Expand Down
5 changes: 5 additions & 0 deletions modules/intermodal/include/motis/intermodal/query_bounds.h
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,10 @@
#include "motis/core/common/unixtime.h"
#include "motis/core/schedule/schedule.h"

#include "motis/intermodal/mumo_type.h"

#include "motis/ridesharing/query_response.h"

#include "motis/protocol/Message_generated.h"

namespace motis::intermodal {
Expand All @@ -30,6 +34,7 @@ struct query_start {
bool is_intermodal_;
geo::latlng pos_;
unixtime time_;
std::optional<motis::ridesharing::ridesharing_edge> rs_data_{};
};

query_start parse_query_start(flatbuffers::FlatBufferBuilder&,
Expand Down
19 changes: 19 additions & 0 deletions modules/intermodal/include/motis/intermodal/ridesharing_edges.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
#pragma once

#include <vector>

#include "motis/module/module.h"

namespace motis::intermodal {

struct mumo_edge;
struct direct_connection;

struct ridesharing_edges {
~ridesharing_edges();
std::vector<mumo_edge> arrs_;
std::vector<mumo_edge> deps_;
std::vector<direct_connection> direct_connections_;
};

} // namespace motis::intermodal
Loading

0 comments on commit b025374

Please sign in to comment.