Skip to content

Commit

Permalink
fix
Browse files Browse the repository at this point in the history
  • Loading branch information
felixguendling committed Mar 5, 2024
1 parent 81454ca commit 6216987
Show file tree
Hide file tree
Showing 4 changed files with 103 additions and 51 deletions.
8 changes: 8 additions & 0 deletions include/nigiri/footpath.h
Original file line number Diff line number Diff line change
Expand Up @@ -51,6 +51,14 @@ struct footpath {
return out << "(" << fp.target() << ", " << fp.duration() << ")";
}

friend bool operator==(footpath const& a, footpath const& b) {
return a.value() == b.value();
}

friend bool operator<(footpath const& a, footpath const& b) {
return a.value() < b.value();
}

location_idx_t::value_t target_ : kTargetBits;
location_idx_t::value_t duration_ : kDurationBits;
};
Expand Down
30 changes: 0 additions & 30 deletions include/nigiri/loader/floyd_warshall.h

This file was deleted.

33 changes: 18 additions & 15 deletions src/loader/build_footpaths.cc
Original file line number Diff line number Diff line change
Expand Up @@ -4,10 +4,6 @@
#include <optional>
#include <stack>

#include "fmt/format.h"
#include "fmt/ostream.h"
#include "fmt/ranges.h"

#include "utl/enumerate.h"
#include "utl/equal_ranges_linear.h"
#include "utl/erase_duplicates.h"
Expand All @@ -17,15 +13,13 @@
#include "utl/progress_tracker.h"
#include "utl/verify.h"

#include "nigiri/loader/floyd_warshall.h"
#include "nigiri/loader/link_nearby_stations.h"
#include "nigiri/loader/merge_duplicates.h"
#include "nigiri/common/day_list.h"
#include "nigiri/constants.h"
#include "nigiri/logging.h"
#include "nigiri/routing/dijkstra.h"
#include "nigiri/rt/frun.h"
#include "nigiri/types.h"
#include "nigiri/timetable.h"

namespace nigiri::loader {

Expand Down Expand Up @@ -139,9 +133,11 @@ void process_2_node_component(timetable& tt,
}
}

