Skip to content

Commit

Permalink
RSL: Behavior model improvements (#405)
Browse files Browse the repository at this point in the history
  • Loading branch information
pablohoch authored Nov 21, 2023
1 parent 174192f commit 75aa5cb
Show file tree
Hide file tree
Showing 118 changed files with 4,784 additions and 3,509 deletions.
8 changes: 4 additions & 4 deletions .github/workflows/unix.yml
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,7 @@ jobs:
- name: Install RSL Web Interface Dependencies
uses: pnpm/action-setup@v2
with:
version: ^8.6.12
version: ^8.10.5
run_install: |
- cwd: ui/rsl
Expand Down Expand Up @@ -83,7 +83,7 @@ jobs:
- name: Install Protocol Tool Dependencies
uses: pnpm/action-setup@v2
with:
version: ^8.6.12
version: ^8.10.5
run_install: |
- cwd: tools/protocol
Expand Down Expand Up @@ -193,7 +193,7 @@ jobs:
- name: Install RSL Web Interface Dependencies
uses: pnpm/action-setup@v2
with:
version: ^8.6.12
version: ^8.10.5
run_install: |
- cwd: ./ui/rsl
Expand Down Expand Up @@ -344,7 +344,7 @@ jobs:
uses: pnpm/action-setup@v2
if: ${{ !matrix.config.skipui }}
with:
version: ^8.6.12
version: ^8.10.5
run_install: |
- cwd: ./ui/rsl
Expand Down
4 changes: 2 additions & 2 deletions .github/workflows/windows.yml
Original file line number Diff line number Diff line change
Expand Up @@ -106,7 +106,7 @@ jobs:
uses: pnpm/action-setup@v2
if: matrix.config.webui == 'On'
with:
version: ^8.6.12
version: ^8.10.5
run_install: |
- cwd: ./ui/rsl
Expand All @@ -120,7 +120,7 @@ jobs:
if: matrix.config.mode == 'Release'
uses: pnpm/action-setup@v2
with:
version: ^8.6.12
version: ^8.10.5
run_install: |
- cwd: tools/protocol
Expand Down
6 changes: 4 additions & 2 deletions base/core/include/motis/core/debug/trip.h
Original file line number Diff line number Diff line change
Expand Up @@ -135,7 +135,8 @@ struct trip_with_sections {
out << cista::ptr_cast(mt) << "/" << mt->trip_idx_ << " ";
}
out << "] arriving from "
<< station{sched, re->from_->get_station()->id_} << "\n";
<< station{sched, re->from_->get_station()->id_} << " at "
<< format_time(through_lc.a_time_) << "\n";
}
}
}
Expand All @@ -152,7 +153,8 @@ struct trip_with_sections {
out << cista::ptr_cast(mt) << "/" << mt->trip_idx_ << " ";
}
out << "] departing to "
<< station{sched, re.to_->get_station()->id_} << "\n";
<< station{sched, re.to_->get_station()->id_} << " at "
<< format_time(through_lc.d_time_) << "\n";
}
}
}
Expand Down
13 changes: 8 additions & 5 deletions docs/api/schemas/motis/paxmon.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -109,6 +109,8 @@ PaxMonRerouteLogRoute:
description: Probability before the reroute
new_probability:
description: Probability after the reroute
localization:
description: TODO
PaxMonRerouteLogEntry:
description: Information about a reroute event
fields:
Expand All @@ -128,11 +130,12 @@ PaxMonRerouteLogEntry:
description: Index and probabilities of the old route
new_routes:
description: Indices and probabilities of the new routes
localization:
description: |
Location of the passenger group at the system time of the reroute.
Alternative routes are searched from this location.
update_number:
description: >
The update number at the time of the reroute. Updates are processed in
batches. Updates with the same update number are processed in the same
batch. Note that there may be multiple update numbers with the same
system time.
PaxMonDataSource:
description: |
Passenger group ID based on the input data.
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
#pragma once

#include <cstdint>
#include <optional>

#include "motis/paxmon/broken_transfer_info.h"
#include "motis/paxmon/localization.h"

namespace motis::paxforecast {

// probability is stored because it may be changed before the simulation begins
// passenger count is stored for convenience
struct passenger_group_with_route_and_probability {
motis::paxmon::passenger_group_with_route pgwr_{};
float probability_{};
std::uint16_t passengers_{};
};

struct affected_route_info {
inline bool broken() const { return broken_transfer_info_.has_value(); }

passenger_group_with_route_and_probability pgwrap_{};
unsigned destination_station_id_{};
motis::paxmon::passenger_localization loc_now_{};
motis::paxmon::passenger_localization loc_broken_{};
std::optional<motis::paxmon::broken_transfer_info> broken_transfer_info_;
std::uint32_t alts_now_{}; // index -> alternatives set
std::uint32_t alts_broken_{}; // index -> alternatives set
};

} // namespace motis::paxforecast
43 changes: 37 additions & 6 deletions modules/paxforecast/include/motis/paxforecast/alternatives.h
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,8 @@

#include <vector>

#include "motis/hash_map.h"
#include "motis/pair.h"
#include "motis/vector.h"

#include "motis/core/schedule/schedule.h"
Expand Down Expand Up @@ -29,16 +31,45 @@ struct alternative {
bool is_original_{};
bool is_recommended_{};
measures::load_level load_info_{measures::load_level::UNKNOWN};

// set by simulation:
float pick_probability_{};
};

