Exemplo n.º 1
0
 def get_feasible_region(self, flow: Flow,
                         send_delay: int, prop_delay: int, proc_delay: int, cycle_len: int) -> IntInterval:
     last_hop_time_slot_offset: int = flow.get_last_hop_time_slot_offset()
     if last_hop_time_slot_offset == -1:
         return IntInterval.closed_open(0, cycle_len)
     else:
         assignable_position: int = send_delay + prop_delay + proc_delay + last_hop_time_slot_offset
         return IntInterval.closed_open(assignable_position, assignable_position + cycle_len)
     pass
Exemplo n.º 2
0
 def allocate_time_slots_m(self, fid: FlowId, time_slot_offset: int, allocated_len: int):
     interval: IntInterval = IntInterval.closed_open(time_slot_offset, time_slot_offset + allocated_len)
     flag: bool = False
     for time_window in self.time_windows:
         try:
             new_time_window_0: IntInterval = time_window | interval
             if getattr(time_window, 'fid') == fid:
                 i: int = self.time_windows.index(time_window)
                 setattr(new_time_window_0, 'fid', fid)
                 del self.time_windows[i]
                 self.time_windows.insert(i, new_time_window_0)
                 j: int = i + 1
                 if j < len(self.time_windows) and \
                         getattr(self.time_windows[j], 'fid') == fid and \
                         new_time_window_0.upper == self.time_windows[j].lower:
                     new_time_window_1: IntInterval = self.time_windows[j] | self.time_windows[i]
                     setattr(new_time_window_1, 'fid', fid)
                     del self.time_windows[i]
                     del self.time_windows[i]
                     self.time_windows.insert(i, new_time_window_1)
                 flag = True
                 break
         except Exception as e:
             pass
     if flag is False:
         setattr(interval, 'fid', fid)
         self.time_windows.append(interval)
     self.time_windows.sort()
Exemplo n.º 3
0
 def test_closed_open(self):
     interval = IntInterval.closed_open(10, 14, step=2)
     assert interval.lower == 10
     assert interval.upper == 14
     assert interval.lower_inc
     assert not interval.upper_inc
     assert interval.step == 2
Exemplo n.º 4
0
 def allocate_time_slots(self, flow: Flow, time_slot_offset: int, allocated_len: int, phs_num: int) -> bool:
     if not self._check_assignable(flow, time_slot_offset, allocated_len, phs_num):
         return False
     cycle_time_slot_num: int = int(np.ceil(flow.cycle / self.time_slot_len))
     for phs in range(0, phs_num):
         offset: int = time_slot_offset + phs * cycle_time_slot_num
         interval: IntInterval = IntInterval.closed_open(offset, offset + allocated_len)
         setattr(interval, 'm_fid', flow.m_fid)
         setattr(interval, 'fid', flow.fid)
         setattr(interval, 'phs', phs)
         self.time_windows.append(interval)
     self.time_windows.sort()
     return True
Exemplo n.º 5
0
    def start_flow(self, t):
        """
        Only flow after the specified t will actually be transferred from the source account to dest.
        """
        if self._flow_enabled:
            raise PipeException("Flow already started")

        if t < self._last_flushed_t:
            raise PipeException("Time travel not supported yet")

        if not self._last_stopped_t == None:
            self._blackouts.append(IntInterval.closed_open(self._last_stopped_t, t))

        self._last_flushed_t = t
        self._flow_enabled = True
Exemplo n.º 6
0
 def _check_assignable(self, flow: Flow, time_slot_offset: int, allocated_len: int, phs_num: int) -> bool:
     cycle_time_slot_num: int = int(np.ceil(flow.cycle / self.time_slot_len))
     for phs in range(0, phs_num):
         offset: int = time_slot_offset + phs * cycle_time_slot_num
         interval: IntInterval = IntInterval.closed_open(offset, offset + allocated_len)
         for time_window in self.time_windows:
             try:
                 if time_window | interval:
                     if time_window.upper == interval.lower:
                         continue
                     elif time_window.lower == interval.upper:
                         continue
                     elif getattr(time_window, 'm_fid') != flow.m_fid:
                         return False
                     elif getattr(time_window, 'phs') != phs:
                         return False
             except Exception as e:
                 pass
     return True
Exemplo n.º 7
0
    def list_to_interval(data_list):
        '''Method to turn lists into intervals.

        :param data_list:
        :return:
        '''
        try:
            list_interval = []
            for i in range(len(data_list)):
                if i != len(data_list) - 1:
                    data_range = IntInterval.closed_open(
                        data_list[i], data_list[i + 1])
                list_interval.append(data_range)

            print("Success in list to interval", datetime.now(), flush=True)
            return list_interval

        except Exception as err:
            logging.error('Error in list to interval:', err)