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(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 carma_planning_msgs::msg::ManeuverPlan cur_plan = it->first;
47 RCLCPP_DEBUG_STREAM(rclcpp::get_logger(
"arbitrator"),
"START");
49 for (
auto mvr : cur_plan.maneuvers)
51 RCLCPP_DEBUG_STREAM(rclcpp::get_logger(
"arbitrator"),
"Printing cur_plan: mvr: "<< (
int)mvr.type);
54 RCLCPP_DEBUG_STREAM(rclcpp::get_logger(
"arbitrator"),
"PRINT END");
56 auto plan_duration = rclcpp::Duration(0, 0);
59 if (!cur_plan.maneuvers.empty())
66 if (plan_duration > longest_plan_duration)
68 longest_plan_duration = plan_duration;
69 longest_plan = cur_plan;
75 final_open_list.push_back((*it));
76 RCLCPP_DEBUG_STREAM(rclcpp::get_logger(
"arbitrator"),
"Has enough duration, skipping that which has following mvrs..:");
77 for (
auto mvr : it->first.maneuvers)
79 RCLCPP_DEBUG_STREAM(rclcpp::get_logger(
"arbitrator"),
"Printing mvr: "<< (
int)mvr.type);
85 std::vector<carma_planning_msgs::msg::ManeuverPlan> children =
neighbor_generator_->generate_neighbors(cur_plan, start_state);
88 for (
auto child = children.begin(); child != children.end(); child++)
91 if (child->maneuvers.empty())
93 RCLCPP_WARN_STREAM(rclcpp::get_logger(
"arbitrator"),
"Child was empty for id: " << std::string(child->maneuver_plan_id));
97 temp_open_list.push_back(std::make_pair(*child,
cost_function_->compute_cost_per_unit_distance(*child)));
101 open_list_to_evaluate = temp_open_list;
104 if (final_open_list.empty())
106 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...");
107 throw std::runtime_error(
"None of the strategic plugins generated any valid plans! Please check if any is turned and returning valid maneuvers...");
113 for (
auto pair : final_open_list)
116 carma_planning_msgs::msg::ManeuverPlan cur_plan = pair.first;
117 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.
Struct defining the vehicle state required for maneuver planning.