struct alternative_routing_options {
bool use_cache_{};
duration pretrip_interval_length_{};
bool allow_start_metas_{};
bool allow_dest_metas_{};
};

struct alternatives_request {
motis::paxmon::passenger_localization localization_{};
unsigned destination_station_id_{};

// result, set by alternative routing:
std::vector<alternative> alternatives_;
};

struct alternatives_set {
std::vector<alternatives_request> requests_;
mcd::hash_map<mcd::pair<motis::paxmon::passenger_localization,
unsigned /* destination_station_id */>,
std::uint32_t>
request_key_to_idx_;

std::uint32_t add_request(
motis::paxmon::passenger_localization const& localization,
unsigned destination_station_id);

void find(motis::paxmon::universe const& uv, schedule const& sched,
routing_cache& cache, alternative_routing_options const& options);
};

std::vector<alternative> find_alternatives(
motis::paxmon::universe const& uv, schedule const& sched,
routing_cache& cache,
mcd::vector<measures::measure_variant const*> const& group_measures,
unsigned const destination_station_id,
routing_cache& cache, unsigned const destination_station_id,
motis::paxmon::passenger_localization const& localization,
motis::paxmon::compact_journey const* remaining_journey, bool use_cache,
duration pretrip_interval_length, bool allow_start_metas,
bool allow_dest_metas);
alternative_routing_options options);

} // namespace motis::paxforecast
11 changes: 7 additions & 4 deletions modules/paxforecast/include/motis/paxforecast/behavior/util.h
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,8 @@

#include "motis/paxmon/passenger_group.h"

#include "motis/paxforecast/alternatives.h"

namespace motis::paxforecast::behavior {

template <typename T>
Expand Down Expand Up @@ -66,13 +68,13 @@ inline void only_keep_best_alternative(std::vector<float>& probabilities,
}

inline std::vector<float> calc_new_probabilites(
float const base_prob, std::vector<float> const& pick_probs,
float const base_prob, std::vector<alternative> const& alts,
float const threshold) {
if (pick_probs.empty()) {
if (alts.empty()) {
return {};
}
auto probs = utl::to_vec(
pick_probs, [&](auto const& pick_prob) { return base_prob * pick_prob; });
alts, [&](auto const& alt) { return base_prob * alt.pick_probability_; });
auto total_sum = 0.0F;
auto kept_sum = 0.0F;
auto rescale = false;
Expand All @@ -91,7 +93,8 @@ inline std::vector<float> calc_new_probabilites(
p /= scale;
}
} else if (kept_sum == 0.0F) {
probs = pick_probs;
probs = utl::to_vec(alts,
[&](auto const& alt) { return alt.pick_probability_; });
only_keep_best_alternative(probs, base_prob);
}
return probs;
Expand Down

This file was deleted.

23 changes: 0 additions & 23 deletions modules/paxforecast/include/motis/paxforecast/load_forecast.h

This file was deleted.

6 changes: 0 additions & 6 deletions modules/paxforecast/include/motis/paxforecast/messages.h
Original file line number Diff line number Diff line change
Expand Up @@ -5,16 +5,10 @@

#include "motis/paxmon/universe.h"

#include "motis/paxforecast/load_forecast.h"
#include "motis/paxforecast/measures/measures.h"
#include "motis/paxforecast/simulation_result.h"

namespace motis::paxforecast {

motis::module::msg_ptr make_forecast_update_msg(
schedule const& sched, motis::paxmon::universe const& uv,
simulation_result const& sim_result, load_forecast const& lfc);

measures::measure_collection from_fbs(
schedule const& sched,
flatbuffers::Vector<flatbuffers::Offset<MeasureWrapper>> const* ms);
Expand Down
5 changes: 2 additions & 3 deletions modules/paxforecast/include/motis/paxforecast/paxforecast.h
Original file line number Diff line number Diff line change
Expand Up @@ -39,13 +39,12 @@ struct paxforecast : public motis::module::module {
std::string routing_cache_filename_;
routing_cache routing_cache_;

bool calc_load_forecast_{true};
bool publish_load_forecast_{false};

bool deterministic_mode_{false};
duration min_delay_improvement_{5};
bool revert_forecasts_{false};
float probability_threshold_{0.01F};
float uninformed_pax_{0.F};
float major_delay_switch_{0.F};

bool allow_start_metas_{false};
bool allow_dest_metas_{false};
Expand Down
11 changes: 1 addition & 10 deletions modules/paxforecast/include/motis/paxforecast/revert_forecast.h
Original file line number Diff line number Diff line change
Expand Up @@ -2,24 +2,15 @@

#include <vector>

#include "motis/hash_map.h"

#include "motis/core/schedule/schedule.h"

#include "motis/paxmon/index_types.h"
#include "motis/paxmon/localization.h"
#include "motis/paxmon/universe.h"

#include "motis/paxforecast/simulation_result.h"

namespace motis::paxforecast {

void revert_forecasts(
motis::paxmon::universe& uv, schedule const& sched,
simulation_result const& sim_result,
std::vector<motis::paxmon::passenger_group_with_route> const& pgwrs,
mcd::hash_map<motis::paxmon::passenger_group_with_route,
motis::paxmon::passenger_localization const*> const&
pgwr_localizations);
std::vector<motis::paxmon::passenger_group_with_route> const& pgwrs);

} // namespace motis::paxforecast
Loading

0 comments on commit 75aa5cb

Please sign in to comment.