CVRP,无需访问每个节点

时间:2019-05-08 11:17:57

标签: linear-programming cplex simplex vehicle-routing docplex

我有一个用于容量车辆路径模型的线性模型。现在,我想限制活动边缘的最大数量,这将导致无法访问每个节点这一事实。但是,每条路线应在站点(节点0)处开始和结束。我有以下模型:

输入:

n = Number of Clients
N = List of Nodes
V = List of nodes plus depot
Q = Vehicle Capacity
q = Demands per Client Dictionary

A = All Possible Roads (eg. [(0,1),(1,2),(2,3),(3,0),(2,0)])
c = All Distances Dictionary (eg. {(0, 1): 90, (1,2): 50, …})

型号:

mdl = Model('CVRP')

x = mdl.binary_var_dict(A, name='x')
u = mdl.continuous_var_dict(N, ub=Q, name='u')

# Objective: Maximize Profit (profit - cost)
mdl.maximize(mdl.sum(q[i]*x[i,j] - c[i,j]*x[i,j] for i,j in A))

# (1) Constraints: Make sure end once in each node
mdl.add_constraints(mdl.sum(x[i,j] for j in V if j!=i) == 1 for i in N)

# (2) Constraints: Make sure leave each node once
mdl.add_constraints(mdl.sum(x[i,j] for i in V if i!=j) == 1 for j in N)

# (3) Constraints: Fill of container is waste current contianer + past containers
mdl.add_indicator_constraints(mdl.indicator_constraint(x[i,j], u[i]+q[j]==u[j]) for i,j in A if i!=0 and j!=0)

# (4) Constraints: Have to take all waste from a container
mdl.add_constraints(u[i]>=q[i] for i in N)

solution = mdl.solve(log_output=True)

为实现最大活动边缘的约​​束,我添加了以下约束:

# (5) Constraint: Set maximum of active edges
mdl.add_constraint(mdl.sum(x[i,j] for i,j in A) <= 6)

因此,我应该在约束(1)和(2)中将'=='运算符调整为'<='。但是,结果是节点0(即仓库)也不再强制访问。有人可以帮我进一步吗?预先谢谢你!

1 个答案:

答案 0 :(得分:3)

为了强制进出仓库,您不得放松仓库的==。因此,您必须为仓库节点和非仓库节点拆分约束(1)和(2):

# Depot
mdl.add_constraints(mdl.sum(x[0,j] for j in V if j!=i))
mdl.add_constraints(mdl.sum(x[i,0] for i in V if i!=j))
# Non-Depot
mdl.add_constraints(mdl.sum(x[i,j] for j in V if j!=i) <= 1 for i in N if N != 0)
mdl.add_constraints(mdl.sum(x[i,j] for i in V if i!=j) <= 1 for j in N if N != 0)

我并没有考虑太多,但是现在您可能还需要一个约束,该约束要求所有节点的入局选定圆弧数等于出局选定圆弧数。也就是说,如果路由进入一个节点,那么它也必须退出该节点。