diff --git a/src/autopack/harness_optimization.py b/src/autopack/harness_optimization.py index 9954f65..d1e836a 100644 --- a/src/autopack/harness_optimization.py +++ b/src/autopack/harness_optimization.py @@ -111,6 +111,34 @@ def harness_length(harness: data_model.Harness) -> float: return np.sum(segment_lengths) +def total_length(harness: data_model.Harness) -> float: + # Use the first segments to see what kind of coordinates we have + first_segment = harness.harness_segments[0] + if len(first_segment.smooth_coords) > 0: + segment_lengths = np.array( + [ + path_length(seg.smooth_coords) * len(seg.cables) + for seg in harness.harness_segments + ] + ) + elif len(first_segment.presmooth_coords) > 0: + segment_lengths = np.array( + [ + path_length(seg.presmooth_coords) * len(seg.cables) + for seg in harness.harness_segments + ] + ) + else: + segment_lengths = np.array( + [ + path_length(seg.discrete_coords) * len(seg.cables) + for seg in harness.harness_segments + ] + ) + + return np.sum(segment_lengths) + + def smooth_cost(harness: data_model.Harness, cost_field: CostField) -> float: """ Returns the cost of the harness through the cost field, calculated @@ -239,12 +267,22 @@ def design_point_ds( "objective": True, }, ), - "length": xr.DataArray( + "harness_length": xr.DataArray( [harness_length(h) for h in harness_solutions], dims=["solution"], attrs={ - "title": "Length", - "description": "Total length of the harness.", + "title": "Harness length", + "description": "Length of the harness.", + "units": "m", + "objective": False, + }, + ), + "total_length": xr.DataArray( + [total_length(h) for h in harness_solutions], + dims=["solution"], + attrs={ + "title": "Total length", + "description": "Total length of the cables in the harness.", "units": "m", "objective": False, },