Carma-platform v4.2.0
CARMA Platform is built on robot operating system (ROS) and utilizes open source software (OSS) that enables Cooperative Driving Automation (CDA) features to allow Automated Driving Systems to interact and cooperate with infrastructure and other vehicles through communication.
arbitrator::FixedPriorityCostFunction Class Reference

Implementation of the CostFunction interface. More...

#include <fixed_priority_cost_function.hpp>

Inheritance diagram for arbitrator::FixedPriorityCostFunction:
Inheritance graph
Collaboration diagram for arbitrator::FixedPriorityCostFunction:
Collaboration graph

Public Member Functions

 FixedPriorityCostFunction (const std::map< std::string, double > &plugin_priorities)
 Constructor for FixedPriorityCostFunction. More...
 
double compute_total_cost (const carma_planning_msgs::msg::ManeuverPlan &plan)
 Compute the unit cost over distance of a given maneuver plan. More...
 
double compute_cost_per_unit_distance (const carma_planning_msgs::msg::ManeuverPlan &plan)
 Compute the unit cost over distance of a given maneuver plan. More...
 
- Public Member Functions inherited from arbitrator::CostFunction
virtual double compute_total_cost (const carma_planning_msgs::msg::ManeuverPlan &plan)=0
 Compute the cost of a given maneuver plan. More...
 
virtual double compute_cost_per_unit_distance (const carma_planning_msgs::msg::ManeuverPlan &plan)=0
 Compute the unit cost over distance of a given maneuver plan. More...
 
virtual ~CostFunction ()
 Virtual destructor provided for memory safety. More...
 

Private Attributes

std::map< std::string, double > plugin_costs_
 

Detailed Description

Implementation of the CostFunction interface.

Implements costs by associating a fixed priority number with each plugin (as specified by configuration). This priority is then normalized across all plugins, and then an inverse is computed to arrive at the cost per unit distance for that plugins.

e.g. Three plugins with priority 20, 10, and 5 will respectively have costs 0, 0.5, 0.75 per unit distance.

Definition at line 37 of file fixed_priority_cost_function.hpp.

Constructor & Destructor Documentation

◆ FixedPriorityCostFunction()

arbitrator::FixedPriorityCostFunction::FixedPriorityCostFunction ( const std::map< std::string, double > &  plugin_priorities)

Constructor for FixedPriorityCostFunction.

Parameters
plugin_prioritieswith plugin_name, priority_value mappings

Definition at line 25 of file fixed_priority_cost_function.cpp.

26 {
27 // Identify the highest priority values present in the list
28 double max_priority = std::numeric_limits<double>::lowest();
29 for (auto it = plugin_priorities.begin(); it != plugin_priorities.end(); it++)
30 {
31 if (it->second > max_priority)
32 {
33 max_priority = it->second;
34 }
35 }
36
37 // Normalize the list and invert into costs
38 for (auto it = plugin_priorities.begin(); it != plugin_priorities.end(); it++)
39 {
40 plugin_costs_[it->first] = 1.0 - (it->second / max_priority);
41 RCLCPP_INFO_STREAM(rclcpp::get_logger("arbitrator"), "FixedPriorityCostFunction: " << "Plugin: " << it->first << " Normalized Cost: " << plugin_costs_[it->first]);
42 }
43 }

References plugin_costs_.

Member Function Documentation

◆ compute_cost_per_unit_distance()

double arbitrator::FixedPriorityCostFunction::compute_cost_per_unit_distance ( const carma_planning_msgs::msg::ManeuverPlan &  plan)
virtual

Compute the unit cost over distance of a given maneuver plan.

Parameters
planThe plan to evaluate
Returns
double The total cost divided by the total distance of the plan

Implements arbitrator::CostFunction.

Definition at line 58 of file fixed_priority_cost_function.cpp.

59 {
61 return compute_total_cost(plan) / plan_dist;
62 }
double compute_total_cost(const carma_planning_msgs::msg::ManeuverPlan &plan)
Compute the unit cost over distance of a given maneuver plan.
double get_plan_end_distance(const carma_planning_msgs::msg::ManeuverPlan &)
Get the end distance of the first maneuver in the plan.
double get_plan_start_distance(const carma_planning_msgs::msg::ManeuverPlan &)
Get the start distance of the first maneuver in the plan.

References compute_total_cost(), arbitrator_utils::get_plan_end_distance(), and arbitrator_utils::get_plan_start_distance().

Here is the call graph for this function:

◆ compute_total_cost()

double arbitrator::FixedPriorityCostFunction::compute_total_cost ( const carma_planning_msgs::msg::ManeuverPlan &  plan)
virtual

Compute the unit cost over distance of a given maneuver plan.

Parameters
planThe plan to evaluate
Returns
double The total cost divided by the total distance of the plan

Implements arbitrator::CostFunction.

Definition at line 45 of file fixed_priority_cost_function.cpp.

46 {
47 double total_cost = 0.0;
48 for (auto it = plan.maneuvers.begin(); it != plan.maneuvers.end(); it++)
49 {
50 std::string planning_plugin = GET_MANEUVER_PROPERTY(*it, parameters).planning_strategic_plugin;
52 plugin_costs_.at(planning_plugin);
53 }
54
55 return total_cost;
56 }
#define GET_MANEUVER_PROPERTY(mvr, property)
Macro definition to enable easier access to fields shared across the maneuver types.
double get_maneuver_start_distance(const carma_planning_msgs::msg::Maneuver &)
Get the start distance the specified maneuver.
double get_maneuver_end_distance(const carma_planning_msgs::msg::Maneuver &)
Get the end distance of the specified maneuver.

References arbitrator_utils::get_maneuver_end_distance(), GET_MANEUVER_PROPERTY, arbitrator_utils::get_maneuver_start_distance(), and plugin_costs_.

Referenced by compute_cost_per_unit_distance().

Here is the call graph for this function:
Here is the caller graph for this function:

Member Data Documentation

◆ plugin_costs_

std::map<std::string, double> arbitrator::FixedPriorityCostFunction::plugin_costs_
private

The documentation for this class was generated from the following files: