Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fishchimp/feature/optimiser v2 2 #300

Merged
merged 15 commits into from
Oct 3, 2024
Merged

Conversation

fishchimp
Copy link
Contributor

Describe your changes

Refactor and Enhancement of the Optimiser Class for Shift and Volunteer Assignment

This PR focuses on improving the Optimiser class's overall code readability, functionality, and alignment with the new requirements for volunteer shift management. Major changes include the replacement of vehicle-based requirements with role-based requirements, the addition of logging for better debugging, and the introduction of new constraints for skill and compatibility handling in the optimisation model.

Key Changes:

  1. Logging Integration:

    • Added logging functionality to track errors and provide insights during the optimisation process.
    • Enhanced the debugging output for clearer visibility of the optimiser's internal state.
  2. Role-Based Optimisation:

    • Transitioned from the asset/vehicle-based logic in the old implementation to a role-based structure in the new version.
    • Replaced AssetRequestVolunteer and AssetRequestVehicle logic with ShiftRequestVolunteer to align with shift management requirements.
  3. MiniZinc Model Refactor:

    • Introduced a new MiniZinc model that simplifies the assignment of volunteers to shifts and roles.
    • The compatibility, mastery, and skill requirements are now handled with flattened 1D matrices to optimise the data passing to the solver.
    • Constraints added to ensure that volunteers are only assigned to roles they are compatible with and have mastered.
  4. Constraints and Objective:

    • The new model includes constraints for skill requirements, ensuring the required number of roles is filled.
    • The objective is now focused on maximising the number of valid role assignments while respecting constraints.
  5. Improved Database Handling:

    • Enhanced save_result function to store possible volunteer assignments with a PENDING status in the ShiftRequestVolunteer table.
    • Added exception handling and rollback mechanisms for better reliability in database transactions.
  6. Flattened Matrices:

    • Helper methods were introduced (flatten_compatibility, flatten_skill_requirements) to flatten 2D matrices into 1D arrays for passing into the MiniZinc model.
  7. Miscellaneous:

    • Removed unnecessary vehicle and position requirements that were irrelevant to the current optimisation scenario.
    • Refactored the entire solve() method for clarity and performance.

Testing:

  • The MiniZinc model string was tested by running it in the MiniZincIDE with hardcoded inputs to validate the optimisation logic and constraints.
    Further testing for data persistence is required, particularly for interactions with the database. Since I am not yet familiar with this process, I need some guidance on setting up and using a database mockup.

Issue ticket number and link

Related Issue Tickets

@fishchimp fishchimp requested a review from 5oappy October 1, 2024 03:10
@fishchimp fishchimp self-assigned this Oct 1, 2024
Copy link
Collaborator

@emilymclean emilymclean left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Looks good, just please do a database write through a repository

Copy link
Contributor

@5oappy 5oappy left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

looks good shift repo might need to be modified / manually merged when pulled with Linda as both may have overlapping features and a refactor may be possible. low priority tho.

@emilymclean emilymclean added this pull request to the merge queue Oct 3, 2024
@emilymclean emilymclean removed this pull request from the merge queue due to the queue being cleared Oct 3, 2024
github-actions bot pushed a commit that referenced this pull request Oct 3, 2024
## Describe your changes
Refactor and Enhancement of the Optimiser Class for Shift and Volunteer
Assignment

This PR focuses on improving the Optimiser class's overall code
readability, functionality, and alignment with the new requirements for
volunteer shift management. Major changes include the replacement of
vehicle-based requirements with role-based requirements, the addition of
logging for better debugging, and the introduction of new constraints
for skill and compatibility handling in the optimisation model.

**Key Changes:**

1. **Logging Integration:**
- Added logging functionality to track errors and provide insights
during the optimisation process.
- Enhanced the debugging output for clearer visibility of the
optimiser's internal state.

2. **Role-Based Optimisation:**
- Transitioned from the asset/vehicle-based logic in the old
implementation to a role-based structure in the new version.
- Replaced `AssetRequestVolunteer` and `AssetRequestVehicle` logic with
`ShiftRequestVolunteer` to align with shift management requirements.
   
3. **MiniZinc Model Refactor:**
- Introduced a new MiniZinc model that simplifies the assignment of
volunteers to shifts and roles.
- The compatibility, mastery, and skill requirements are now handled
with flattened 1D matrices to optimise the data passing to the solver.
- Constraints added to ensure that volunteers are only assigned to roles
they are compatible with and have mastered.

4. **Constraints and Objective:**
- The new model includes constraints for skill requirements, ensuring
the required number of roles is filled.
- The objective is now focused on maximising the number of valid role
assignments while respecting constraints.

5. **Improved Database Handling:**
- Enhanced `save_result` function to store possible volunteer
assignments with a `PENDING` status in the `ShiftRequestVolunteer`
table.
- Added exception handling and rollback mechanisms for better
reliability in database transactions.

6. **Flattened Matrices:**
- Helper methods were introduced (`flatten_compatibility`,
`flatten_skill_requirements`) to flatten 2D matrices into 1D arrays for
passing into the MiniZinc model.

7. **Miscellaneous:**
- Removed unnecessary vehicle and position requirements that were
irrelevant to the current optimisation scenario.
   - Refactored the entire `solve()` method for clarity and performance.

**Testing:**

- The MiniZinc model string was tested by running it in the MiniZincIDE
with hardcoded inputs to validate the optimisation logic and
constraints.
Further testing for data persistence is required, particularly for
interactions with the database. Since I am not yet familiar with this
process, I need some guidance on setting up and using a database mockup.

## Issue ticket number and link
### Related Issue Tickets

- [FIR-4: Scheduler Create
Shifts](https://fireapp-emergiq-2024.atlassian.net/browse/FIR-4)
- [FIR-111: Optimiser outputs optimal
volunteers](https://fireapp-emergiq-2024.atlassian.net/browse/FIR-111)

---------

Co-authored-by: Muhammad Hafizh Hasyim <[email protected]>
@emilymclean emilymclean merged commit 1eda316 into main Oct 3, 2024
6 checks passed
@emilymclean emilymclean deleted the fishchimp/feature/optimiser_v2_2 branch October 3, 2024 07:44
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants