def check_batch_constraints(num_tasks, batch_size, max_batch_size, max_tasks):
"""
Checks if the number of tasks and batch size adhere to the specified constraints.
Args:
num_tasks (int): The total number of tasks to process.
batch_size (int): The size of each batch.
max_batch_size (int): The maximum allowed batch size.
max_tasks (int): The maximum allowed number of tasks.
Returns:
bool: True if constraints are met, False otherwise.
"""
if num_tasks > max_tasks:
print(f"Error: Number of tasks ({num_tasks}) exceeds the maximum allowed ({max_tasks}).")
return False
if batch_size < 1:
print("Error: Batch size must be at least 1.")
return False
if batch_size > max_batch_size:
print(f"Error: Batch size ({batch_size}) exceeds the maximum allowed ({max_batch_size}).")
return False
if num_tasks % batch_size != 0:
print("Warning: Number of tasks is not perfectly divisible by the batch size. Some tasks might be left out.")
return True
if __name__ == '__main__':
# Example Usage:
num_tasks = 100
batch_size = 10
max_batch_size = 20
max_tasks = 100
if check_batch_constraints(num_tasks, batch_size, max_batch_size, max_tasks):
print("Batch constraints are met.")
else:
print("Batch constraints are not met.")
#Example of constraint violation
num_tasks = 150
batch_size = 10
max_batch_size = 20
max_tasks = 100
if check_batch_constraints(num_tasks, batch_size, max_batch_size, max_tasks):
print("Batch constraints are met.")
else:
print("Batch constraints are not met.")
#Example of constraint violation
num_tasks = 100
batch_size = 25
max_batch_size = 20
max_tasks = 100
if check_batch_constraints(num_tasks, batch_size, max_batch_size, max_tasks):
print("Batch constraints are met.")
else:
print("Batch constraints are not met.")
Add your comment