Skip to content

Commit

Permalink
Calculate total cable length
Browse files Browse the repository at this point in the history
  • Loading branch information
antwi87 committed Mar 12, 2024
1 parent 63f67d1 commit fb0ad7a
Showing 1 changed file with 41 additions and 3 deletions.
44 changes: 41 additions & 3 deletions src/autopack/harness_optimization.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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,
},
Expand Down

0 comments on commit fb0ad7a

Please sign in to comment.