Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Fishchimp/feature/optimiser v2 2 (#300)
## 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]>
- Loading branch information