HI,

I am working on a variant of the CVRP and trying to solve this problem with different sub-tour elimination constraints. In the OPL-CPLEX it is straightforward to do that, but in DoCplex I have some issues. The problem is:

```
Nodes = ["depot", "node1", "node2", "node3", "node4", "node5"];
Nodes_1 = ["node1", "node2", "node3", "node4", "node5"];
Vehicles = ["v1", "v2"];
depots = ["depot"]
I = range(len(Nodes))
J = range(len(Nodes))
I_1 = range(len(Nodes_1))
J_1 = range(len(Nodes_1))
P = range(len(Nodes))
K = range(len(Vehicles))
I_2 = range(len(depots))
J_2 = range(len(depots))
capacity = [5, 5]
demand = [0, 1, 1, 1, 1, 1]
cost = [
[1000,13,11,12,11,12],
[13,1000,10,13,14,12],
[11,10,1000,12,13,15],
[12,13,12,1000,15,15],
[11,14,13,15,1000,13],
[12,12,15,15,13,1000]
]
for i in I:
if(i>0):
for j in J:
if(j>0):
for k in K:
if(i!=j):
mdl.add_constraint(u[i] - u[j] + (5*x[(i,j,k)]) <= (5-demand[i]), "c6")
```

I have defined different subsets to do the appropriate filtering, but when the problem is run the following error is rising:

```
---------------------------------------------------------------------------
KeyError Traceback (most recent call last)
<ipython-input-50-5c1f8a616afd> in <module>()
54 for k in K:
55 if(i!=j):
---> 56 mdl.add_constraint(u[i] - u[j] + (5*x[(i,j,k)]) <= (5-demand[i]), "c6")
57
58 # The solve section
KeyError: 5
```

Also, writing the above constraint as follows still results the different solutions:

```
for i,i1 in enumerate(I_1):
for j in J_1:
for k in K:
if(i!=j):
mdl.add_constraint(u[i] - u[j] + (5*x[(i,j,k)]) <= (5-demand[i1]), "c6")
```

The sub-tour I am trying to write is a special case of the MTZ and defined as:

```
forall i,j in Nodes and i,j >1 and i!=j;
u[i] - u[j] + A*x(i,j,k) <= A-demand(i)if(demand[i]+demand[j] < A);
```

Would you please, how we can fix that?

Best regards

------------------------------

Abbas Omidi

------------------------------