27 carma_planning_msgs::msg::ManeuverPlan
root;
28 std::vector<std::pair<carma_planning_msgs::msg::ManeuverPlan, double>> open_list_to_evaluate;
29 std::vector<std::pair<carma_planning_msgs::msg::ManeuverPlan, double>> final_open_list;
31 const double INF = std::numeric_limits<double>::infinity();
32 open_list_to_evaluate.push_back(std::make_pair(
root, INF));
34 carma_planning_msgs::msg::ManeuverPlan longest_plan =
root;
35 rclcpp::Duration longest_plan_duration = rclcpp::Duration::from_nanoseconds(0);
38 while (!open_list_to_evaluate.empty())
40 std::vector<std::pair<carma_planning_msgs::msg::ManeuverPlan, double>> temp_open_list;
42 for (
auto it = open_list_to_evaluate.begin(); it != open_list_to_evaluate.end(); it++)
45 auto& cur_plan = it->first;
47 if (cur_plan.maneuver_plan_id ==
"")
50 cur_plan.maneuver_plan_id =
54 RCLCPP_DEBUG_STREAM(rclcpp::get_logger(
"arbitrator"),
55 "Start printing newly requested maneuver plan for debugging:");
57 for (
auto mvr : cur_plan.maneuvers)
59 RCLCPP_DEBUG_STREAM(rclcpp::get_logger(
"arbitrator"),
63 RCLCPP_DEBUG_STREAM(rclcpp::get_logger(
"arbitrator"),
64 "Ended printing newly requested maneuver plan for debugging");
66 auto plan_duration = rclcpp::Duration(0, 0);
69 if (!cur_plan.maneuvers.empty())
76 if (plan_duration > longest_plan_duration)
78 longest_plan_duration = plan_duration;
79 longest_plan = cur_plan;
85 final_open_list.push_back((*it));
86 RCLCPP_DEBUG_STREAM(rclcpp::get_logger(
"arbitrator"),
"Has enough duration, skipping that which has following mvrs..:");
87 for (
auto mvr : it->first.maneuvers)
89 RCLCPP_DEBUG_STREAM(rclcpp::get_logger(
"arbitrator"),
96 std::vector<carma_planning_msgs::msg::ManeuverPlan> children =
neighbor_generator_->generate_neighbors(cur_plan, start_state);
98 rclcpp::get_logger(
"arbitrator"),
99 "Arbitrator received total of " << children.size()
100 <<
" response from strategic_plugins for plan_id: "
101 << std::string(cur_plan.maneuver_plan_id)
104 for (
auto child = children.begin(); child != children.end(); child++)
106 if (child->maneuvers.empty())
109 rclcpp::get_logger(
"arbitrator"),
110 "Arbitrator didn't get successful maneuver plan for plan_id: "
111 << std::string(cur_plan.maneuver_plan_id)
112 <<
", from one of the strategic plugin, which so far had maneuvers: "
114 for (
auto mvr : cur_plan.maneuvers)
117 rclcpp::get_logger(
"arbitrator"),
124 temp_open_list.push_back(std::make_pair(*child,
cost_function_->compute_cost_per_unit_distance(*child)));
128 open_list_to_evaluate = temp_open_list;
131 if (final_open_list.empty())
133 RCLCPP_ERROR_STREAM(rclcpp::get_logger(
"arbitrator"),
"None of the strategic plugins generated any valid plans! Please check if any is turned and returning valid maneuvers...");
134 throw std::runtime_error(
"None of the strategic plugins generated any valid plans! Please check if any is turned and returning valid maneuvers...");
140 for (
auto pair : final_open_list)
143 carma_planning_msgs::msg::ManeuverPlan cur_plan = pair.first;
144 rclcpp::Duration plan_duration(0,0);
rclcpp::Duration target_plan_duration_
carma_planning_msgs::msg::ManeuverPlan generate_plan(const VehicleState &start_state)
Utilize the configured cost function, neighbor generator, and search strategy, to generate a plan by ...
std::shared_ptr< SearchStrategy > search_strategy_
std::shared_ptr< NeighborGenerator > neighbor_generator_
std::shared_ptr< CostFunction > cost_function_
rclcpp::Time get_plan_start_time(const carma_planning_msgs::msg::ManeuverPlan &)
Get the start time of the first maneuver in the plan.
rclcpp::Time get_plan_end_time(const carma_planning_msgs::msg::ManeuverPlan &)
Get the end time of the first maneuver in the plan.
std::string maneuver_type_to_string(uint8_t type)
Convert maneuver type enum to string representation.
auto to_string(const UtmZone &zone) -> std::string
Struct defining the vehicle state required for maneuver planning.