void build_component_graph(timetable& tt,
component& c,
footgraph const& fgraph) {
void build_component_graph(
timetable& tt,
component& c,
footgraph const& fgraph,
cista::raw::mutable_fws_multimap<location_idx_t, footpath>& tmp_graph) {
if (c.invalid()) {
return;
}
Expand All @@ -151,9 +147,8 @@ void build_component_graph(timetable& tt,
utl::verify(size > 2, "invalid size [component={}], first={}", c.idx(),
tt.locations_.ids_.at(c.from_->l_).view());

tmp_graph.clear();
for (auto i = 0U; i != size; ++i) {
c.graph_.resize(c.graph_.size() + 1U);

auto it = c.from_;
auto const from_l = (c.from_ + i)->l_;
for (auto const& edge : fgraph[to_idx(from_l)]) {
Expand All @@ -169,10 +164,17 @@ void build_component_graph(timetable& tt,
auto const fp_duration = std::max({tt.locations_.transfer_time_[from_l],
tt.locations_.transfer_time_[to_l],
u8_minutes{edge.duration()}});
c.graph_[location_idx_t{c.graph_.size() - 1U}].push_back(
footpath{location_idx_t{j} /* TODO */, fp_duration});
tmp_graph[location_idx_t{i}].push_back(
footpath{location_idx_t{j}, fp_duration});
tmp_graph[location_idx_t{j}].push_back(
footpath{location_idx_t{i}, fp_duration});
}
}

for (auto n : tmp_graph) {
utl::erase_duplicates(n);
c.graph_.emplace_back(n);
}
}

void connect_components(timetable& tt,
Expand All @@ -196,6 +198,7 @@ void connect_components(timetable& tt,
tt.locations_.preprocessing_footpaths_in_[location_idx_t{
tt.locations_.src_.size() - 1}];

auto tmp_graph = cista::raw::mutable_fws_multimap<location_idx_t, footpath>{};
auto components = std::vector<component>{};
utl::equal_ranges_linear(
assignments,
Expand All @@ -207,7 +210,7 @@ void connect_components(timetable& tt,
} else if (c.size() == 2U) {
process_2_node_component(tt, c, fgraph);
} else {
build_component_graph(tt, c, fgraph);
build_component_graph(tt, c, fgraph, tmp_graph);
components.emplace_back(std::move(c));
}
});
Expand Down
83 changes: 77 additions & 6 deletions test/loader/build_footpaths_test.cc
Original file line number Diff line number Diff line change
Expand Up @@ -21,12 +21,6 @@ constexpr auto const test_files = R"(
# agency.txt
agency_id,agency_name,agency_url,agency_timezone
# stops.txt
stop_id,stop_name,stop_desc,stop_lat,stop_lon,stop_url,location_type,parent_station
A,A,,0.0,1.0,,
B,B,,2.0,3.0,,
C,C,,4.0,5.0,,
# routes.txt
route_id,agency_id,route_short_name,route_long_name,route_desc,route_type
Expand All @@ -39,6 +33,12 @@ trip_id,arrival_time,departure_time,stop_id,stop_sequence,pickup_type,drop_off_t
# calendar_dates.txt
service_id,date,exception_type
# stops.txt
stop_id,stop_name,stop_desc,stop_lat,stop_lon,stop_url,location_type,parent_station
A,A,,0.0,1.0,,
B,B,,2.0,3.0,,
C,C,,4.0,5.0,,
# transfers.txt
from_stop_id,to_stop_id,transfer_type,min_transfer_time
A,B,2,180
Expand Down Expand Up @@ -78,4 +78,75 @@ TEST(loader, build_footpaths) {
00:03.0->(B, B)
)"sv,
ss.str());
}

namespace {

constexpr auto const timetable_fr = R"(
# agency.txt
agency_id,agency_name,agency_url,agency_timezone
# routes.txt
route_id,agency_id,route_short_name,route_long_name,route_desc,route_type
# trips.txt
route_id,service_id,trip_id,trip_headsign,block_id
# stop_times.txt
trip_id,arrival_time,departure_time,stop_id,stop_sequence,pickup_type,drop_off_type
# calendar_dates.txt
service_id,date,exception_type
# stops.txt
stop_id,stop_code,stop_name,stop_desc,stop_lon,stop_lat,zone_id,stop_url,location_type,parent_station,stop_timezone,level_id,wheelchair_boarding,platform_code
IDFM:2921,,Gare de Breuillet Village,,2.171831602352254,48.56476273942137,4,,0,IDFM:59940,Europe/Paris,,1,
IDFM:18740,,Gare de Breuillet Village,,2.1718863797167716,48.56472713695579,4,,0,IDFM:59940,Europe/Paris,,1,
IDFM:3646,,Gare de Breuillet Village,,2.1723438872522034,48.5649372275467,4,,0,IDFM:59940,Europe/Paris,,1,
IDFM:monomodalStopPlace:43099,,Breuillet Village,,2.170354257290333,48.56433413404574,5,,0,IDFM:59940,,,0,
IDFM:StopPlaceEntrance:50170822,,r. de la Gare (bâtiment voyageur),,2.171354288391762,48.56494833051335,,,2,IDFM:59940,,,0,
IDFM:StopPlaceEntrance:50170823,,r. de la Gare (bus),,2.1717500047925014,48.56478016324463,,,2,IDFM:59940,,,0,
IDFM:StopPlaceEntrance:50170827,,r. de la Gare (parking),,2.171571124479157,48.56494984068485,,,2,IDFM:59940,,,0,
IDFM:StopPlaceEntrance:50170828,,r. de la Gare (passage à niveau),,2.170238281207967,48.56438280290591,,,2,IDFM:59940,,,0,
# transfers.txt
from_stop_id,to_stop_id,transfer_type,min_transfer_time
IDFM:18740,IDFM:2921,2,60
IDFM:18740,IDFM:3646,2,60
IDFM:18740,IDFM:monomodalStopPlace:43099,2,192
IDFM:2921,IDFM:18740,2,60
IDFM:2921,IDFM:3646,2,60
IDFM:2921,IDFM:monomodalStopPlace:43099,2,187
IDFM:3646,IDFM:18740,2,60
IDFM:3646,IDFM:2921,2,60
IDFM:3646,IDFM:monomodalStopPlace:43099,2,229
IDFM:monomodalStopPlace:43099,IDFM:18740,2,192
IDFM:monomodalStopPlace:43099,IDFM:2921,2,187
IDFM:monomodalStopPlace:43099,IDFM:3646,2,229
)";

} // namespace

TEST(loader, build_footpaths_fr) {
auto tt = timetable{};

tt.date_range_ = {date::sys_days{2024_y / March / 1},
date::sys_days{2024_y / March / 2}};
loader::register_special_stations(tt);
loader::gtfs::load_timetable({}, source_idx_t{0},
loader::mem_dir::read(timetable_fr), tt);
loader::finalize(tt);

auto ss = std::stringstream{};
for (auto const [i, x] : utl::enumerate(tt.locations_.footpaths_out_[0])) {
if (!x.empty()) {
ss << location{tt, location_idx_t{i}} << "\n";
for (auto const y : x) {
ss << " " << y.duration() << "->" << location{tt, y.target()} << "\n";
}
}
}

std::cout << ss.view() << "\n";
}

0 comments on commit 6216987

Please sign in to comment.