Ejemplo n.º 1
0
 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
Ejemplo n.º 2
0
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_
Ejemplo n.º 3
0
    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'])