Skip to content

Commit

Permalink
Merge pull request #7 from factryflow/bugfix/matrix-utilization
Browse files Browse the repository at this point in the history
Bugfix/matrix utilization
  • Loading branch information
mjducut-oe authored Oct 24, 2024
2 parents 550e74f + cb018dc commit dca690b
Show file tree
Hide file tree
Showing 10 changed files with 313 additions and 99 deletions.
4 changes: 4 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -1,5 +1,9 @@
# Prototyping Notebooks
notebooks/
*.ipynb

# Test data
inputs/

# vscode settings
.vscode/
Expand Down
16 changes: 13 additions & 3 deletions src/factryengine/models/task.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
from pydantic import BaseModel, Field, model_validator, validator
from pydantic import BaseModel, Field, model_validator, validator, PrivateAttr

from .resource import Resource, ResourceGroup

Expand Down Expand Up @@ -44,15 +44,16 @@ def get_unique_resources(self) -> set[Resource]:


class Task(BaseModel):
id: int
id: int | str
name: str = ""
duration: int = Field(gt=0)
priority: int = Field(gt=0)
assignments: list[Assignment] = []
constraints: set[Resource] = set()
predecessor_ids: set[int] = set()
predecessor_ids: set[int] | set[str] = set()
predecessor_delay: int = Field(0, gt=0)
quantity: int = Field(None, gt=0)
_batch_id: int = PrivateAttr(None)

def __hash__(self):
return hash(self.id)
Expand Down Expand Up @@ -85,3 +86,12 @@ def set_name(cls, v, values) -> str:
def get_id(self) -> int:
"""returns the task id"""
return self.id

@property
def batch_id(self):
"""returns the batch id of the task"""
return self._batch_id

def set_batch_id(self, batch_id):
"""sets the batch id of the task"""
self._batch_id = batch_id
9 changes: 5 additions & 4 deletions src/factryengine/scheduler/heuristic_solver/main.py
Original file line number Diff line number Diff line change
Expand Up @@ -74,24 +74,25 @@ def solve(self) -> list[dict]:
except AllocationError as e:
self.mark_task_as_unscheduled(task_id=task_id, error_message=str(e))
continue

# update resource windows
self.window_manager.update_resource_windows(allocated_resource_windows_dict)

# Append task values

task_values = {
"task_id": task_id,
"assigned_resource_ids": list(allocated_resource_windows_dict.keys()),
"task_start": min(
start for start, _ in allocated_resource_windows_dict.values()
start for intervals in allocated_resource_windows_dict.values() for start, _ in intervals
),
"task_end": max(
end for _, end in allocated_resource_windows_dict.values()
end for intervals in allocated_resource_windows_dict.values() for _, end in intervals
),
"resource_intervals": allocated_resource_windows_dict.values(),
}
self.task_vars[task_id] = task_values


return list(
self.task_vars.values()
) # Return values of the dictionary as a list
Expand Down
7 changes: 5 additions & 2 deletions src/factryengine/scheduler/heuristic_solver/matrix.py
Original file line number Diff line number Diff line change
Expand Up @@ -56,9 +56,12 @@ 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):
# if not np.array_equal(new_intervals, trim_matrix.intervals):
# raise ValueError("All matrices must have the same intervals")

# Used np.allclose to allow for small differences in the intervals
if not np.allclose(new_intervals, trim_matrix.intervals, atol=1e-8):
raise ValueError("All matrices must have the same intervals")

return cls(
Expand Down
Loading

0 comments on commit dca690b

Please sign in to comment.