|
| 1 | +/* |
| 2 | +Copyright 2026 Mert Güler |
| 3 | +
|
| 4 | +Licensed under the Apache License, Version 2.0 (the "License"); |
| 5 | +you may not use this file except in compliance with the License. |
| 6 | +You may obtain a copy of the License at |
| 7 | +
|
| 8 | + http://www.apache.org/licenses/LICENSE-2.0 |
| 9 | +
|
| 10 | +Unless required by applicable law or agreed to in writing, software |
| 11 | +distributed under the License is distributed on an "AS IS" BASIS, |
| 12 | +WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. |
| 13 | +See the License for the specific language governing permissions and |
| 14 | +limitations under the License. |
| 15 | +*/ |
| 16 | + |
| 17 | +#pragma once |
| 18 | + |
| 19 | +#include <cstddef> |
| 20 | +#include <vector> |
| 21 | + |
| 22 | +#include "frontier_exploration_ros2/frontier_types.hpp" |
| 23 | +#include "frontier_exploration_ros2/mrtsp_ordering.hpp" |
| 24 | + |
| 25 | +namespace frontier_exploration_ros2 |
| 26 | +{ |
| 27 | + |
| 28 | +constexpr std::size_t kMaxDpSolverCandidateLimit{60U}; |
| 29 | + |
| 30 | +struct MrtspSolverConfig |
| 31 | +{ |
| 32 | + // Upper bound for the candidate pool passed to the bounded solver. |
| 33 | + std::size_t candidate_limit{15}; |
| 34 | + // Number of distinct frontier visits evaluated in each receding-horizon plan. |
| 35 | + std::size_t planning_horizon{10}; |
| 36 | +}; |
| 37 | + |
| 38 | +struct MrtspPrunedCandidate |
| 39 | +{ |
| 40 | + // Index in the frontier vector received from the core. The DP solver works on the |
| 41 | + // pruned vector, then callers use this field to map the result back to dispatch data. |
| 42 | + std::size_t original_index{}; |
| 43 | + FrontierCandidate candidate{}; |
| 44 | + // MRTSP start-row cost used for deterministic top-N candidate pruning. |
| 45 | + double score{0.0}; |
| 46 | +}; |
| 47 | + |
| 48 | +// Scores candidates with the same robot-to-frontier cost used by the MRTSP matrix, |
| 49 | +// sorts them deterministically, and returns the best bounded candidate pool. |
| 50 | +std::vector<MrtspPrunedCandidate> prune_mrtsp_candidates( |
| 51 | + const std::vector<FrontierCandidate> & candidates, |
| 52 | + const RobotState & robot_state, |
| 53 | + const CostWeights & weights, |
| 54 | + double sensor_effective_range_m, |
| 55 | + double max_linear_speed_vmax, |
| 56 | + double max_angular_speed_wmax, |
| 57 | + const MrtspSolverConfig & config); |
| 58 | + |
| 59 | +// Searches the lowest-cost K-frontier sequence in the given matrix. |
| 60 | +// Matrix node 0 is the robot start node, and nodes 1..M are pruned frontiers. |
| 61 | +// Returned indices are relative to the pruned candidate list. |
| 62 | +std::vector<std::size_t> solve_bounded_horizon_mrtsp_order( |
| 63 | + const MrtspCostMatrix & cost_matrix, |
| 64 | + std::size_t planning_horizon); |
| 65 | + |
| 66 | +} // namespace frontier_exploration_ros2 |
0 commit comments