def reference_to_current_time(earliest_time, latest_time): delta = timedelta(minutes=earliest_time) r_earliest_time = TimeStamp(delta).to_str() delta = timedelta(minutes=latest_time) r_latest_time = TimeStamp(delta).to_str() return r_earliest_time, r_latest_time
def __init__(self, id=''): if not id: self.id = generate_uuid() else: self.id = id self.pickup_pose = Area() self.delivery_pose = Area() self.earliest_pickup_time = TimeStamp() self.latest_pickup_time = TimeStamp() self.user_id = '' self.load_type = '' self.load_id = '' self.priority = -1
def update_timestamp(message): header = message.get('header') if header: header.update(timeStamp=TimeStamp().to_str()) else: header = MessageFactoryBase.get_header(None) message.update(header)
def __init__(self, ccu_store, api, stp_solver, allocation_method, round_time=5, **kwargs): self.logger = logging.getLogger("mrs.auctioneer") self.robot_ids = list() self.timetables = dict() self.api = api self.stp = STP(stp_solver) self.allocation_method = allocation_method self.round_time = timedelta(seconds=round_time) self.alternative_timeslots = kwargs.get('alternative_timeslots', False) self.logger.debug("Auctioneer started") self.tasks_to_allocate = dict() self.allocations = list() self.waiting_for_user_confirmation = list() self.round = Round() # TODO: Update zero_timepoint today_midnight = datetime.today().replace(hour=0, minute=0, second=0, microsecond=0) self.zero_timepoint = TimeStamp() self.zero_timepoint.timestamp = today_midnight
def is_executable(self): current_time = TimeStamp() start_time = TimeStamp.from_datetime(self.start_time) if start_time < current_time: return True else: return False
def init_ztp(self): midnight = self.get_current_time().replace(hour=0, minute=0, second=0, microsecond=0) ztp = TimeStamp() ztp.timestamp = midnight return ztp
def to_timestamp(ztp, r_time): """ Returns a timestamp ztp(TimeStamp) + relative time(float) in seconds """ if r_time == float('inf'): time_ = TimeStamp() time_.timestamp = datetime.max else: time_ = ztp + timedelta(seconds=r_time) return time_
def get_header(message_type, meta_model='msg', recipients=[]): if recipients is not None and not isinstance(recipients, list): raise Exception("Recipients must be a list of strings") return {"header": {'type': message_type, 'metamodel': 'ropod-%s-schema.json' % meta_model, 'msgId': generate_uuid(), 'timestamp': TimeStamp().to_str(), 'receiverIds': recipients}}
def time_to_close(self): current_time = TimeStamp() if current_time < self.closure_time: return False self.logger.debug("Closing round at %s", current_time) self.opened = False return True
def is_executable(self): """Returns True if the given task needs to be dispatched based on the task schedule; returns False otherwise """ current_time = TimeStamp() if self.start_time < current_time: return True else: return False
def __init__(self, robot_id, api, robot_store, stp_solver, task_type): self.id = robot_id self.api = api self.stp = STP(stp_solver) self.timetable = Timetable(robot_id, self.stp) today_midnight = datetime.today().replace(hour=0, minute=0, second=0, microsecond=0) self.timetable.zero_timepoint = TimeStamp() self.timetable.zero_timepoint.timestamp = today_midnight
def trigger(self): print("Test triggered") test_msg = dict() test_msg['header'] = dict() test_msg['payload'] = dict() test_msg['header']['type'] = 'START-TEST' test_msg['header']['metamodel'] = 'ropod-msg-schema.json' test_msg['header']['msgId'] = generate_uuid() test_msg['header']['timestamp'] = TimeStamp().to_str() test_msg['payload']['metamodel'] = 'ropod-bid_round-schema.json' self.shout(test_msg)
def __new__(cls, message_type, meta_model=None, **kwargs): recipients = kwargs.get('recipients', list()) if recipients is not None and not isinstance(recipients, list): raise Exception("Recipients must be a list of strings") return { 'type': message_type, 'metamodel': meta_model, 'msgId': str(generate_uuid()), 'timestamp': TimeStamp().to_str(), 'receiverIds': recipients }
def start(self): """ Starts and auction round: - opens the round - marks the round as not finished opened: The auctioneer processes bid msgs closed: The auctioneer no longer processes incoming bid msgs, i.e., bid msgs received after the round has closed are not considered in the election process After the round closes, the election process takes place finished: The election process is over, i.e., an mrs has been made (or an exception has been raised) """ open_time = TimeStamp() self.closure_time = TimeStamp(delta=self.round_time) self.logger.debug("Round opened at %s and will close at %s", open_time, self.closure_time) self.finished = False self.opened = True
def announce_tasks(self): tasks = list(self.tasks_to_allocate.values()) earliest_task = Task.get_earliest_task(tasks) closure_time = earliest_task.pickup_constraint.earliest_time - self.closure_window if not self.is_valid_time(closure_time) and self.alternative_timeslots: # Closure window should be long enough to allow robots to bid (tune if necessary) closure_time = self.get_current_time() + self.closure_window elif not self.is_valid_time( closure_time) and not self.alternative_timeslots: self.logger.warning( "Task %s cannot not be allocated at its given temporal constraints", earliest_task.task_id) earliest_task.update_status(TaskStatusConst.PREEMPTED) self.tasks_to_allocate.pop(earliest_task.task_id) return self.changed_timetable.clear() for task in tasks: if not task.hard_constraints: self.update_soft_constraints(task) self.round = Round(self.robot_ids, self.tasks_to_allocate, n_tasks=len(tasks), closure_time=closure_time, alternative_timeslots=self.alternative_timeslots, simulator=self.simulator) earliest_admissible_time = TimeStamp() earliest_admissible_time.timestamp = self.get_current_time( ) + timedelta(minutes=1) task_announcement = TaskAnnouncement(tasks, self.round.id, self.timetable_manager.ztp, earliest_admissible_time) self.logger.debug("Starting round: %s", self.round.id) self.logger.debug("Number of tasks to allocate: %s", len(tasks)) msg = self.api.create_message(task_announcement) self.logger.debug("Auctioneer announces tasks %s", [task.task_id for task in tasks]) self.round.start() self.api.publish(msg, groups=['TASK-ALLOCATION'])
def to_stn_task(self, task_lot): """ Converts a task to an stn task Args: task_lot (obj): task_lot object to be converted zero_timepoint (TimeStamp): Zero Time Point. Origin time to which task temporal information is referenced to """ start_timepoint_constraints = task_lot.constraints.timepoint_constraints[0] r_earliest_start_time, r_latest_start_time = TimepointConstraints.relative_to_ztp(start_timepoint_constraints, self.zero_timepoint) delta = timedelta(minutes=1) earliest_navigation_start = TimeStamp(delta) r_earliest_navigation_start = earliest_navigation_start.get_difference(self.zero_timepoint, "minutes") stn_task = STNTask(task_lot.task.task_id, r_earliest_navigation_start, r_earliest_start_time, r_latest_start_time, task_lot.start_location, task_lot.finish_location) return stn_task
def get_task_schedule(self, task_id, robot_id): # For now, returning the start navigation time from the dispatchable graph task_schedule = dict() timetable = self.timetables.get(robot_id) relative_start_navigation_time = timetable.dispatchable_graph.get_time( task_id, "navigation") relative_start_time = timetable.dispatchable_graph.get_time( task_id, "start") relative_latest_finish_time = timetable.dispatchable_graph.get_time( task_id, "finish", False) self.logger.debug("Current time %s: ", TimeStamp()) self.logger.debug("zero_timepoint %s: ", self.zero_timepoint) self.logger.debug("Relative start navigation time: %s", relative_start_navigation_time) self.logger.debug("Relative start time: %s", relative_start_time) self.logger.debug("Relative latest finish time: %s", relative_latest_finish_time) start_navigation_time = self.zero_timepoint + timedelta( minutes=relative_start_navigation_time) start_time = self.zero_timepoint + timedelta( minutes=relative_start_time) finish_time = self.zero_timepoint + timedelta( minutes=relative_latest_finish_time) self.logger.debug("Start navigation of task %s: %s", task_id, start_navigation_time) self.logger.debug("Start of task %s: %s", task_id, start_time) self.logger.debug("Latest finish of task %s: %s", task_id, finish_time) task_schedule['start_time'] = start_navigation_time.to_datetime() task_schedule['finish_time'] = finish_time.to_datetime() return task_schedule
def refresh(self): """Update the header with new values """ self['header']['timestamp'] = TimeStamp().to_str() self['header']['msgId'] = str(generate_uuid())
def get_current_timestamp(self): if self.simulator: return TimeStamp.from_datetime(self.simulator.current_time) else: return TimeStamp()