diff --git a/.gitmodules b/.gitmodules index b3b0fa3..cfb67a0 100644 --- a/.gitmodules +++ b/.gitmodules @@ -1,3 +1,6 @@ [submodule "3rdparty/qhttp"] path = 3rdparty/qhttp url = https://github.com/giraldeau/qhttp.git +[submodule "3rdparty/rapidjson"] + path = 3rdparty/rapidjson + url = https://github.com/miloyip/rapidjson diff --git a/3rdparty/CMakeLists.txt b/3rdparty/CMakeLists.txt new file mode 100644 index 0000000..60fea36 --- /dev/null +++ b/3rdparty/CMakeLists.txt @@ -0,0 +1 @@ +add_subdirectory(qhttp) diff --git a/3rdparty/rapidjson b/3rdparty/rapidjson new file mode 160000 index 0000000..7e68aa0 --- /dev/null +++ b/3rdparty/rapidjson @@ -0,0 +1 @@ +Subproject commit 7e68aa0a21b7800ec98133cb106e49bd6536e25c diff --git a/CMakeLists.txt b/CMakeLists.txt new file mode 100644 index 0000000..2ac225a --- /dev/null +++ b/CMakeLists.txt @@ -0,0 +1,25 @@ +cmake_minimum_required(VERSION 3.10) + +project(EvNav) +list(APPEND CMAKE_MODULE_PATH "${CMAKE_CURRENT_SOURCE_DIR}/cmake") + +set(CMAKE_CXX_STANDARD 14) +set(CMAKE_CXX_STANDARD_REQUIRED ON) +set(THREADS_PREFER_PTHREAD_FLAG ON) +set(CMAKE_DISABLE_SOURCE_CHANGES ON) +set(CMAKE_AUTOMOC ON) + +include(GNUInstallDirs) +find_package(Threads REQUIRED) +find_package(Qt5 COMPONENTS Core Network Test REQUIRED) +find_package(LibOSRM REQUIRED) +link_directories(${LibOSRM_LIBRARY_DIRS}) + +enable_testing() + +add_subdirectory(3rdparty) +add_subdirectory(libevnav) +add_subdirectory(evnav-srv) +add_subdirectory(evnav-cli) +add_subdirectory(example) +add_subdirectory(tests) diff --git a/cmake/FindLibOSRM.cmake b/cmake/FindLibOSRM.cmake new file mode 100644 index 0000000..50a5641 --- /dev/null +++ b/cmake/FindLibOSRM.cmake @@ -0,0 +1,63 @@ +# - Try to find LibOSRM +# Once done this will define +# LibOSRM_FOUND - System has LibOSRM +# LibOSRM_LIBRARIES - The libraries and ldflags needed to use LibOSRM +# LibOSRM_DEPENDENT_LIBRARIES - The libraries and ldflags need to link LibOSRM dependencies +# LibOSRM_LIBRARY_DIRS - The libraries paths needed to find LibOSRM +# LibOSRM_CXXFLAGS - Compiler switches required for using LibOSRM + +find_package(PkgConfig) +pkg_search_module(PC_LibOSRM QUIET libosrm) + +function(JOIN VALUES GLUE OUTPUT) + string (REPLACE ";" "${GLUE}" _TMP_STR "${VALUES}") + set (${OUTPUT} "${_TMP_STR}" PARENT_SCOPE) +endfunction() + +list(REMOVE_ITEM PC_LibOSRM_CFLAGS " ") +JOIN("${PC_LibOSRM_CFLAGS}" " " output) + +set(LibOSRM_CXXFLAGS ${output}) +set(LibOSRM_LIBRARY_DIRS ${PC_LibOSRM_LIBRARY_DIRS}) + +find_path(LibOSRM_INCLUDE_DIR osrm/osrm.hpp + PATH_SUFFIXES osrm include/osrm include + HINTS ${PC_LibOSRM_INCLUDEDIR} ${PC_LibOSRM_INCLUDE_DIRS} + ~/Library/Frameworks + /Library/Frameworks + /usr/local + /usr + /opt/local + /opt) + +find_library(TEST_LibOSRM_STATIC_LIBRARY Names osrm.lib libosrm.a + PATH_SUFFIXES osrm lib/osrm lib + HINTS ${PC_LibOSRM_LIBDIR} ${PC_LibOSRM_LIBRARY_DIRS} + ~/Library/Frameworks + /Library/Frameworks + /usr/local + /usr + /opt/local + /opt) +find_library(TEST_LibOSRM_DYNAMIC_LIBRARY Names libosrm.dylib libosrm.so + PATH_SUFFIXES osrm lib/osrm lib + HINTS ${PC_LibOSRM_LIBDIR} ${PC_LibOSRM_LIBRARY_DIRS} + ~/Library/Frameworks + /Library/Frameworks + /usr/local + /usr + /opt/local + /opt) + +set(LibOSRM_DEPENDENT_LIBRARIES ${PC_LibOSRM_STATIC_LDFLAGS}) +set(LibOSRM_LIBRARIES ${PC_LibOSRM_LDFLAGS}) + +include(FindPackageHandleStandardArgs) +# handle the QUIETLY and REQUIRED arguments and set LIBOSRM_FOUND to TRUE +# if all listed variables are TRUE +find_package_handle_standard_args(LibOSRM DEFAULT_MSG + LibOSRM_LIBRARY_DIRS + LibOSRM_CXXFLAGS + LibOSRM_LIBRARIES + LibOSRM_DEPENDENT_LIBRARIES + LibOSRM_INCLUDE_DIR) diff --git a/evnav-cli/CMakeLists.txt b/evnav-cli/CMakeLists.txt new file mode 100644 index 0000000..bf27d29 --- /dev/null +++ b/evnav-cli/CMakeLists.txt @@ -0,0 +1,3 @@ +add_executable(evnav-cli main.cpp) +target_link_libraries(evnav-cli evnavcore) +install(TARGETS evnav-cli DESTINATION bin) diff --git a/evnav-cli/main.cpp b/evnav-cli/main.cpp index 54130c5..1c7c440 100644 --- a/evnav-cli/main.cpp +++ b/evnav-cli/main.cpp @@ -45,7 +45,7 @@ int main(int argc, char *argv[]) ChargerProvider provider; provider.loadJson(args.at(1)); - ChargerProvider dcfc = provider.filter(provider.fastChargerFilter()); + ChargerProvider dcfc = provider.filter(ChargerProvider::fastChargerFilter); qDebug() << "chargers loaded:" << provider.size(); qDebug() << "fast chargers:" << dcfc.size(); diff --git a/evnav-srv/CMakeLists.txt b/evnav-srv/CMakeLists.txt new file mode 100644 index 0000000..741de0d --- /dev/null +++ b/evnav-srv/CMakeLists.txt @@ -0,0 +1,3 @@ +add_executable(evnav-srv main.cpp) +target_link_libraries(evnav-srv evnavcore) +install(TARGETS evnav-srv DESTINATION bin) diff --git a/evnav-srv/main.cpp b/evnav-srv/main.cpp index 785a9bd..07cf192 100644 --- a/evnav-srv/main.cpp +++ b/evnav-srv/main.cpp @@ -43,7 +43,7 @@ int main(int argc, char *argv[]) qDebug() << "loading chargers..."; ChargerProvider provider; provider.loadJson(args.at(1)); - ChargerProvider dcfc = provider.filter(provider.fastChargerFilter()); + ChargerProvider dcfc = provider.filter(ChargerProvider::fastChargerFilter); qDebug() << "fast chargers found:" << dcfc.size(); evnav.setChargerProvider(&dcfc); diff --git a/example/CMakeLists.txt b/example/CMakeLists.txt new file mode 100644 index 0000000..025c95e --- /dev/null +++ b/example/CMakeLists.txt @@ -0,0 +1,2 @@ +add_executable(minievnav main.cpp) +target_link_libraries(minievnav evnavcore) diff --git a/example/main.cpp b/example/main.cpp index 7eb6e03..bc8497d 100644 --- a/example/main.cpp +++ b/example/main.cpp @@ -25,8 +25,7 @@ int main(int argc, char *argv[]) config.storage_config = {argv[1]}; config.use_shared_memory = false; - qDebug() << config.storage_config.core_data_path.c_str(); - qDebug() << config.storage_config.file_index_path.c_str(); + qDebug() << config.storage_config.base_path.c_str(); qDebug() << config.storage_config.IsValid(); qDebug() << config.IsValid(); diff --git a/libevnav/CMakeLists.txt b/libevnav/CMakeLists.txt new file mode 100644 index 0000000..eee5ca8 --- /dev/null +++ b/libevnav/CMakeLists.txt @@ -0,0 +1,6 @@ +file(GLOB EVNAVCORE_SOURCES "*.cpp" "*.h") + +add_library(evnavcore ${EVNAVCORE_SOURCES}) +target_link_libraries(evnavcore PUBLIC Qt5::Core qhttp Threads::Threads ${LibOSRM_LIBRARIES} ${LibOSRM_DEPENDENT_LIBRARIES}) +target_include_directories(evnavcore PUBLIC ${CMAKE_CURRENT_SOURCE_DIR} ${LibOSRM_INCLUDE_DIR} "${LibOSRM_INCLUDE_DIR}/osrm") +set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} ${LibOSRM_CXXFLAGS}") diff --git a/libevnav/charger.h b/libevnav/charger.h index 5071c7c..8456199 100644 --- a/libevnav/charger.h +++ b/libevnav/charger.h @@ -8,7 +8,7 @@ #include #include #include -#include +#include #include "edge.h" diff --git a/libevnav/chargerprovider.cpp b/libevnav/chargerprovider.cpp index b1f062a..a216522 100644 --- a/libevnav/chargerprovider.cpp +++ b/libevnav/chargerprovider.cpp @@ -46,3 +46,8 @@ ChargerProvider ChargerProvider::filter(std::function predicat } return ChargerProvider(filtered); } + +bool ChargerProvider::fastChargerFilter(Charger &charger) +{ + return charger.level() == 3; +} diff --git a/libevnav/chargerprovider.h b/libevnav/chargerprovider.h index 2eeb8c0..cf48d8f 100644 --- a/libevnav/chargerprovider.h +++ b/libevnav/chargerprovider.h @@ -25,14 +25,9 @@ class ChargerProvider int size() { return m_chargers.size(); } QList chargers() { return m_chargers.values(); } Charger charger(VertexId id) { return m_chargers[id]; } - - ChargerProvider filter(std::function predicate); - auto fastChargerFilter() { - return [](Charger &c){ return c.level() == 3; }; - } - + static bool fastChargerFilter(Charger &charger); signals: public slots: diff --git a/libevnav/evnav.cpp b/libevnav/evnav.cpp index 0b4acab..0255e7e 100644 --- a/libevnav/evnav.cpp +++ b/libevnav/evnav.cpp @@ -8,6 +8,8 @@ #define _USE_MATH_DEFINES #include +using namespace osrm; + Evnav::Evnav(const QString &osrm) { Q_UNUSED(osrm); diff --git a/libevnav/evnav.h b/libevnav/evnav.h index 80bbb69..86c3025 100644 --- a/libevnav/evnav.h +++ b/libevnav/evnav.h @@ -14,8 +14,6 @@ #include "evnavrequest.h" #include "graph.h" -using namespace osrm; - class Trip { public: int dist_m; @@ -35,7 +33,7 @@ class Evnav void route(EvnavRequest &req, QJsonObject &result); void write(QVector &path, QJsonObject &json); - engine::Status computeTrip(const Coordinate &src, const Coordinate &dst, Trip &t); + engine::Status computeTrip(const osrm::util::Coordinate &src, const osrm::util::Coordinate &dst, Trip &t); void chargerMatrix(std::function cb); void computeDistanceHistogram(QVector &hist, int bin); diff --git a/libevnav/shortestpath.cpp b/libevnav/shortestpath.cpp index 837bce2..a654ec8 100644 --- a/libevnav/shortestpath.cpp +++ b/libevnav/shortestpath.cpp @@ -25,7 +25,7 @@ double ShortestPath::distTo(VertexId dst) { if (m_distTo.contains(dst)) return m_distTo[dst]; - return INFINITY; + return Q_INFINITY; } bool ShortestPath::hasPathTo(VertexId dst) @@ -49,8 +49,8 @@ QList ShortestPath::pathTo(VertexId dst) void ShortestPath::relax(Edge &e) { - double old_dist = INFINITY; - double new_dist = INFINITY; + double old_dist = Q_INFINITY; + double new_dist = Q_INFINITY; VertexId v = e.from(); VertexId w = e.to(); if (m_distTo.contains(v)) diff --git a/tests/CMakeLists.txt b/tests/CMakeLists.txt new file mode 100644 index 0000000..986ecd4 --- /dev/null +++ b/tests/CMakeLists.txt @@ -0,0 +1 @@ +add_subdirectory(graph) diff --git a/tests/graph/CMakeLists.txt b/tests/graph/CMakeLists.txt new file mode 100644 index 0000000..5281311 --- /dev/null +++ b/tests/graph/CMakeLists.txt @@ -0,0 +1,4 @@ +add_executable(tst_graphtest tst_graphtest.cpp) +target_link_libraries(tst_graphtest evnavcore Qt5::Test) +#target_include_directories(tst_graphtest PRIVATE "${LibOSRM_INCLUDE_DIRS}") +target_compile_definitions(tst_graphtest PRIVATE TOPSRCDIR="${CMAKE_SOURCE_DIR}") diff --git a/tests/graph/tst_graphtest.cpp b/tests/graph/tst_graphtest.cpp index f4a1c31..ad69377 100644 --- a/tests/graph/tst_graphtest.cpp +++ b/tests/graph/tst_graphtest.cpp @@ -103,7 +103,7 @@ void GraphTest::testLoadCharger() QString path(TOPSRCDIR "/res/result_circuit_electrique_20161019165359.json"); provider.loadJson(path); QVERIFY2(provider.size() > 0, "failed to load the charger list"); - ChargerProvider dcfc = provider.filter(provider.fastChargerFilter()); + ChargerProvider dcfc = provider.filter(ChargerProvider::fastChargerFilter); QVERIFY2(dcfc.size() > 0, "failed to filter chargers"); }