diff --git a/cmake/headers.cmake b/cmake/headers.cmake index 44af319..2aae87c 100644 --- a/cmake/headers.cmake +++ b/cmake/headers.cmake @@ -46,8 +46,6 @@ include/warthog/scenario/grid_patch_set.h include/warthog/scenario/scenario_manager.h include/warthog/scenario/scenario_runner.h -include/warthog/search/dummy_filter.h -include/warthog/search/dummy_listener.h include/warthog/search/expansion_policy.h include/warthog/search/gridmap_expansion_policy.h include/warthog/search/noop_search.h @@ -64,13 +62,10 @@ include/warthog/search/vl_gridmap_expansion_policy.h include/warthog/util/cast.h include/warthog/util/cost_table.h include/warthog/util/dimacs_parser.h -include/warthog/util/file_utils.h include/warthog/util/helpers.h include/warthog/util/intrin.h -include/warthog/util/macros.h include/warthog/util/pqueue.h include/warthog/util/string.h include/warthog/util/template.h include/warthog/util/timer.h -include/warthog/util/vec_io.h ) diff --git a/include/warthog/geometry/geom.h b/include/warthog/geometry/geom.h index 5e0730a..1e670f4 100644 --- a/include/warthog/geometry/geom.h +++ b/include/warthog/geometry/geom.h @@ -166,9 +166,23 @@ struct rectangle } // namespace warthog::geometry std::ostream& -operator<<(std::ostream& out, warthog::geometry::rectangle& rect); +operator<<(std::ostream& out, warthog::geometry::rectangle& rect) +{ + out.write((char*)(&rect.x1), sizeof(rect.x1)); + out.write((char*)(&rect.x2), sizeof(rect.x2)); + out.write((char*)(&rect.y1), sizeof(rect.y1)); + out.write((char*)(&rect.y2), sizeof(rect.y2)); + return out; +} std::istream& -operator>>(std::istream& in, warthog::geometry::rectangle& rect); +operator>>(std::istream& in, warthog::geometry::rectangle& rect) +{ + in.read((char*)(&rect.x1), sizeof(rect.x1)); + in.read((char*)(&rect.x2), sizeof(rect.x2)); + in.read((char*)(&rect.y1), sizeof(rect.y1)); + in.read((char*)(&rect.y2), sizeof(rect.y2)); + return in; +} #endif // WARTHOG_GEOMETRY_GEOM_H diff --git a/include/warthog/search/dummy_filter.h b/include/warthog/search/dummy_filter.h deleted file mode 100644 index 0b6d47c..0000000 --- a/include/warthog/search/dummy_filter.h +++ /dev/null @@ -1,36 +0,0 @@ -#ifndef WARTHOG_SEARCH_DUMMY_FILTER_H -#define WARTHOG_SEARCH_DUMMY_FILTER_H - -// search/dummy_filter.h -// -// A node filter that doesn't filter anything. -// -// @author: dharabor -// @created: 2016-07-19 -// - -#include - -namespace warthog::search -{ - -class dummy_filter -{ -public: - dummy_filter() { } - ~dummy_filter() { } - - inline bool - filter(uint32_t node_id, uint32_t edge_idx) - { - return false; - } - - inline void - set_target(uint32_t target_id) - { } -}; - -} // namespace warthog::search - -#endif // WARTHOG_SEARCH_DUMMY_FILTER_H diff --git a/include/warthog/search/dummy_listener.h b/include/warthog/search/dummy_listener.h deleted file mode 100644 index 1108b07..0000000 --- a/include/warthog/search/dummy_listener.h +++ /dev/null @@ -1,45 +0,0 @@ -#ifndef WARTHOG_SEARCH_DUMMY_LISTENER_H -#define WARTHOG_SEARCH_DUMMY_LISTENER_H - -// search/dummy_listener.h -// -// A search listener is a callback class that executes specialised -// code for partiular search events, such as when: -// - a node is generated -// - a node is expanded -// - a node is relaxed -// -// This class implements dummy listener with empty event handlers. -// -// @author: dharabor -// @created: 2020-03-09 -// - -#include "search_node.h" -#include -#include - -namespace warthog::search -{ - -class dummy_listener -{ -public: - inline void - generate_node( - search_node* parent, search_node* child, cost_t edge_cost, - uint32_t edge_id) - { } - - inline void - expand_node(search_node* current) - { } - - inline void - relax_node(search_node* current) - { } -}; - -} // namespace warthog::search - -#endif // WARTHOG_SEARCH_DUMMY_LISTENER_H diff --git a/include/warthog/search/unidirectional_search.h b/include/warthog/search/unidirectional_search.h index 4897a80..cef10ce 100644 --- a/include/warthog/search/unidirectional_search.h +++ b/include/warthog/search/unidirectional_search.h @@ -20,7 +20,6 @@ #include #include #include -#include #include #include diff --git a/include/warthog/util/file_utils.h b/include/warthog/util/file_utils.h deleted file mode 100644 index dbf17a8..0000000 --- a/include/warthog/util/file_utils.h +++ /dev/null @@ -1,113 +0,0 @@ -/* - * file_utils.h - * - * Created on: Oct 1, 2018 - * Author: koldar - */ - -#ifndef WARTHOG_UTIL_FILE_UTILS_H -#define WARTHOG_UTIL_FILE_UTILS_H - -#include - -namespace warthog::util -{ - -/** - * @brief get the number of bytes the file occipies on the filesyste, - * - * @param name the name fo the file to aqnalyze - * @return size_t number of bytes @c name occupies - */ -[[deprecated("Move to std::filesystem")]] -size_t -getBytesOfFile(const std::string& name); - -/** - * Check if a file exists - * - * @param[in] name the filename to check - * @return - * @li true fi the file exists; - * @li false otherwise; - */ -[[deprecated("Move to std::filesystem")]] -bool -isFileExists(const std::string& name); - -/** - * Get the basename of a file given its absolute path - * - * @pre - * @li filepath is an absolute path (like the one returneed by __FILE__); - * - * @param[in] filepath the absolute path to handle - * @return a pointer in @c filepath where the basename of the file starts - */ -consteval const char* -getBaseName_(const char* filepath) -{ - if(filepath == nullptr) return nullptr; - const char* name_start = filepath; - for(const char* p = filepath; *p != '\0'; ++p) - { - if(*p == '/' || *p == '\\') name_start = p + 1; - } - return name_start; -} - -/** - * Get the basename of a file given its absolute path - * - * @pre - * @li filepath is an absolute path (like the one returneed by __FILE__); - * - * @param[in] filepath the absolute path to handle - * @return a pointer in @c filepath where the basename of the file starts - */ -[[deprecated("Move to std::filesystem")]] -const char* -getBaseName(const char* filepath); - -/** - * @brief Get the basename of a file given its path - * - * @pre - * @li filepath does not end with "/" - * - * @param filepath the path to handle - * @return const char* a pointer of the given path - */ -[[deprecated("Move to std::filesystem")]] -const char* -getBaseName(const std::string& filepath); - -/** - * @brief Get the basename of a file given its path - * - * @pre - * @li filepath does not end with "/" - * - * @param filepath the path to handle - * @return a copy of the basename path - */ -[[deprecated("Move to std::filesystem")]] -std::string -getBaseNameAsString(const std::string& filepath); - -/** - * @brief Get the basename of a file given its path - * - * @pre - * @li filepath does not end with "/" - * - * @param filepath the path to handle - * @return a copy of the basename path - */ -[[deprecated("Move to std::filesystem")]] -std::string -getBaseNameAsString(const char* filepath); - -} // namespace warthog::util - -#endif // WARTHOG_UTIL_FILE_UTILS_H diff --git a/include/warthog/util/helpers.h b/include/warthog/util/helpers.h index 60b9349..24cfc00 100644 --- a/include/warthog/util/helpers.h +++ b/include/warthog/util/helpers.h @@ -47,36 +47,6 @@ load_integer_labels_dimacs( void value_index_swap_array(std::vector& vec); -struct thread_params -{ - // thread data - uint32_t thread_id_; - uint32_t max_threads_; - bool thread_finished_; - void* (*fn_worker_)(void*); - - // task data - uint32_t nprocessed_; - uint32_t first_id_; - uint32_t last_id_; - void* shared_; -}; - -// helper code for simple parallel computations. -// simple in this case means no synchronisation between threads. -// @param fn_worker: the actual precompute function: -// - it takes as input a pointer whose actual type is -// warthog::label::thread_params -// - it returns a (possibly null) pointer to a result -// @param shared_data: -// a pointer to data which will be shared among all worker -// threads -// @param task_total: the total number of tasks in the workload -// @return: 0 (the function always succeeds) -void* -parallel_compute( - void* (*fn_worker)(void*), void* shared_data, uint32_t task_total); - } // namespace warthog::util #endif // WARTHOG_UTIL_HELPERS_H diff --git a/include/warthog/util/macros.h b/include/warthog/util/macros.h deleted file mode 100644 index d2ef7a4..0000000 --- a/include/warthog/util/macros.h +++ /dev/null @@ -1,146 +0,0 @@ -/* - * macros.h - * - * Created on: Oct 1, 2018 - * Author: koldar - */ - -#ifndef WARTHOG_UTIL_MACROS_H -#define WARTHOG_UTIL_MACROS_H - -#define CAT(x, y) x##y - -#define PASTE(x, y) CAT(x, y) - -/** - * Count the arguments in a variadic macro - * - * @code - * COUNT_ARGS(a) //1 - * COUNT_ARGS(a,b) //2 - * @endcode - * - * @param[in] ... params to count - */ -#define COUNT_ARGS(...) _COUNT_ARGS(__VA_ARGS__, _PP_RSEQ_N()) -#define _COUNT_ARGS(...) _PP_ARG_N(__VA_ARGS__) -#define _PP_ARG_N( \ - _1, _2, _3, _4, _5, _6, _7, _8, _9, _10, _11, _12, _13, _14, _15, _16, \ - _17, _18, _19, _20, _21, _22, _23, _24, _25, _26, _27, _28, _29, _30, \ - _31, _32, _33, _34, _35, _36, _37, _38, _39, _40, _41, _42, _43, _44, \ - _45, _46, _47, _48, _49, _50, _51, _52, _53, _54, _55, _56, _57, _58, \ - _59, _60, _61, _62, _63, N, ...) \ - N - -#define _PP_RSEQ_N() \ - 63, 62, 61, 60, 59, 58, 57, 56, 55, 54, 53, 52, 51, 50, 49, 48, 47, 46, \ - 45, 44, 43, 42, 41, 40, 39, 38, 37, 36, 35, 34, 33, 32, 31, 30, 29, \ - 28, 27, 26, 25, 24, 23, 22, 21, 20, 19, 18, 17, 16, 15, 14, 13, 12, \ - 11, 10, 9, 8, 7, 6, 5, 4, 3, 2, 1, 0 - -/** - * Execute an operation for each element of a list - * - * Here's an example - * @code - * #define OPERATION_SUM_MAP(context, index, x) (x*x) - * #define OPERATION_SUM_COMBINE(context, x, y) x + y - * - * FOR_EACH(,OPERATION_SUM_MAP, OPERATION_MAP_COMBINE, 1, 2, 3, 4); - * //outputs (1*1)+(2*2)+(3*3)+(4*4) - * @endcode - * - * @attention - * empty variadic is not support - * - * @param[in] CONTEXT a macro that will be available to both the mapping macro - * and the combine macro - * @param[in] OP a macro telling us what we need to do with a single value in - * the variadic - * @param[in] COMB a macro telling us how to combine 2 values previously - * generated by OP macro - */ -#define FOR_EACH(CONTEXT, OP, COMB, ...) \ - PASTE(_FOR_EACH_, COUNT_ARGS(__VA_ARGS__))(CONTEXT, OP, COMB, __VA_ARGS__) - -#define _FOR_EACH_1(CONTEXT, OP, COMB, x) OP(CONTEXT, 1, x) -#define _FOR_EACH_2(CONTEXT, OP, COMB, x, ...) \ - COMB( \ - CONTEXT, OP(CONTEXT, 2, x), \ - _FOR_EACH_1(CONTEXT, OP, COMB, __VA_ARGS__)) -#define _FOR_EACH_3(CONTEXT, OP, COMB, x, ...) \ - COMB( \ - CONTEXT, OP(CONTEXT, 3, x), \ - _FOR_EACH_2(CONTEXT, OP, COMB, __VA_ARGS__)) -#define _FOR_EACH_4(CONTEXT, OP, COMB, x, ...) \ - COMB( \ - CONTEXT, OP(CONTEXT, 4, x), \ - _FOR_EACH_3(CONTEXT, OP, COMB, __VA_ARGS__)) -#define _FOR_EACH_5(CONTEXT, OP, COMB, x, ...) \ - COMB( \ - CONTEXT, OP(CONTEXT, 5, x), \ - _FOR_EACH_4(CONTEXT, OP, COMB, __VA_ARGS__)) -#define _FOR_EACH_6(CONTEXT, OP, COMB, x, ...) \ - COMB( \ - CONTEXT, OP(CONTEXT, 6, x), \ - _FOR_EACH_5(CONTEXT, OP, COMB, __VA_ARGS__)) -#define _FOR_EACH_7(CONTEXT, OP, COMB, x, ...) \ - COMB( \ - CONTEXT, OP(CONTEXT, 7, x), \ - _FOR_EACH_6(CONTEXT, OP, COMB, __VA_ARGS__)) -#define _FOR_EACH_8(CONTEXT, OP, COMB, x, ...) \ - COMB( \ - CONTEXT, OP(CONTEXT, 8, x), \ - _FOR_EACH_7(CONTEXT, OP, COMB, __VA_ARGS__)) -#define _FOR_EACH_9(CONTEXT, OP, COMB, x, ...) \ - COMB( \ - CONTEXT, OP(CONTEXT, 9, x), \ - _FOR_EACH_8(CONTEXT, OP, COMB, __VA_ARGS__)) -#define _FOR_EACH_10(CONTEXT, OP, COMB, x, ...) \ - COMB( \ - CONTEXT, OP(CONTEXT, 10, x), \ - _FOR_EACH_9(CONTEXT, OP, COMB, __VA_ARGS__)) -#define _FOR_EACH_11(CONTEXT, OP, COMB, x, ...) \ - COMB( \ - CONTEXT, OP(CONTEXT, 11, x), \ - _FOR_EACH_10(CONTEXT, OP, COMB, __VA_ARGS__)) -#define _FOR_EACH_12(CONTEXT, OP, COMB, x, ...) \ - COMB( \ - CONTEXT, OP(CONTEXT, 12, x), \ - _FOR_EACH_11(CONTEXT, OP, COMB, __VA_ARGS__)) -#define _FOR_EACH_13(CONTEXT, OP, COMB, x, ...) \ - COMB( \ - CONTEXT, OP(CONTEXT, 13, x), \ - _FOR_EACH_12(CONTEXT, OP, COMB, __VA_ARGS__)) -#define _FOR_EACH_14(CONTEXT, OP, COMB, x, ...) \ - COMB( \ - CONTEXT, OP(CONTEXT, 14, x), \ - _FOR_EACH_13(CONTEXT, OP, COMB, __VA_ARGS__)) -#define _FOR_EACH_15(CONTEXT, OP, COMB, x, ...) \ - COMB( \ - CONTEXT, OP(CONTEXT, 15, x), \ - _FOR_EACH_14(CONTEXT, OP, COMB, __VA_ARGS__)) - -/** - * @attention - * empty variadic is not support - * - * @return the first item of a variadic sequence - */ -#define FIRST_ELEMENT(x, ...) x - -/** - * Executive the statements only if the pointer is not NULL - * - * @code - * int* a = ... - * DO_IF_NOT_NULL(a) { - * std::cout << " a is " << *a << std::endl; - * } - * @endcode - * - * @param[in] x the pointer to check - */ -#define DO_IF_NOT_NULL(x) if(x != nullptr) - -#endif // WARTHOG_UTIL_MACROS_H diff --git a/include/warthog/util/pqueue.h b/include/warthog/util/pqueue.h index 3e65f79..42b4d88 100644 --- a/include/warthog/util/pqueue.h +++ b/include/warthog/util/pqueue.h @@ -221,9 +221,10 @@ class pqueue newsize = newsize >= 4 ? newsize : 4; if(newsize < queuesize_) { - std::cerr << "err; pqueue::resize newsize < queuesize " - << std::endl; - exit(1); + WARTHOG_GCRIT_FMT( + "pqueue::resize newsize({}) < queuesize({})", newsize, + queuesize_); + throw std::logic_error("newsize < queuesize_"); } search::search_node** tmp = new search::search_node* [newsize] {}; diff --git a/include/warthog/util/timer.h b/include/warthog/util/timer.h index 6b3337a..47f21cb 100644 --- a/include/warthog/util/timer.h +++ b/include/warthog/util/timer.h @@ -45,18 +45,6 @@ class timer } clock::time_point get_time(); - // std::chrono::nanoseconds - // get_time_nano(); - // double - // get_time_micro() - // { - // return get_time_nano().count() * 1e-3; - // } - // double - // get_time_sec() - // { - // return get_time_nano().count() * 1e-9; - // } private: clock::time_point start_time; diff --git a/include/warthog/util/vec_io.h b/include/warthog/util/vec_io.h deleted file mode 100644 index 8383c8a..0000000 --- a/include/warthog/util/vec_io.h +++ /dev/null @@ -1,136 +0,0 @@ -#ifndef WARTHOG_UTIL_VEC_IO_H -#define WARTHOG_UTIL_VEC_IO_H - -#include -#include -#include -#include -#include -#include -#include -#include - -template -[[deprecated("TDB")]] -std::ostream& -operator<<(std::ostream& str, const std::unordered_set& v) -{ - str << "[ "; - for(auto it = v.begin(); it != v.end(); ++it) - { - str << *it << " "; - } - str << "]"; - return str; -} - -template -[[deprecated("TDB")]] -std::ostream& -operator<<(std::ostream& stream, const std::unordered_map& map) -{ - stream << "{ "; - for(auto el : map) - { - stream << "[" << el.first << ", " << el.second << "], "; - } - stream << " }"; - return stream; -} - -template -[[deprecated("TDB")]] -std::ostream& -operator<<(std::ostream& str, const std::vector& v) -{ - str << "[ "; - for(auto it = v.cbegin(); it != v.cend(); ++it) - { - str << *it << " "; - } - str << "]"; - return str; -} - -/** - * store a vector instance into a file - * - * @pre - * @li @c file open with "wb"; - * - * @param[inout] file the file to write into - * @param[in] v the vector to save into the file - */ -template -[[deprecated("TDB")]] -void -save_vector(std::FILE* file, const std::vector& v) -{ - int s = v.size(); - if(std::fwrite(&s, sizeof(s), 1, file) != 1) - throw std::runtime_error("std::fwrite failed"); - if(std::fwrite(&v[0], sizeof(T), v.size(), file) != v.size()) - throw std::runtime_error("std::fwrite failed"); -} - -/** - * Load a vector from a file - * - * @pre - * @li @c file open with "rb"; - * - * @param[inout] file the file to read - * @return a vector instance which has been just read from @c file - */ -template -[[deprecated("TDB")]] -std::vector -load_vector(std::FILE* file) -{ - int s; - if(std::fread(&s, sizeof(s), 1, file) != 1) - throw std::runtime_error("std::fread failed"); - std::vector v(s); - - size_t stuffRead = std::fread(&v[0], sizeof(T), s, file); - if((int)stuffRead != s) - { - WARTHOG_GERROR_FMT( - "we were expecting to read {} but we read {} elements instead", s, - stuffRead); - throw std::runtime_error("std::fread failed"); - } - - return v; // NVRO -} - -/** - * Convert an array of bytes to a vector of T. - */ -template -[[deprecated("TDB")]] -std::vector -load_vector(const char*& ss) -{ - // unsigned char temp; - int s, i = 0, st = sizeof(T); - - memcpy(&s, ss, sizeof(int)); - ss += sizeof(int); - - std::vector v(s); - - while(i < s) - { - T c; - - memcpy(&c, ss, st); - ss += st; - v.at(i) = c; - i++; - } - - return v; -} - -#endif // WARTHOG_UTIL_VEC_IO_H diff --git a/src/CMakeLists.txt b/src/CMakeLists.txt index a80741f..aae1329 100644 --- a/src/CMakeLists.txt +++ b/src/CMakeLists.txt @@ -4,7 +4,6 @@ target_sources(warthog_core PRIVATE domain/gridmap.cpp geometry/geography.cpp -geometry/geom.cpp io/bittable_serialize.cpp io/grid_trace.cpp @@ -28,7 +27,6 @@ search/vl_gridmap_expansion_policy.cpp util/cost_table.cpp util/dimacs_parser.cpp -util/file_utils.cpp util/helpers.cpp util/timer.cpp ) diff --git a/src/geometry/geography.cpp b/src/geometry/geography.cpp index b650c8c..0daa079 100644 --- a/src/geometry/geography.cpp +++ b/src/geometry/geography.cpp @@ -1,9 +1,8 @@ -#include -#include #include -#define PI_360 0.00872664625997 -#define PI_180 0.017453292519943295 +#include + +#include /* Writes result sine result sin(πa) to the location pointed to by sp Writes result cosine result cos(πa) to the location pointed to by cp @@ -19,6 +18,11 @@ namespace warthog::geometry namespace { +constexpr double PI_360 + = 0.008'726'646'259'971'647'884'618'453'842'443'063'567; +constexpr double PI_180 + = 0.017'453'292'519'943'295'769'236'907'684'886'127'134; + void sincospi(double a, double* sp, double* cp) { @@ -71,19 +75,11 @@ sincospi(double a, double* sp, double* cp) *cp = c; } -#ifdef NDEBUG -inline double -deg_to_rad(double deg) -{ - return deg * PI_180; -} -#else double deg_to_rad(double deg) { - return deg * M_PI / 180; + return deg * PI_180; } -#endif double rad_to_deg(double rad) diff --git a/src/geometry/geom.cpp b/src/geometry/geom.cpp deleted file mode 100644 index b1c5032..0000000 --- a/src/geometry/geom.cpp +++ /dev/null @@ -1,22 +0,0 @@ -#include -#include - -std::ostream& -operator<<(std::ostream& out, warthog::geometry::rectangle& rect) -{ - out.write((char*)(&rect.x1), sizeof(rect.x1)); - out.write((char*)(&rect.x2), sizeof(rect.x2)); - out.write((char*)(&rect.y1), sizeof(rect.y1)); - out.write((char*)(&rect.y2), sizeof(rect.y2)); - return out; -} - -std::istream& -operator>>(std::istream& in, warthog::geometry::rectangle& rect) -{ - in.read((char*)(&rect.x1), sizeof(rect.x1)); - in.read((char*)(&rect.x2), sizeof(rect.x2)); - in.read((char*)(&rect.y1), sizeof(rect.y1)); - in.read((char*)(&rect.y2), sizeof(rect.y2)); - return in; -} diff --git a/src/io/grid_trace.cpp b/src/io/grid_trace.cpp index 14bd25f..a608701 100644 --- a/src/io/grid_trace.cpp +++ b/src/io/grid_trace.cpp @@ -1,6 +1,7 @@ +#include + #include #include -#include namespace warthog::io { diff --git a/src/io/log.cpp b/src/io/log.cpp index 7e7a900..5d93e8e 100644 --- a/src/io/log.cpp +++ b/src/io/log.cpp @@ -1,7 +1,8 @@ +#include + #include #include #include -#include namespace warthog::io { diff --git a/src/io/scenario_serialize.cpp b/src/io/scenario_serialize.cpp index d723953..7d1025a 100644 --- a/src/io/scenario_serialize.cpp +++ b/src/io/scenario_serialize.cpp @@ -1,7 +1,6 @@ #include #include -// #include #include #include diff --git a/src/memory/node_pool.cpp b/src/memory/node_pool.cpp index d2df7a1..b7a3576 100644 --- a/src/memory/node_pool.cpp +++ b/src/memory/node_pool.cpp @@ -1,4 +1,5 @@ #include + #include #include diff --git a/src/scenario/scenario_manager.cpp b/src/scenario/scenario_manager.cpp index 4f49e71..a2ab501 100644 --- a/src/scenario/scenario_manager.cpp +++ b/src/scenario/scenario_manager.cpp @@ -2,7 +2,6 @@ #include #include -#include #include #include diff --git a/src/scenario/scenario_runner.cpp b/src/scenario/scenario_runner.cpp index 7357575..6305494 100644 --- a/src/scenario/scenario_runner.cpp +++ b/src/scenario/scenario_runner.cpp @@ -1,7 +1,6 @@ #include #include -#include #include #include diff --git a/src/util/cost_table.cpp b/src/util/cost_table.cpp index 7ca626b..b180135 100644 --- a/src/util/cost_table.cpp +++ b/src/util/cost_table.cpp @@ -1,6 +1,9 @@ #include +#include + #include +#include namespace warthog::util { @@ -10,10 +13,8 @@ cost_table::cost_table(const char* filename) : cost_table() std::ifstream file(filename, std::fstream::in); if(!file.is_open()) { - std::cerr << "err; cost_table::cost_table " - "cannot open costs file: " - << filename << std::endl; - exit(1); + WARTHOG_GERROR_FMT("cost_table cannot open costs file {}", filename); + throw std::runtime_error("cost_table"); } while(!file.eof()) @@ -23,25 +24,22 @@ cost_table::cost_table(const char* filename) : cost_table() file >> terrain >> cost; if(!file.good()) { - std::cerr << "err; cost_table::cost_table " - "failed to parse cost for terrain `" - << terrain << "`" << std::endl; - exit(1); + WARTHOG_GERROR_FMT( + "cost_table failed to parse cost for terrain `{}`", terrain); + throw std::runtime_error("cost_table"); } if(costs_[terrain] == costs_[terrain]) { - std::cerr - << "err; cost_table::cost_table " - "costs file contains multiple definitions for terrain `" - << terrain << "`" << std::endl; - exit(1); + WARTHOG_GERROR_FMT( + "cost_table multiple definitions for terrain `{}`", terrain); + throw std::runtime_error("cost_table"); } if(cost < 0.0) { - std::cerr << "err; cost_table::cost_table " - "costs file specifies a negative cost for terrain `" - << terrain << "`" << std::endl; - exit(1); + WARTHOG_GERROR_FMT( + "cost_table has negative cost for terrain `{}` at {}", terrain, + cost); + throw std::runtime_error("cost_table"); } costs_[terrain] = cost; file >> std::ws; @@ -56,7 +54,7 @@ cost_table::cost_table(const char* filename) : cost_table() cost_t cost_table::lowest_cost(domain::vl_gridmap& map) { - warthog::cost_t lowest = INFINITY; + warthog::cost_t lowest = std::numeric_limits::infinity(); for(uint32_t id = 0; id < map.width() * map.height(); id++) { auto cost = costs_[map.get_label(id)]; diff --git a/src/util/file_utils.cpp b/src/util/file_utils.cpp deleted file mode 100644 index 006f472..0000000 --- a/src/util/file_utils.cpp +++ /dev/null @@ -1,67 +0,0 @@ -/* - * file_utils.cpp - * - * Created on: Oct 1, 2018 - * Author: koldar - */ - -#include -#include -#include -#include - -namespace warthog::util -{ - -namespace -{ -const char* -getBaseName_aux(const char* filepath) -{ - if(filepath == nullptr) return nullptr; - const char* name_start = filepath; - for(const char* p = filepath; *p != '\0'; ++p) - { - if(*p == '/' || *p == '\\') name_start = p + 1; - } - return name_start; -} -} - -size_t -getBytesOfFile(const std::string& name) -{ - return std::filesystem::file_size(name); -} - -bool -isFileExists(const std::string& name) -{ - return std::filesystem::exists(name); -} - -std::string -getBaseNameAsString(const std::string& filepath) -{ - return getBaseName_aux(filepath.c_str()); -} - -std::string -getBaseNameAsString(const char* filepath) -{ - return getBaseName_aux(filepath); -} - -const char* -getBaseName(const std::string& filepath) -{ - return getBaseName_aux(filepath.c_str()); -} - -const char* -getBaseName(const char* filepath) -{ - return getBaseName_aux(filepath); -} - -} // namespace warthog::util diff --git a/src/util/helpers.cpp b/src/util/helpers.cpp index 81337d1..5132b97 100644 --- a/src/util/helpers.cpp +++ b/src/util/helpers.cpp @@ -7,9 +7,6 @@ #include #include #include -#include -#include -#include namespace warthog::util { @@ -53,83 +50,6 @@ load_integer_labels_dimacs(const char* filename, std::vector& labels) return load_integer_labels(filename, labels); } -void* -parallel_compute( - void* (*fn_worker)(void*), void* shared_data, uint32_t task_total) -{ - std::cerr << "parallel compute begin. tasks to process: " << task_total - << "\n"; - if(task_total == 0) { return 0; } - -// OK, let's fork some threads -// TODO: detect cores with std::thread::hardware_concurrency(); -#ifdef SINGLE_THREADED - const uint32_t NUM_THREADS = 1; -#else - const uint32_t NUM_THREADS = (uint32_t)std::thread::hardware_concurrency(); -#endif - - std::vector threads(NUM_THREADS); - std::vector task_data(NUM_THREADS); - - void* (*fn_task_wrapper)(void*) = [](void* in) -> void* { - thread_params* par = (thread_params*)in; - par->thread_finished_ = false; - void* retval = par->fn_worker_(in); - par->thread_finished_ = true; - return retval; - }; - - for(uint32_t i = 0; i < NUM_THREADS; i++) - { - // define workloads - task_data[i].thread_id_ = i; - task_data[i].max_threads_ = NUM_THREADS; - task_data[i].nprocessed_ = 0; - task_data[i].shared_ = shared_data; - task_data[i].fn_worker_ = fn_worker; - - // gogogogo - pthread_create( - &threads[i], NULL, fn_task_wrapper, (void*)&task_data[i]); - } - std::cerr << "forked " << NUM_THREADS << " threads \n"; - - std::cerr << "progress: ["; - for(uint32_t i = 0; i < 100; i++) - { - std::cerr << " "; - } - std::cerr << "]\rprogress: ["; - uint32_t pct_done = 0; - while(true) - { - // check progress - uint32_t nprocessed = 0; - uint32_t nfinished = 0; - for(uint32_t i = 0; i < NUM_THREADS; i++) - { - nprocessed += task_data[i].nprocessed_; - nfinished += task_data[i].thread_finished_; - } - - uint32_t pct_progress = (nprocessed * 100) / task_total; - if(pct_progress > pct_done) - { - for(uint32_t i = 0; i < (pct_progress - pct_done); i++) - { - std::cerr << "="; - } - pct_done = pct_progress; - } - - if(nfinished == NUM_THREADS) { break; } - else { sleep(0.5); } - } - std::cerr << "\nparallel compute; end\n"; - return 0; -} - void value_index_swap_array(std::vector& vec) {