1. def check_batch_constraints(num_tasks, batch_size, max_batch_size, max_tasks):
  2. """
  3. Checks if the number of tasks and batch size adhere to the specified constraints.
  4. Args:
  5. num_tasks (int): The total number of tasks to process.
  6. batch_size (int): The size of each batch.
  7. max_batch_size (int): The maximum allowed batch size.
  8. max_tasks (int): The maximum allowed number of tasks.
  9. Returns:
  10. bool: True if constraints are met, False otherwise.
  11. """
  12. if num_tasks > max_tasks:
  13. print(f"Error: Number of tasks ({num_tasks}) exceeds the maximum allowed ({max_tasks}).")
  14. return False
  15. if batch_size < 1:
  16. print("Error: Batch size must be at least 1.")
  17. return False
  18. if batch_size > max_batch_size:
  19. print(f"Error: Batch size ({batch_size}) exceeds the maximum allowed ({max_batch_size}).")
  20. return False
  21. if num_tasks % batch_size != 0:
  22. print("Warning: Number of tasks is not perfectly divisible by the batch size. Some tasks might be left out.")
  23. return True
  24. if __name__ == '__main__':
  25. # Example Usage:
  26. num_tasks = 100
  27. batch_size = 10
  28. max_batch_size = 20
  29. max_tasks = 100
  30. if check_batch_constraints(num_tasks, batch_size, max_batch_size, max_tasks):
  31. print("Batch constraints are met.")
  32. else:
  33. print("Batch constraints are not met.")
  34. #Example of constraint violation
  35. num_tasks = 150
  36. batch_size = 10
  37. max_batch_size = 20
  38. max_tasks = 100
  39. if check_batch_constraints(num_tasks, batch_size, max_batch_size, max_tasks):
  40. print("Batch constraints are met.")
  41. else:
  42. print("Batch constraints are not met.")
  43. #Example of constraint violation
  44. num_tasks = 100
  45. batch_size = 25
  46. max_batch_size = 20
  47. max_tasks = 100
  48. if check_batch_constraints(num_tasks, batch_size, max_batch_size, max_tasks):
  49. print("Batch constraints are met.")
  50. else:
  51. print("Batch constraints are not met.")

Add your comment