Skip to content

Commit

Permalink
Refactor trim method to trim_end and add interval check
Browse files Browse the repository at this point in the history
  • Loading branch information
Yacobolo committed Feb 15, 2024
1 parent ffeae0b commit 370e90d
Showing 1 changed file with 7 additions and 2 deletions.
9 changes: 7 additions & 2 deletions src/factryengine/scheduler/heuristic_solver/matrix.py
Original file line number Diff line number Diff line change
Expand Up @@ -51,14 +51,19 @@ def compare_update_mask_and_merge(cls, matrices: list["Matrix"]) -> "Matrix":
return cls.merge(matrices)

@classmethod
def trim(cls, original_matrix: "Matrix", trim_matrix: "Matrix") -> "Matrix":
def trim_end(cls, original_matrix: "Matrix", trim_matrix: "Matrix") -> "Matrix":
"""
Trims a Matrix based on another
"""
new_intervals = original_matrix.intervals[: len(trim_matrix.intervals)]
# Check if intervals are the same

if not np.array_equal(new_intervals, trim_matrix.intervals):
raise ValueError("All matrices must have the same intervals")

return cls(
resource_ids=original_matrix.resource_ids,
intervals=trim_matrix.intervals,
intervals=new_intervals,
resource_matrix=original_matrix.resource_matrix[
: len(trim_matrix.intervals)
],
Expand Down

0 comments on commit 370e90d

Please sign in to comment.