Skip to content

[Feature] Add RewardWithPenalties class and penalty functions#78

Merged
Pabloo22 merged 4 commits intomainfrom
77-add-new-rewardobserver
Sep 13, 2025
Merged

[Feature] Add RewardWithPenalties class and penalty functions#78
Pabloo22 merged 4 commits intomainfrom
77-add-new-rewardobserver

Conversation

@Pabloo22
Copy link
Owner

No description provided.

Copy link
Contributor

@gemini-code-assist gemini-code-assist bot left a comment

Choose a reason for hiding this comment

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

Summary of Changes

Hello @Pabloo22, I'm Gemini Code Assist1! I'm currently reviewing this pull request and will post my feedback shortly. In the meantime, here's a summary to help you and other reviewers quickly get up to speed!

This pull request enhances the library's ability to handle scheduling constraints by introducing a robust system for incorporating penalties into both metaheuristic objective functions and reinforcement learning reward mechanisms. It provides new classes and functions to calculate and apply penalties for deadline and due date violations, making the optimization and learning processes more sensitive to these critical constraints.

Highlights

  • New Penalty Computation Functions: Introduced compute_penalty_for_deadlines and compute_penalty_for_due_dates in the metaheuristics module for modular and reusable penalty calculations related to schedule violations.
  • Refactored Makespan Objective: The get_makespan_with_penalties_objective function now leverages the newly introduced dedicated penalty computation functions, enhancing code clarity and maintainability.
  • RewardWithPenalties Class for RL: A new RewardObserver class, RewardWithPenalties, has been added to the reinforcement learning module. This class allows for the flexible combination of a base reward with custom penalties for constraint violations, such as deadlines and due dates.
  • RL Penalty Utility Functions: Specific utility functions (get_deadline_violation_penalty, get_due_date_violation_penalty) were added to the reinforcement learning utilities for calculating penalties on a per-scheduled-operation basis, facilitating their use within the RewardWithPenalties class.
  • Test File Renaming and Updates: The test file test_rl_utils.py was renamed to test_utils.py and updated to include comprehensive test cases for the newly added penalty utility functions, ensuring their correctness.
Using Gemini Code Assist

The full guide for Gemini Code Assist can be found on our documentation page, here are some quick tips.

Invoking Gemini

You can request assistance from Gemini at any point in your pull request via creating an issue comment (i.e. comment on the pull request page) using either /gemini <command> or @gemini-code-assist <command>. Below is a summary of the supported commands.

Feature Command Description
Code Review /gemini review Performs a code review for the current pull request in its current state.
Pull Request Summary /gemini summary Provides a summary of the current pull request in its current state.
Comment @gemini-code-assist Responds in comments when explicitly tagged, both in issue comments and review comments.
Help /gemini help Displays a list of available commands.

Customization

To customize Gemini Code Assist for GitHub experience, repository maintainers can create a configuration file and/or provide a custom code review style guide (such as PEP-8 for Python) by creating and adding files to a .gemini/ folder in the base of the repository. Detailed instructions can be found here.

Limitations & Feedback

Gemini Code Assist may make mistakes. Please leave feedback on any instances where its feedback is incorrect or counter productive. You can react with 👍 and 👎 on @gemini-code-assist comments. If you're interested in giving your feedback about your experience with Gemini Code Assist for Github and other Google products, sign up here.

You can also get AI-powered code generation, chat, as well as code reviews directly in the IDE at no cost with the Gemini Code Assist IDE Extension.

Footnotes

  1. Review the Privacy Notices, Generative AI Prohibited Use Policy, Terms of Service, and learn how to configure Gemini Code Assist in GitHub here. Gemini can make mistakes, so double check it and use code with caution.

Copy link
Contributor

Copilot AI left a comment

Choose a reason for hiding this comment

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

Pull Request Overview

This PR introduces a RewardWithPenalties class for the reinforcement learning module that adds penalty functionality to existing reward functions. The changes enable penalties for deadline and due date violations in job shop scheduling problems.

Key changes include:

  • Added RewardWithPenalties class that wraps base reward observers with penalty functions
  • Introduced penalty computation functions for deadline and due date violations
  • Refactored metaheuristic objective functions to extract reusable penalty computation logic

Reviewed Changes

Copilot reviewed 7 out of 7 changed files in this pull request and generated 1 comment.

Show a summary per file
File Description
job_shop_lib/reinforcement_learning/_reward_observers.py Adds the new RewardWithPenalties class that combines base rewards with penalty functions
job_shop_lib/reinforcement_learning/_utils.py Introduces get_deadline_violation_penalty and get_due_date_violation_penalty functions
job_shop_lib/reinforcement_learning/__init__.py Exports the new class and penalty functions in the module's public API
job_shop_lib/metaheuristics/_objective_functions.py Refactors existing code to extract penalty computation into reusable functions
job_shop_lib/metaheuristics/__init__.py Exports the new penalty computation functions
tests/reinforcement_learning/test_utils.py Adds comprehensive tests for the penalty functions

Tip: Customize your code reviews with copilot-instructions.md. Create the file or learn how to get started.

Copy link
Contributor

@gemini-code-assist gemini-code-assist bot left a comment

Choose a reason for hiding this comment

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

Code Review

This pull request introduces a new RewardWithPenalties reward observer and associated penalty functions for deadline and due date violations. The implementation refactors existing penalty calculation logic from get_makespan_with_penalties_objective into separate, reusable functions. My review focuses on improving code maintainability by addressing duplication in the new penalty functions, correcting documentation, and highlighting a potential loss of test coverage from a removed file. I've also suggested adding type hints to a new test helper for better clarity.

@codecov-commenter
Copy link

codecov-commenter commented Sep 11, 2025

⚠️ Please install the 'codecov app svg image' to ensure uploads and comments are reliably processed by Codecov.

Codecov Report

✅ All modified and coverable lines are covered by tests.

📢 Thoughts on this report? Let us know!

@Pabloo22 Pabloo22 requested a review from Copilot September 12, 2025 16:34
Copy link
Contributor

Copilot AI left a comment

Choose a reason for hiding this comment

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

Pull Request Overview

Copilot reviewed 9 out of 9 changed files in this pull request and generated 2 comments.


Tip: Customize your code reviews with copilot-instructions.md. Create the file or learn how to get started.

@Pabloo22 Pabloo22 requested a review from Copilot September 13, 2025 19:12
Copy link
Contributor

Copilot AI left a comment

Choose a reason for hiding this comment

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

Pull Request Overview

Copilot reviewed 10 out of 10 changed files in this pull request and generated 1 comment.


Tip: Customize your code reviews with copilot-instructions.md. Create the file or learn how to get started.

@Pabloo22 Pabloo22 merged commit a108e0f into main Sep 13, 2025
10 checks passed
@Pabloo22 Pabloo22 added the enhancement New feature or request label Sep 13, 2025
@Pabloo22 Pabloo22 deleted the 77-add-new-rewardobserver branch October 12, 2025 09:52
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

enhancement New feature or request

Projects

None yet

Development

Successfully merging this pull request may close these issues.

[Feature] Add new RewardObserver for taking into account deadlines and due dates

3 participants