0

这是删除我的客户之前的一次迭代 46

import time 

elif ET[min_index][0] == 7: #event type: taxi taking customer to destination
        
        TNOW = Tnext 
        Customer_found = -1
        Num_trip += 1 #this variable hold the total number of trip completion.
        
        
        #Find the customer who is going to finsh his trip
        Customer_complete = ET[min_index][2] #denote the ID of the customer who is going to finsh his trip. 
        for i in range(NumC):
            if LC[i][5] == Customer_complete:
                Customer_found = i
                break
       
        #Find the driver that is taking this customer to finish the trip
        Taxi_complete = ET[min_index][1] #denote the ID of the taxi who is taking the customer to finish her service.
        Taxi_found = -1
        for j in range(NumT):
            if LT[j][3] == Taxi_complete:
                Taxi_found = j
                break
        print("ET[min_index][2]",ET[min_index][2])
        print("HERE I am at ET 7 inside the very first FOR loop")
        print("Customer_found", Customer_found)
        print("I HAVE JUST FINISHED SERVING THIS CUSTOMER: ", Customer_complete)
        X_cur = LC[Customer_found][3] #current positition of the taxi i-th after dropping off customer 1
        Y_cur = LC[Customer_found][4]
        
        print("X_cur = ", X_cur)
        print("Y_cur = ", Y_cur)
        
        #assign customer to taxi
        Min_Distance = 10000
        assigned_new = -1
        Assigned = False # this indicate whether or not we have assgined a customer. This is as same as Assigned= 0.
        
        
        
        
        print("IM going to delete: ", Customer_found)
        LC.pop(Customer_found)
        print("I just deleted: ", Customer_found)
        
        
        
        NumC -= 1
        if NumC > 0: #check to see if there is any other customer close by.  
             for k in range(NumC): #range take value from 0 -> NumC-1
                if LC[k][0] == 0:
                    Assigned = True
                    #check if the location of the i-th taxi that just dropped off customer 1 is close to customer 2.
                    Distance = math.sqrt((LC[k][1]-X_cur)**2 + (LC[k][2]-Y_cur)**2)
                    if Distance < Min_Distance:
                        Min_Distance = Distance 
                        assigned_new = k
                    
        if Assigned:
            LC[assigned_new][0] = 1 # make customer i-th become busy
            print("assigned_new=",assigned_new)
            EC.append(TNOW + time_coef*(Min_Distance + math.sqrt((LC[assigned_new][1]-LC[assigned_new][3])**2 +
                                                                    (LC[assigned_new][2]-LC[assigned_new][4])**2)))
            ET.append([7, ET[min_index][1], LC[assigned_new][5]])
            
            

            
        
            #The below step make sure that we delete the abandonment of customer once they have 
            been assigned a taxi.
            FR = -1 #found row
            for m in range(len(EC)):
                print(m)
                if ET[m][2] == LC[assigned_new][5]: #this condition check if this event is an abandonment and it also check if the event is correspond to the customer we are deal with.
                    #Customer assigned + 1 is because if Customer assigned = 0 then we know that it is the first customer that is going to abandon.
                    FR = m # want to find which row of the EC and the ET correspond the abandonment of the customer
                    break

            #Delete/ remove and item from a list of EC and ET
            EC.pop(FR)
            ET.pop(FR)


        else:
            print("Taxi_found", Taxi_found)
            LT[Taxi_found][0] = 0 # min_index never used on LT and LC
            LT[Taxi_found][1] = X_cur
            LT[Taxi_found][2] = Y_cur
            print(" I COULD not find a customer to match and I have just executed else 
    condition of ET==7")
            
        ET.pop(min_index)
        EC.pop(min_index)

在这里您可以在事件类型中看到条目 [5,0, 46] 已被删除

大家好,我正在尝试编写一个算法,可以模拟将出租车打给乘客的过程。每个事件类型都有数字编码:
所以 ET == 1 只是出租车到达事件,
2:客户到达,
3:终止事件,
4:出租车放弃,
5:客户没有耐心,
7:只是出租车将客户带到目的地并与另一位客户重新匹配。

事件日历 (EC) 中的第 0 个条目是距离下一次出租车到达的时间,
事件日历中的第 1 个条目是距离下一个客户到达的时间,事件日历中的
第 2 个条目是终止时间。

EC 列将随着事件类型 (ET) 的变化而更新。

LT 只是出租车的列表:

  • 第 0 个条目是状态:“0”是空闲,“1”是忙
  • 第一个和第二个条目是所述到达出租车的 x 和 y 坐标
  • 第三个条目是该出租车的 ID

同样适用于 LC,但第 3 和第 4 项表示客户想去的目的地。

当客户到达时,要么他/她立即得到匹配,要么我为他们分配对应的耐心时间和如下所示的事件:[5,0,id_customer]。如果客户在他们的耐心时间到期之前没有匹配到司机,那么算法会在那之后删除他们。

我相信我的问题发生在ET == 7. 因此,出租车 54 应该将 43 带到他/她的目的地,然后根据 min_distance 重新匹配到客户 45 或 46(我选择欧几里德距离和 min_distance 为任意值)。无论哪一个匹配,算法都会删除客户的耐心时间,这是一个[5,0,45][5,0,46](但不是两个,因为如果你查看出租车列表,只有一辆出租车,两者都不能匹配到一辆出租车)。

抱歉,这篇文章很长,如果没有上述所有细节,我无法解释。谢谢阅读

4

0 回答 0