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

Fixed matching on bidirectional edge when reverse movement tolerance was enabled #212

Open
wants to merge 1 commit 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
6 changes: 5 additions & 1 deletion src/mm/composite_graph.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -30,8 +30,12 @@ DummyGraph::DummyGraph(const Traj_Candidates &traj_candidates,
n, c.edge->index, c.offset-iter->second->offset);
} else if (iter->second->offset - c.offset <
c.edge->length * reverse_tolerance) {
// reverse movement is discouraged, so it has higher cost than normal
// movement.
double reverse_movement_cost =
(iter->second->offset - c.offset) * (2.0 - reverse_tolerance);
add_edge(iter->second->index,
n, c.edge->index, 0);
n, c.edge->index, reverse_movement_cost);
}
}
}
Expand Down
3 changes: 2 additions & 1 deletion src/network/network.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,8 @@ Network::Network(const std::string &filename,
const std::string &id_name,
const std::string &source_name,
const std::string &target_name) {
if (FMM::UTIL::check_file_extension(filename, "shp")) {
if (FMM::UTIL::check_file_extension(filename, "shp") ||
FMM::UTIL::check_file_extension(filename, "gpkg")) {
read_ogr_file(filename,id_name,source_name,target_name);
} else {
std::string message = (boost::format("Network file not supported %1%") % filename).str();
Expand Down
16 changes: 14 additions & 2 deletions test/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,18 @@ add_executable(fmm_test fmm_test.cpp
target_link_libraries(fmm_test ${GDAL_LIBRARIES} ${Boost_LIBRARIES}
${OpenMP_CXX_LIBRARIES} ${OSMIUM_LIBRARIES})

add_executable(stmatch_test stmatch_test.cpp
$<TARGET_OBJECTS:MM_OBJ>
$<TARGET_OBJECTS:CORE>
$<TARGET_OBJECTS:CONFIG>
$<TARGET_OBJECTS:ALGORITHM>
$<TARGET_OBJECTS:UTIL>
$<TARGET_OBJECTS:IO>
$<TARGET_OBJECTS:NETWORK>
$<TARGET_OBJECTS:STMATCH_OBJ>)
target_link_libraries(stmatch_test ${GDAL_LIBRARIES} ${Boost_LIBRARIES}
${OpenMP_CXX_LIBRARIES} ${OSMIUM_LIBRARIES})

add_executable(network_graph_test network_graph_test.cpp
$<TARGET_OBJECTS:CORE>
$<TARGET_OBJECTS:CONFIG>
Expand All @@ -33,7 +45,7 @@ add_executable(network_test network_test.cpp
$<TARGET_OBJECTS:IO>
$<TARGET_OBJECTS:NETWORK>)
target_link_libraries(network_test ${GDAL_LIBRARIES} ${OpenMP_CXX_LIBRARIES}
${OSMIUM_LIBRARIES})
${OSMIUM_LIBRARIES})

add_custom_target(tests
DEPENDS algorithm_test network_test network_graph_test fmm_test)
DEPENDS algorithm_test network_test network_graph_test fmm_test stmatch_test)
2 changes: 1 addition & 1 deletion test/fmm_test.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ TEST_CASE( "fmm is tested", "[fmm]" ) {
MatchResult result = model.match_traj(trajectory,config);
LineString expected_mgeom = wkt2linestring(
"LINESTRING(2 0.250988700565,2 1,2 2,3 2,4 2,4 2.45776836158)");
REQUIRE_THAT(result.cpath,Catch::Equals<int>({2,5,13,14,23}));
REQUIRE_THAT(result.cpath,Catch::Equals<FMM::NETWORK::EdgeID>({2,5,13,14,23}));
REQUIRE(expected_mgeom==result.mgeom);
}
}
48 changes: 48 additions & 0 deletions test/stmatch_test.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,48 @@
#include "core/geometry.hpp"
#include "mm/stmatch/stmatch_algorithm.hpp"
#define CATCH_CONFIG_MAIN
#include "catch2/catch.hpp"

#include "util/debug.hpp"
#include "network/network.hpp"
#include "mm/fmm/fmm_algorithm.hpp"
#include "mm/transition_graph.hpp"
#include "core/gps.hpp"
#include "io/gps_reader.hpp"

using namespace FMM;
using namespace FMM::IO;
using namespace FMM::CORE;
using namespace FMM::NETWORK;
using namespace FMM::MM;

TEST_CASE("stmatch is tested", "[stmatch]") {
spdlog::set_level((spdlog::level::level_enum) 0);
spdlog::set_pattern("[%l][%s:%-3#] %v");

SECTION("basic matching") {
Network network("../data/network.gpkg");
NetworkGraph graph(network);
STMATCH stmatch(network, graph);
CSVTrajectoryReader reader("../data/trips.csv","id","geom");
std::vector<Trajectory> trajectories = reader.read_all_trajectories();
const Trajectory &traj = trajectories[0];
STMATCHConfig config(4, 0.4, 0.5);
MatchResult result = stmatch.match_traj(traj, config);
LineString expected_mgeom = wkt2linestring(
"LINESTRING(2 0.250988700565,2 1,2 2,3 2,4 2,4 2.45776836158)");
REQUIRE_THAT(result.cpath,Catch::Equals<FMM::NETWORK::EdgeID>({2,5,13,14,23}));
REQUIRE(expected_mgeom == result.mgeom);
}

SECTION("bidirectional") {
Network network("../data/network.gpkg");
NetworkGraph graph(network);
STMATCH stmatch(network, graph);
Trajectory traj(1, wkt2linestring("LINESTRING (1.9 3.5,1.6 3.5,1.5 3.5,1.3 3.5,"
"1.0 3.5,0.8 3.5,0.6 3.5)"));
MatchResult result =
stmatch.match_traj(traj, STMATCHConfig(8, 1.0, 1.0, 30, 1.5, 0.5));
REQUIRE_THAT(result.cpath, Catch::Equals<FMM::NETWORK::EdgeID>({28}));
}
}