Увеличьте скорость этого цикла сортировки - PullRequest
0 голосов
/ 26 февраля 2020
s = {'RESCUE':0,'BASE':0,'FOOD':2,'MEDICINE':2}


for i,sr in enumerate(self.detection):
    for j,serv in enumerate(self.detection):
                    if i<j:
                        if s.get(sr[1]) > s.get(serv[1]):
                                self.detection[i] , self.detection[j] = self.detection[j] , self.detection[i]
                        elif serv[1] == 'BASE' :
                                continue
                        elif sr[1] =='BASE' and serv[1] == 'RESCUE' :
                                continue
                        elif serv[1] == sr[1]:          # Checks if service is same 
                            if abs(sr[2] - self.prev_dist) > abs(serv[2] - self.prev_dist):         # Compares the distance 
                                    self.detection[i] , self.detection[j] = self.detection[j] , self.detection[i]
                            elif abs(sr[2] - self.prev_dist) == abs(serv[2] - self.prev_dist) and sr[3] > serv[3]:  # compares arrived time                                                     # Compares arrival time
                                    self.detection[i] , self.detection[j] = self.detection[j] , self.detection[i]

Как уменьшить этот цикл так, чтобы увеличил его производительность . пример элемента списка (self.detection) ['F4', 'FOOD', 5,10]

Добро пожаловать на сайт PullRequest, где вы можете задавать вопросы и получать ответы от других членов сообщества.
...