OR工具:根据python中另一个维度的积累添加一个维度(特别是每使用24小时的车辆成本)



我想为车辆使用的每24小时添加一个固定成本(使用python版本的OR工具(。不过,我不知道该怎么做。

我从James E.Marca那里收到了一个解决方案的想法(链接:https://groups.google.com/g/or-tools-discuss/c/zEZ8PaMsV6g/m/W5KwdQN3AAAJ)

"正如您所发现的,您不能在python中使用依赖维度。

我建议创建一个明确的日常成本维度。有规律的节点将零添加到成本维度,但创建一个伪"0";"一天结束";节点,每辆车每天一个,这会增加您的日常成本。所以处理回调函数中的此逻辑(如果不是一天结束节点,返回零,否则返回每日成本(。

然后通过以下方式将所有一天结束的节点添加到解算器的最小化中使用对的调用路由。AddVariableMinimizedByFinalizer(day_cost_dimension.CumulVar(day_i_vehicle_j_index((

也许这为你指明了正确的方向">

[稍后消息]

我只是在想第1点。我认为你不需要使用额外的成本维度,但可以与您的已经使模型最小化(距离或时间(。

我的意思是创建我所描述的每日节点(每辆车一个每天(,允许它们被丢弃(0的析取(,但需要如果车辆的时间维度大于24小时的倍数。然后计算到每日节点的距离等于你每天要承担的额外费用。

例如,在标准示例中,您有以下内容:

def create_data_model():
"""Stores the data for the problem."""
data = {}
data['distance_matrix'] = [
...
# set distance from all nodes to dummy end-of-day nodes as daily cost
]
...
# Instantiate the data problem.
data = create_data_model()
def distance_callback(from_index, to_index):
"""Returns the distance between the two nodes."""
# Convert from routing variable Index to distance matrix NodeIndex.
from_node = manager.IndexToNode(from_index)
to_node = manager.IndexToNode(to_index)
#
# this next line will correctly add "cost" of visiting end-of-day nodes
# if the data was set up correctly earlier
#
return data['distance_matrix'][from_node][to_node]
transit_callback_index = routing.RegisterTransitCallback(distance_callback)
routing.SetArcCostEvaluatorOfAllVehicles(transit_callback_index) 

相关内容

最新更新