From 8d26209f740f6613569732ce37134a4a02d4a388 Mon Sep 17 00:00:00 2001 From: Ryan Hechenberger Date: Mon, 16 Dec 2024 13:05:50 +1100 Subject: [PATCH 1/5] removed jps direction in id --- include/jps/forward.h | 8 +------- src/jump/offline_jump_point_locator2.cpp | 16 ---------------- src/search/jps2plus_expansion_policy.cpp | 2 +- 3 files changed, 2 insertions(+), 24 deletions(-) diff --git a/include/jps/forward.h b/include/jps/forward.h index b392e1b..0f08cd7 100644 --- a/include/jps/forward.h +++ b/include/jps/forward.h @@ -10,7 +10,7 @@ namespace jps using warthog::pack_id; using warthog::pad_id; -using jps_id = warthog::pad32_id; +using jps_id = pad_id; typedef enum { @@ -26,12 +26,6 @@ typedef enum ALL = 255 } direction; -// we sometimes store the id of a node in the lower 3 bytes of a word and -// use the upper byte to store something else (e.g. the parent direction) -[[deprecated]] -constexpr uint32_t JPS_ID_MASK - = (1 << 24) - 1; - using vec_jps_id = std::vector; using vec_jps_cost = std::vector; diff --git a/src/jump/offline_jump_point_locator2.cpp b/src/jump/offline_jump_point_locator2.cpp index 3d2525a..f3f1c3e 100644 --- a/src/jump/offline_jump_point_locator2.cpp +++ b/src/jump/offline_jump_point_locator2.cpp @@ -205,7 +205,6 @@ offline_jump_point_locator2::jump_northwest( { uint32_t jp_cost = (label_straight1 & 32767); jps_id jp_id = jps_id(jump_from.id - mapw * jp_cost); - *(((uint8_t*)&jp_id) + 3) = NORTH; neighbours.push_back(jp_id); costs.push_back(jp_cost + num_steps * warthog::DBL_ROOT_TWO); } @@ -216,7 +215,6 @@ offline_jump_point_locator2::jump_northwest( { uint32_t jp_cost = (label_straight2 & 32767); jps_id jp_id = jps_id(jump_from.id - jp_cost); - *(((uint8_t*)&jp_id) + 3) = WEST; neighbours.push_back(jp_id); costs.push_back(jp_cost + num_steps * warthog::DBL_ROOT_TWO); } @@ -277,7 +275,6 @@ offline_jump_point_locator2::jump_northeast( { uint32_t jp_cost = (label_straight1 & 32767); jps_id jp_id = jps_id(jump_from.id - mapw * jp_cost); - *(((uint8_t*)&jp_id) + 3) = NORTH; neighbours.push_back(jp_id); costs.push_back(jp_cost + num_steps * warthog::DBL_ROOT_TWO); } @@ -287,7 +284,6 @@ offline_jump_point_locator2::jump_northeast( { uint32_t jp_cost = (label_straight2 & 32767); jps_id jp_id = jps_id(jump_from.id + jp_cost); - *(((uint8_t*)&jp_id) + 3) = EAST; neighbours.push_back(jp_id); costs.push_back(jp_cost + num_steps * warthog::DBL_ROOT_TWO); } @@ -347,7 +343,6 @@ offline_jump_point_locator2::jump_southwest( { uint32_t jp_cost = (label_straight1 & 32767); jps_id jp_id = jps_id(jump_from.id + mapw * jp_cost); - *(((uint8_t*)&jp_id) + 3) = SOUTH; neighbours.push_back(jp_id); costs.push_back(jp_cost + num_steps * warthog::DBL_ROOT_TWO); } @@ -357,7 +352,6 @@ offline_jump_point_locator2::jump_southwest( { uint32_t jp_cost = (label_straight2 & 32767); jps_id jp_id = jps_id(jump_from.id - jp_cost); - *(((uint8_t*)&jp_id) + 3) = WEST; neighbours.push_back(jp_id); costs.push_back(jp_cost + num_steps * warthog::DBL_ROOT_TWO); } @@ -419,7 +413,6 @@ offline_jump_point_locator2::jump_southeast( { uint32_t jp_cost = (label_straight1 & 32767); jps_id jp_id = jps_id(jump_from.id + mapw * jp_cost); - *(((uint8_t*)&jp_id) + 3) = SOUTH; neighbours.push_back(jp_id); costs.push_back(jp_cost + num_steps * warthog::DBL_ROOT_TWO); } @@ -429,7 +422,6 @@ offline_jump_point_locator2::jump_southeast( { uint32_t jp_cost = (label_straight2 & 32767); jps_id jp_id = jps_id(jump_from.id + jp_cost); - *(((uint8_t*)&jp_id) + 3) = EAST; neighbours.push_back(jp_id); costs.push_back(jp_cost + num_steps * warthog::DBL_ROOT_TWO); } @@ -484,7 +476,6 @@ offline_jump_point_locator2::jump_north( uint32_t nx = node_id.id % map_->width(); if(nx == gx) { - *(((uint8_t*)&goal_id) + 3) = NORTH; neighbours.push_back(goal_id); costs.push_back((goal_delta / map_->width()) + cost_to_node_id); return; @@ -495,7 +486,6 @@ offline_jump_point_locator2::jump_north( if(!(label & 32768)) { jps_id jp_id = jps_id(node_id.id - id_delta); - *(((uint8_t*)&jp_id) + 3) = NORTH; neighbours.push_back(jp_id); costs.push_back(num_steps + cost_to_node_id); } @@ -518,7 +508,6 @@ offline_jump_point_locator2::jump_south( uint32_t nx = node_id.id % map_->width(); if(nx == gx) { - *(((uint8_t*)&goal_id) + 3) = SOUTH; neighbours.push_back(goal_id); costs.push_back((goal_delta / map_->width()) + cost_to_node_id); return; @@ -529,7 +518,6 @@ offline_jump_point_locator2::jump_south( if(!(label & 32768)) { jps_id jp_id = jps_id(node_id.id + id_delta); - *(((uint8_t*)&jp_id) + 3) = SOUTH; neighbours.push_back(jp_id); costs.push_back(num_steps + cost_to_node_id); } @@ -547,7 +535,6 @@ offline_jump_point_locator2::jump_east( uint32_t goal_delta = goal_id.id - node_id.id; if(num_steps >= goal_delta) { - *(((uint8_t*)&goal_id) + 3) = EAST; neighbours.push_back(goal_id); costs.push_back(goal_delta + cost_to_node_id); return; @@ -557,7 +544,6 @@ offline_jump_point_locator2::jump_east( if(!(label & 32768)) { jps_id jp_id = jps_id(node_id.id + num_steps); - *(((uint8_t*)&jp_id) + 3) = EAST; neighbours.push_back(jp_id); costs.push_back(num_steps + cost_to_node_id); } @@ -575,7 +561,6 @@ offline_jump_point_locator2::jump_west( uint32_t goal_delta = node_id.id - goal_id.id; if(num_steps >= goal_delta) { - *(((uint8_t*)&goal_id) + 3) = WEST; neighbours.push_back(goal_id); costs.push_back(goal_delta + cost_to_node_id); return; @@ -585,7 +570,6 @@ offline_jump_point_locator2::jump_west( if(!(label & 32768)) { jps_id jp_id = jps_id(node_id.id - num_steps); - *(((uint8_t*)&jp_id) + 3) = WEST; neighbours.push_back(jp_id); costs.push_back(num_steps + cost_to_node_id); } diff --git a/src/search/jps2plus_expansion_policy.cpp b/src/search/jps2plus_expansion_policy.cpp index 995ef9a..2e5767e 100644 --- a/src/search/jps2plus_expansion_policy.cpp +++ b/src/search/jps2plus_expansion_policy.cpp @@ -60,7 +60,7 @@ jps2plus_expansion_policy::expand( jps_id jp_id = jp_ids_.at(i); // TODO: FIX jps node id warthog::search::search_node* mynode - = generate(jps_id(jp_id.id & jps::JPS_ID_MASK)); + = generate(jps_id(jp_id.id)); add_neighbour(mynode, costs_.at(i)); } } From 398580d3789ef149d1f2da9ea5a6f133a6067f48 Mon Sep 17 00:00:00 2001 From: Ryan Hechenberger Date: Wed, 18 Dec 2024 13:03:04 +1100 Subject: [PATCH 2/5] update gridmap to new core utility functions --- include/jps/jump/online_jump_point_locator.h | 4 ++-- include/jps/jump/online_jump_point_locator2.h | 4 ++-- src/jump/offline_jump_point_locator.cpp | 2 +- src/jump/offline_jump_point_locator2.cpp | 2 +- src/jump/online_jump_point_locator.cpp | 4 ++-- src/jump/online_jump_point_locator2.cpp | 4 ++-- src/search/jps.cpp | 2 +- 7 files changed, 11 insertions(+), 11 deletions(-) diff --git a/include/jps/jump/online_jump_point_locator.h b/include/jps/jump/online_jump_point_locator.h index b2bdace..85fde3f 100644 --- a/include/jps/jump/online_jump_point_locator.h +++ b/include/jps/jump/online_jump_point_locator.h @@ -101,7 +101,7 @@ class online_jump_point_locator map_->to_unpadded_xy(mapid, x, y); ry = x; rx = map_->header_height() - y - 1; - return jps_id(rmap_->to_padded_id(rx, ry)); + return jps_id(rmap_->to_padded_id_from_unpadded(rx, ry)); } inline jps_id @@ -114,7 +114,7 @@ class online_jump_point_locator rmap_->to_unpadded_xy(rmapid, rx, ry); x = ry; y = rmap_->header_width() - rx - 1; - return jps_id(map_->to_padded_id(x, y)); + return jps_id(map_->to_padded_id_from_unpadded(x, y)); } warthog::domain::gridmap* diff --git a/include/jps/jump/online_jump_point_locator2.h b/include/jps/jump/online_jump_point_locator2.h index 0e6739f..ed2aff2 100644 --- a/include/jps/jump/online_jump_point_locator2.h +++ b/include/jps/jump/online_jump_point_locator2.h @@ -111,7 +111,7 @@ class online_jump_point_locator2 map_->to_unpadded_xy(mapid, x, y); ry = x; rx = map_->header_height() - y - 1; - return jps_id(rmap_->to_padded_id(rx, ry)); + return jps_id(rmap_->to_padded_id_from_unpadded(rx, ry)); } // convert rmap indexes to map indexes @@ -125,7 +125,7 @@ class online_jump_point_locator2 rmap_->to_unpadded_xy(rmapid, rx, ry); x = ry; y = rmap_->header_width() - rx - 1; - return jps_id(map_->to_padded_id(x, y)); + return jps_id(map_->to_padded_id_from_unpadded(x, y)); } warthog::domain::gridmap* diff --git a/src/jump/offline_jump_point_locator.cpp b/src/jump/offline_jump_point_locator.cpp index e03a884..a3b372b 100644 --- a/src/jump/offline_jump_point_locator.cpp +++ b/src/jump/offline_jump_point_locator.cpp @@ -36,7 +36,7 @@ offline_jump_point_locator::preproc() { for(uint32_t x = 0; x < map_->header_width(); x++) { - jps_id mapid = jps_id{map_->to_padded_id(x, y)}; + jps_id mapid = jps_id{map_->to_padded_id_from_unpadded(x, y)}; // std::cout << mapid << " "; for(uint32_t i = 0; i < 8; i++) { diff --git a/src/jump/offline_jump_point_locator2.cpp b/src/jump/offline_jump_point_locator2.cpp index f3f1c3e..f96b372 100644 --- a/src/jump/offline_jump_point_locator2.cpp +++ b/src/jump/offline_jump_point_locator2.cpp @@ -47,7 +47,7 @@ offline_jump_point_locator2::preproc() { for(uint32_t x = 0; x < map_->header_width(); x++) { - jps_id mapid = jps_id{map_->to_padded_id(x, y)}; + jps_id mapid = jps_id{map_->to_padded_id_from_unpadded(x, y)}; // std::cout << mapid << " "; for(uint32_t i = 0; i < 8; i++) { diff --git a/src/jump/online_jump_point_locator.cpp b/src/jump/online_jump_point_locator.cpp index 4951f65..ba2165e 100644 --- a/src/jump/online_jump_point_locator.cpp +++ b/src/jump/online_jump_point_locator.cpp @@ -36,10 +36,10 @@ online_jump_point_locator::create_rmap() { for(uint32_t y = 0; y < maph; y++) { - uint32_t label = map_->get_label(map_->to_padded_id(x, y)); + uint32_t label = map_->get_label(map_->to_padded_id_from_unpadded(x, y)); uint32_t rx = ((rmapw - 1) - y); uint32_t ry = x; - rmap->set_label(rmap->to_padded_id(rx, ry), label); + rmap->set_label(rmap->to_padded_id_from_unpadded(rx, ry), label); } } return rmap; diff --git a/src/jump/online_jump_point_locator2.cpp b/src/jump/online_jump_point_locator2.cpp index f7563c0..c36c393 100644 --- a/src/jump/online_jump_point_locator2.cpp +++ b/src/jump/online_jump_point_locator2.cpp @@ -38,10 +38,10 @@ online_jump_point_locator2::create_rmap() { for(uint32_t y = 0; y < maph; y++) { - uint32_t label = map_->get_label(map_->to_padded_id(x, y)); + uint32_t label = map_->get_label(map_->to_padded_id_from_unpadded(x, y)); uint32_t rx = ((rmapw - 1) - y); uint32_t ry = x; - rmap->set_label(rmap->to_padded_id(rx, ry), label); + rmap->set_label(rmap->to_padded_id_from_unpadded(rx, ry), label); } } return rmap; diff --git a/src/search/jps.cpp b/src/search/jps.cpp index 6948dd4..ea16e2f 100644 --- a/src/search/jps.cpp +++ b/src/search/jps.cpp @@ -255,7 +255,7 @@ create_corner_map(warthog::domain::gridmap* gm) { for(uint32_t x = 0; x < mapwidth; x++) { - jps_id from_id = jps_id(gm->to_padded_id(x, y)); + jps_id from_id = jps_id(gm->to_padded_id_from_unpadded(x, y)); if(!gm->get_label(from_id)) { continue; } jps_id w_id = jps_id(from_id.id - 1); From cfd86da8f530e3a0646aca17f0263156472b24bc Mon Sep 17 00:00:00 2001 From: Ryan Hechenberger Date: Wed, 18 Dec 2024 13:07:16 +1100 Subject: [PATCH 3/5] update jps to newer core version --- extern/warthog-core | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/extern/warthog-core b/extern/warthog-core index 6586def..e0d951c 160000 --- a/extern/warthog-core +++ b/extern/warthog-core @@ -1 +1 @@ -Subproject commit 6586def3f6b205dab1e396505a9f3012c99e874d +Subproject commit e0d951c09ed23e92989b8fa8b30b49d5f66604de From 34ddcb176dd8a2f9a5a8f4afbca8b2c7389af743 Mon Sep 17 00:00:00 2001 From: Ryan Hechenberger Date: Wed, 18 Dec 2024 13:59:30 +1100 Subject: [PATCH 4/5] update jps app with utility id --- apps/jps.cpp | 30 +++++++++++++++++++++--------- extern/warthog-core | 2 +- 2 files changed, 22 insertions(+), 10 deletions(-) diff --git a/apps/jps.cpp b/apps/jps.cpp index ffe61d2..9d222b1 100644 --- a/apps/jps.cpp +++ b/apps/jps.cpp @@ -111,21 +111,23 @@ check_optimality( } template -void +int run_experiments( Search& algo, std::string alg_name, warthog::util::scenario_manager& scenmgr, bool verbose, bool checkopt, std::ostream& out) { - std::cout << "id\talg\texpanded\tgenerated\treopen\tsurplus\theapops" - << "\tnanos\tplen\tpcost\tscost\tmap\n"; + auto* expander = algo.get_expander(); + if (expander == nullptr) + return 1; + out << "id\talg\texpanded\tgenerated\treopen\tsurplus\theapops" + << "\tnanos\tplen\tpcost\tscost\tmap\n"; for(unsigned int i = 0; i < scenmgr.num_experiments(); i++) { warthog::util::experiment* exp = scenmgr.get_experiment(i); - warthog::pack_id startid{ - exp->starty() * exp->mapwidth() + exp->startx()}; - warthog::pack_id goalid{exp->goaly() * exp->mapwidth() + exp->goalx()}; + warthog::pack_id startid = expander->get_pack(exp->startx(), exp->starty()); + warthog::pack_id goalid = expander->get_pack(exp->goalx(), exp->goaly()); warthog::search::problem_instance pi(startid, goalid, verbose); warthog::search::search_parameters par; warthog::search::solution sol; @@ -141,12 +143,17 @@ run_experiments( << exp->distance() << "\t" << scenmgr.last_file_loaded() << std::endl; - if(checkopt) { check_optimality(sol, exp); } + if(checkopt) { + if (!check_optimality(sol, exp)) + return 4; + } } + + return 0; } template -void +int run_jps( warthog::util::scenario_manager& scenmgr, std::string mapname, std::string alg_name) @@ -158,8 +165,13 @@ run_jps( warthog::search::unidirectional_search jps(&heuristic, &expander, &open); - run_experiments(jps, alg_name, scenmgr, verbose, checkopt, std::cout); + int ret = run_experiments(jps, alg_name, scenmgr, verbose, checkopt, std::cout); + if (ret != 0) { + std::cerr << "run_experiments error code " << ret << std::endl; + return ret; + } std::cerr << "done. total memory: " << jps.mem() + scenmgr.mem() << "\n"; + return 0; } } // namespace diff --git a/extern/warthog-core b/extern/warthog-core index e0d951c..3574fb1 160000 --- a/extern/warthog-core +++ b/extern/warthog-core @@ -1 +1 @@ -Subproject commit e0d951c09ed23e92989b8fa8b30b49d5f66604de +Subproject commit 3574fb1cf7bab2ae3a9b5b322bd66bd1fed84cc4 From dcaa193c62b6f0b1c5cc1cdb77563a7e3913bdae Mon Sep 17 00:00:00 2001 From: "github-actions[bot]" <41898282+github-actions[bot]@users.noreply.github.com> Date: Fri, 10 Jan 2025 04:20:05 +0000 Subject: [PATCH 5/5] auto clang-format action --- apps/jps.cpp | 21 ++++++++++++--------- src/jump/online_jump_point_locator.cpp | 3 ++- src/jump/online_jump_point_locator2.cpp | 3 ++- 3 files changed, 16 insertions(+), 11 deletions(-) diff --git a/apps/jps.cpp b/apps/jps.cpp index 9d222b1..09da234 100644 --- a/apps/jps.cpp +++ b/apps/jps.cpp @@ -118,16 +118,17 @@ run_experiments( std::ostream& out) { auto* expander = algo.get_expander(); - if (expander == nullptr) - return 1; + if(expander == nullptr) return 1; out << "id\talg\texpanded\tgenerated\treopen\tsurplus\theapops" << "\tnanos\tplen\tpcost\tscost\tmap\n"; for(unsigned int i = 0; i < scenmgr.num_experiments(); i++) { warthog::util::experiment* exp = scenmgr.get_experiment(i); - warthog::pack_id startid = expander->get_pack(exp->startx(), exp->starty()); - warthog::pack_id goalid = expander->get_pack(exp->goalx(), exp->goaly()); + warthog::pack_id startid + = expander->get_pack(exp->startx(), exp->starty()); + warthog::pack_id goalid + = expander->get_pack(exp->goalx(), exp->goaly()); warthog::search::problem_instance pi(startid, goalid, verbose); warthog::search::search_parameters par; warthog::search::solution sol; @@ -143,9 +144,9 @@ run_experiments( << exp->distance() << "\t" << scenmgr.last_file_loaded() << std::endl; - if(checkopt) { - if (!check_optimality(sol, exp)) - return 4; + if(checkopt) + { + if(!check_optimality(sol, exp)) return 4; } } @@ -165,8 +166,10 @@ run_jps( warthog::search::unidirectional_search jps(&heuristic, &expander, &open); - int ret = run_experiments(jps, alg_name, scenmgr, verbose, checkopt, std::cout); - if (ret != 0) { + int ret = run_experiments( + jps, alg_name, scenmgr, verbose, checkopt, std::cout); + if(ret != 0) + { std::cerr << "run_experiments error code " << ret << std::endl; return ret; } diff --git a/src/jump/online_jump_point_locator.cpp b/src/jump/online_jump_point_locator.cpp index ba2165e..a6a7d82 100644 --- a/src/jump/online_jump_point_locator.cpp +++ b/src/jump/online_jump_point_locator.cpp @@ -36,7 +36,8 @@ online_jump_point_locator::create_rmap() { for(uint32_t y = 0; y < maph; y++) { - uint32_t label = map_->get_label(map_->to_padded_id_from_unpadded(x, y)); + uint32_t label + = map_->get_label(map_->to_padded_id_from_unpadded(x, y)); uint32_t rx = ((rmapw - 1) - y); uint32_t ry = x; rmap->set_label(rmap->to_padded_id_from_unpadded(rx, ry), label); diff --git a/src/jump/online_jump_point_locator2.cpp b/src/jump/online_jump_point_locator2.cpp index c36c393..830a4f4 100644 --- a/src/jump/online_jump_point_locator2.cpp +++ b/src/jump/online_jump_point_locator2.cpp @@ -38,7 +38,8 @@ online_jump_point_locator2::create_rmap() { for(uint32_t y = 0; y < maph; y++) { - uint32_t label = map_->get_label(map_->to_padded_id_from_unpadded(x, y)); + uint32_t label + = map_->get_label(map_->to_padded_id_from_unpadded(x, y)); uint32_t rx = ((rmapw - 1) - y); uint32_t ry = x; rmap->set_label(rmap->to_padded_id_from_unpadded(rx, ry), label);