Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- from exceptions import InvalidJobError
- class Job:
- existing_jobs = set()
- def __init__(self, location=None, start_time=None, end_time=None,
- name=None, capacity_demand=0, capacity_dimension=0,
- service_time=0, skill_requirements=()):
- # Validate inputs
- if not any([location, start_time, end_time]):
- raise InvalidJobError("All jobs must have a location, a start "
- "time and and end time.")
- try:
- self.start_time = int(start_time)
- self.end_time = int(end_time)
- except (ValueError, TypeError):
- raise InvalidJobError("Could not discern time slot for job "
- "at location: {}".format(location))
- if self.start_time > self.end_time:
- raise InvalidJobError("Start time greater than end time for: "
- "{}".format(location))
- self.location = location
- self.name = name if name else self.location
- if self.name in Job.existing_jobs:
- raise InvalidJobError("Jobs with duplicate locations must be given"
- " unique names. Location: {}".format(location)
- )
- self.capacity_demand = int(capacity_demand)
- self.capacity_dimension = int(capacity_dimension)
- self.service_time = int(service_time)
- if not skill_requirements:
- self.skill_requirements = {-1}
- else:
- try:
- self.skill_requirements = set(skill_requirements)
- except TypeError:
- raise InvalidJobError("Skill requirements must be a sequence, "
- "location: {}".format(self.location))
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement