我正在开发一个启发式的车辆路径问题(VRP)的变化,并希望提高计算运行时间。你知道吗
目前,该解决方案存储为一个字典,其中车辆ID作为密钥,列表中包含客户ID作为值。客户id的序列表示访问序列。 主要的问题是这个解决方案被操纵了很多次(客户改变了位置和/或车辆),我不得不多次迭代这个解决方案来评估这个解决方案。你知道吗
解决方案示例如下:
s = {}
s['v1'] = ['c1', 'c2', 'c3', 'c4']
s['v2'] = ['c5', 'c6']
s['v3'] = ['c7', 'c8', 'c9']
我知道标准的python字典和列表不是最快的选择,我猜在numpy或pandas中有更好的选择。 我遇到了下面的选项,其中dict被转换为df:
df=pd.DataFrame.from_dict(d,orient='index').transpose()
但是,在df列中建模客户序列并不能保持列表的灵活性。你知道吗
你有什么建议可以保留现有的结构吗?你知道吗
作为替代方案,我考虑将structore更改为一个3D二进制矩阵,用于标识客户和车辆分配的顺序。你知道吗
有关使用“解决方案”执行的操作的附加信息:
总体目标是通过多次迭代来改进解决方案,将单个或多组客户从车辆路线中移除并插入其中。目前,这是通过python列表操作符pop()、remove()、insert()完成的。 为了决定要移动哪些客户或在最后计算解决方案的值,启发式方法使用evaluate()函数(以下版本是一个简化的示例,其中计算每个客户的到达时间,如果车辆迟到,则给出惩罚):
def evaluate(s, vehicleData, customerData):
# set objective value == 0:
obj_val = 0
# Iterate over all vehicles
for vehicleId, customerList in s.items():
# set the current time equal to the start time of the vehicle:
t_current = vehicleData[vehicleId]['twStart']
# Iterate over the customers in each vehicle route:
for customer in customerList:
# If a vehicle arrives at customer location after the visitation time is over, add a penalty:
if t_current > customerData[customer]['twEnd']:
obj_val -= 100000
# Set t_current == twStart[job] if vehicle is too early:
if t_current < customerData[customer]['twStart']:
t_current = customerData[customer]['twStart']
# Add time per job (tpj) to t_current:
t_current += customerData[customer]['tpj']
return obj_val
vehicleData和customerData是数据帧。你知道吗
目前没有回答
相关问题 更多 >
编程相关推荐