Module costs

evaluation

class commonocean_dc.costs.evaluation.PartialCostFunction(value)[source]

See our cost functions for more details.

A: Acceleration, J: Jerk, Jlat: Lateral Jerk, Jlon: Longitudinal Jerk, RA: Rudder Angle, RR: Rudder Rate, Y: Yaw Rate, V: Velocity Offset, Vlon: Longitudinal Velocity Offset, O: Orientation Offset, D: Distance to Obstacles, T: Time, ID: Inverse Duration, R: Rule compliance

A = 'A'
J = 'J'
Jlat = 'Jlat'
Jlon = 'Jlon'
RA = 'RA'
RR = 'RR'
Y = 'Y'
V = 'V'
Vlon = 'Vlon'
O = 'O'
D = 'D'
T = 'T'
ID = 'ID'
VCRO = 'VCRO'
R = 'R'
class commonocean_dc.costs.evaluation.CostFunctionEvaluator(cost_function_id: CostFunction, vessel_type: VesselType)[source]
classmethod init_from_solution(solution: Solution)[source]
property required_properties
evaluate_pp_solution(cr_scenario: Scenario, cr_pproblem: PlanningProblem, trajectory: Trajectory, draw_waters_path=False, debug_plot=False)[source]

Computes costs of one solution for cr_pproblem.

Parameters:
  • cr_scenario – scenario

  • cr_pproblem – planning problem that is solved by trajectory

  • trajectory – solution trajectory

  • draw_waters_path – optionally visualize the detected waters path with respect to whose some parameters for the cost computation are determined (only useful for development).

  • debug_plot – show plot in case a trajectory cannot be transformed to curvilinear coordinates.

Returns:

result of evaluation

evaluate_solution(scenario: Scenario, cr_pproblems: PlanningProblemSet, solution: Solution) SolutionResult[source]

Computes costs for all solutions of a planning problem set.

Parameters:
  • scenario – scenario that was solved

  • cr_pproblems – planning problem set that was solved

  • solution – Solution object that contains trajectories

Returns:

SolutionResult object that contains partial and total costs

class commonocean_dc.costs.evaluation.PlanningProblemCostResult(cost_function_id: CostFunction, solution_id: int)[source]
property total_costs: float
add_partial_costs(pcf: PartialCostFunction, cost: float, weight)[source]
class commonocean_dc.costs.evaluation.SolutionResult(benchmark_id: str, pp_results: List[PlanningProblemCostResult] = ())[source]
add_results(pp_result: PlanningProblemCostResult)[source]

partial_cost_functions

exception commonocean_dc.costs.partial_cost_functions.PartialCostFunctionException[source]
commonocean_dc.costs.partial_cost_functions.euclidean_dist(x1: array, x2: array) float[source]

Returns the euclidean distance between two points.

commonocean_dc.costs.partial_cost_functions.position_waters(scenario: Scenario, position: ndarray) List[Waterway][source]

Returns the list of waters that contains the given position

commonocean_dc.costs.partial_cost_functions.acceleration_cost(scenario: Scenario, planning_problem: PlanningProblem, trajectory: Trajectory, properties: Dict[SolutionProperties, Dict[int, Any]]) float[source]

Calculates the acceleration cost for the given trajectory.

commonocean_dc.costs.partial_cost_functions.jerk_cost(scenario: Scenario, planning_problem: PlanningProblem, trajectory: Trajectory, properties: Dict[SolutionProperties, Dict[int, Any]]) float[source]

Calculates the jerk cost for the given trajectory.

commonocean_dc.costs.partial_cost_functions.jerk_lat_cost(scenario: Scenario, planning_problem: PlanningProblem, trajectory: Trajectory, properties: Dict[SolutionProperties, Dict[int, Any]]) float[source]

Calculates the lateral jerk cost for the given trajectory.

commonocean_dc.costs.partial_cost_functions.jerk_lon_cost(scenario: Scenario, planning_problem: PlanningProblem, trajectory: Trajectory, properties: Dict[SolutionProperties, Dict[int, Any]]) float[source]

Calculates the longitudinal jerk cost for the given trajectory.

commonocean_dc.costs.partial_cost_functions.rudder_angle_cost(scenario: Scenario, planning_problem: PlanningProblem, trajectory: Trajectory, properties: Dict[SolutionProperties, Dict[int, Any]]) float[source]

Calculates the rudder angle cost for the given trajectory.

commonocean_dc.costs.partial_cost_functions.rudder_rate_cost(scenario: Scenario, planning_problem: PlanningProblem, trajectory: Trajectory, properties: Dict[SolutionProperties, Dict[int, Any]]) float[source]

Calculates the rudder rate cost for the given trajectory.

commonocean_dc.costs.partial_cost_functions.yaw_cost(scenario: Scenario, planning_problem: PlanningProblem, trajectory: Trajectory, properties: Dict[SolutionProperties, Dict[int, Any]]) float[source]

Calculates the yaw cost for the given trajectory.

commonocean_dc.costs.partial_cost_functions.path_length_cost(scenario: Scenario, planning_problem: PlanningProblem, trajectory: Trajectory, properties: Dict[SolutionProperties, Dict[int, Any]]) float[source]

