Skip to content

Commit

Permalink
Feature/gridmap utility apply (#7)
Browse files Browse the repository at this point in the history
* update gridmap to new core utility functions
  • Loading branch information
heavenfall authored Jan 10, 2025
1 parent a8391e6 commit ab83dfc
Show file tree
Hide file tree
Showing 9 changed files with 38 additions and 21 deletions.
33 changes: 24 additions & 9 deletions apps/jps.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -111,21 +111,24 @@ check_optimality(
}

template<typename Search>
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;
Expand All @@ -141,12 +144,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<typename ExpansionPolicy>
void
int
run_jps(
warthog::util::scenario_manager& scenmgr, std::string mapname,
std::string alg_name)
Expand All @@ -158,8 +166,15 @@ 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
Expand Down
4 changes: 2 additions & 2 deletions include/jps/jump/online_jump_point_locator.h
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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*
Expand Down
4 changes: 2 additions & 2 deletions include/jps/jump/online_jump_point_locator2.h
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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*
Expand Down
2 changes: 1 addition & 1 deletion src/jump/offline_jump_point_locator.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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++)
{
Expand Down
2 changes: 1 addition & 1 deletion src/jump/offline_jump_point_locator2.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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++)
{
Expand Down
5 changes: 3 additions & 2 deletions src/jump/online_jump_point_locator.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -36,10 +36,11 @@ 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;
Expand Down
5 changes: 3 additions & 2 deletions src/jump/online_jump_point_locator2.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -38,10 +38,11 @@ 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;
Expand Down
2 changes: 1 addition & 1 deletion src/search/jps.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down

0 comments on commit ab83dfc

Please sign in to comment.