diff --git a/dynoplan b/dynoplan index 936794ee..4193bec1 160000 --- a/dynoplan +++ b/dynoplan @@ -1 +1 @@ -Subproject commit 936794ee18b02e080cc5d445d8c9e80f95ffa9f0 +Subproject commit 4193bec1f4b76f72fa29165727b7d44903992df6 diff --git a/src/db_cbs.cpp b/src/db_cbs.cpp index 0ebcbc50..17a62759 100644 --- a/src/db_cbs.cpp +++ b/src/db_cbs.cpp @@ -182,6 +182,14 @@ int main(int argc, char* argv[]) { options_tdbastar.max_motions = std::min(options_tdbastar.max_motions, 1e6); } // disable/enable motions + // for (auto& iter : robot_motions) { + // for (size_t i = 0; i < problem.robotTypes.size(); ++i) { + // if (iter.first == problem.robotTypes[i]) { + // disable_motions(robots[i], options_tdbastar.delta, filter_duplicates, alpha, options_tdbastar.max_motions, iter.second); + // break; + // } + // } + // } bool solved_db = false; HighLevelNode start; start.solution.resize(env["robots"].size()); @@ -244,11 +252,10 @@ int main(int argc, char* argv[]) { HighLevelNode newNode = P; size_t tmp_robot_id = c.first; newNode.id = id; -#ifdef DBG_PRINTS +// #ifdef DBG_PRINTS std::cout << "Node ID is " << id << std::endl; -#endif +// #endif newNode.constraints[tmp_robot_id].insert(newNode.constraints[tmp_robot_id].end(), c.second.begin(), c.second.end()); - std::cout << "New node constraints size: " << newNode.constraints.size() << std::endl; newNode.cost -= newNode.solution[tmp_robot_id].trajectory.cost; #ifdef DBG_PRINTS std::cout << "New node cost: " << newNode.cost << std::endl; diff --git a/src/dbcbs_utils.hpp b/src/dbcbs_utils.hpp index 31b7715f..e61cb80d 100644 --- a/src/dbcbs_utils.hpp +++ b/src/dbcbs_utils.hpp @@ -139,4 +139,58 @@ void export_solutions(const std::vector>& so } } -} \ No newline at end of file +} + +void disable_motions( + std::shared_ptr& robot, + float delta, + bool filterDuplicates, + float alpha, + size_t num_max_motions, + std::vector& motions) { + ompl::NearestNeighbors *T_m; + // enable all motions + for (size_t i = 0; i < motions.size(); ++i) { + motions[i].disabled = false; + } + if(filterDuplicates){ + size_t num_duplicates = 0; + dynoplan::Motion fakeMotion; + fakeMotion.idx = -1; + fakeMotion.traj.states.push_back(Eigen::VectorXd(robot->nx)); + std::vector neighbors_m; + for (const auto& m : motions) { + if (m.disabled) { + continue; + } + // fakeMotion.traj.states.at(0) = m.states[0]; + fakeMotion.states[0] = m.states[0]; + T_m->nearestR(&fakeMotion, delta*alpha, neighbors_m); + for (dynoplan::Motion* nm : neighbors_m){ + if (nm == &m || nm->disabled) { + continue; + } + float goal_delta = robot->distance(m.traj.states.back(), nm->traj.states.back()); + if (goal_delta < delta*(1-alpha)) { + nm->disabled = true; + ++num_duplicates; + } + } + } + std::cout << "There are " << num_duplicates << " duplicate motions!" << std::endl; + + } + // limit to num_max_motions + size_t num_enabled_motions = 0; + for (size_t i = 0; i < motions.size(); ++i){ + if (!motions[i].disabled) { + if (num_enabled_motions >= num_max_motions) { + motions[i].disabled = true; + } else { + ++num_enabled_motions; + } + } + } + std::cout << "There are " << num_enabled_motions << " motions enabled." << std::endl; + + } \ No newline at end of file