Calculates the path length cost for the given trajectory.

commonocean_dc.costs.partial_cost_functions.time_cost(scenario: Scenario, planning_problem: PlanningProblem, trajectory: Trajectory, properties: Dict[SolutionProperties, Dict[int, Any]]) float[source]

Calculates the time cost for the given trajectory.

commonocean_dc.costs.partial_cost_functions.inverse_duration_cost(scenario: Scenario, planning_problem: PlanningProblem, trajectory: Trajectory, properties: Dict[SolutionProperties, Dict[int, Any]]) float[source]

Calculates the inverse time cost for the given trajectory.

commonocean_dc.costs.partial_cost_functions.orientation_offset_cost(scenario: Scenario, planning_problem: PlanningProblem, trajectory: Trajectory, properties: Dict[SolutionProperties, Dict[int, Any]]) float[source]

Calculates the Orientation Offset cost.

commonocean_dc.costs.partial_cost_functions.velocity_offset_cost(scenario: Scenario, planning_problem: PlanningProblem, trajectory: Trajectory, properties: Dict[SolutionProperties, Dict[int, Any]]) float[source]

Calculates the Velocity Offset cost.

commonocean_dc.costs.partial_cost_functions.longitudinal_velocity_offset_cost(scenario: Scenario, planning_problem: PlanningProblem, trajectory: Trajectory, properties: Dict[SolutionProperties, Dict[int, Any]]) float[source]

Calculates the Velocity Offset cost.

commonocean_dc.costs.partial_cost_functions.distance_to_obstacle_cost(scenario: Scenario, planning_problem: PlanningProblem, trajectory: Trajectory, properties: Dict[SolutionProperties, Dict[int, Any]]) float[source]

Calculates the Distance to Obstacle cost.

commonocean_dc.costs.partial_cost_functions.vcro(scenario: Scenario, planning_problem: PlanningProblem, trajectory: Trajectory, properties: Dict[SolutionProperties, Dict[int, Any]]) float[source]

Calculates the VCRO cost.

commonocean_dc.costs.partial_cost_functions.r(scenario: Scenario, planning_problem: PlanningProblem, trajectory: Trajectory, properties: Dict[SolutionProperties, Dict[int, Any]]) float[source]

Calculates the Rules cost.

route_matcher

commonocean_dc.costs.route_matcher.merge_trajectories(traj_1: Trajectory, traj_2: Trajectory)[source]
commonocean_dc.costs.route_matcher.smoothen_polyline(polyline, resampling_distance: float = 2.0, n_lengthen=3)[source]
commonocean_dc.costs.route_matcher.extrapolate_polyline(polyline: ndarray, offset: float = 10) ndarray[source]

Current ccosy creates wrong projection domain if polyline has large distance between waypoints –> resampling; initial and final points are not within projection domain -> extrapolation :param polyline: polyline to be used to create ccosy :param offset: offset of newly created vertices :return: extrapolated polyline

commonocean_dc.costs.route_matcher.create_cosy_from_waters(waters)[source]
commonocean_dc.costs.route_matcher.create_cosy_from_vertices(center_vertices)[source]
commonocean_dc.costs.route_matcher.get_orientation_at_position(cosy, position)[source]
commonocean_dc.costs.route_matcher.cleanup_discontinuities(positions: ndarray, ds_0: float, tol: float, dt: float)[source]

remove discontinuities from a signal. :param signal: signal to be checked :param ds0: initial first order derivative of signal :param tol: max. absolute deviation between signal states at subsequent time steps :param dt: time step :return:

class commonocean_dc.costs.route_matcher.SolutionProperties(value)[source]

An enumeration.

AllowedVelocityInterval = 'ALLOWED_VELOCITY_INTERVAL'
LongPosition = 'LONG_POSITION'
LatPosition = 'LAT_POSITION'
LonJerk = 'LON_JERK'
LonVelocity = 'LAT_VELOCITY'
LatJerk = 'LAT_JERK'
LatVelocity = 'LAT_VELOCITY'
LonDistanceObstacles = 'LON_DISTANCE_OBSTACLES'
DeltaOrientation = 'DELTA_ORIENTATION'
class commonocean_dc.costs.route_matcher.WatersRouteMatcher(scenario: Scenario, vessel_type: VesselType)[source]

Finds waters paths of vessels’ trajectories and transforms to lane-based coordinate systems.

scenario_cc()[source]
find_waters_by_position(position: ndarray) List[int][source]
get_waters_cosy(waters_id: int) CurvilinearCoordinateSystem[source]
find_waters_by_trajectory(trajectory: Trajectory, required_properties: List[SolutionProperties], exclude_oncoming_lanes=True) Tuple[List[int], Dict[SolutionProperties, Dict[int, Any]]][source]
calculate_properties(trajectory: Trajectory, required_properties: List[SolutionProperties]) Dict[SolutionProperties, Dict[int, Any]][source]

Calculates necessary properties for the partial costs :param trajectory: trajectory in cartesian coordinates :param required_properties: additional properties that should be retrieved :return: