Created
February 2, 2026 11:10
-
-
Save roganjoshp/9458d2548cefa1321c2648faa4c11a9b to your computer and use it in GitHub Desktop.
Method decorator
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| class Problem(TimeMixin): | |
| """ | |
| Container class to aggregate problem definition/constraints and pass to | |
| solver | |
| """ | |
| def __init__( | |
| self, start_date: str, name: str = "", config: Config = Config() | |
| ): | |
| self.config = config | |
| def supported_backends(backends: List[str]): | |
| """ | |
| Decorator to ensure that solver-incompatible constraints that are added | |
| raise a warning to the user. | |
| Parameters | |
| ---------- | |
| backends : list | |
| A list of solver names that are supported for a feature | |
| """ | |
| def decorator(func): | |
| @functools.wraps(func) | |
| def check_backends(self, *args, **kwargs): | |
| if ( | |
| self.config.solver not in backends | |
| and not self.config.silence_warnings | |
| ): | |
| warnings.warn( | |
| f"{func.__name__} not supported for " | |
| f"solver: {self.config.solver}" | |
| ) | |
| return func(self, *args, **kwargs) | |
| return check_backends | |
| return decorator | |
| @supported_backends(["jsprit", "rust"]) | |
| def add_optional_break(self, opt_break: OptionalBreak): | |
| pass | |
| @supported_backends(["rust"]) | |
| def add_required_break(self, req_break: RequiredBreak): | |
| pass | |
| @supported_backends(["jsprit"]) | |
| def add_consecutive_jobs(self, consecutive_jobs: ConsecutiveJobs): | |
| pass |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment