I have a vehicle routing problem solved by linear programming, but I'm confused about the constraints (see the model in figure 1). In the model, $u$ and $x$ are decision variables, and we set node $0$ as the depot, nodes $1$ to $n$ as customers. Constraints 1 & 2 indicate that there can only be one edge for both going into and out of the CUSTOMER nodes. However, when I use Gurobi optimizer to solve it, I find the solution always includes the depot (node $0$. See a solution in figure 2). Even I set the depot to an extremely far location (figure 3), the depot is still in the solution. Theoretically, to minimize the objective function, if there are no constraints about the edges into and out of the depot, then $x_{0i}$ and $x_{i0}$ should always be 0. The constraints about the depot can be like $\sum x_{i0} \ge 1$, but there are no such constraints in the model.
This is the code used for adding constraints:
mdl.addConstrs( # mdl is the name of the model
quicksum(x[i, j] for j in V if j != i) == 1 for i in N) # only one edge into customer node i
mdl.addConstrs(
quicksum(x[i, j] for i in V if i != j) == 1 for j in N) # only one edge out of customer node i
mdl.addConstrs((x[i, j] == 1) >> (u[i] + q[i] == u[j]) for i, j in A if i != 0 and j != 0)
mdl.addConstrs(u[i] >= q[i] for i in N)
mdl.addConstrs(u[i] <= Q for i in N)
Now I'm confident that my code is not problematic (if anyone want to check it I've put it on my Github: https://github.com/KaiyuWei/VRP-problem-by-Gurobi--Python), then could anyone explain the reason why the depot is always included? Thanks!
q !=0
, Is it possible for you to have, e.g.,u1 + q1 = u2
ANDu2+q2=u1
(that is to sayx[1,2]
andx[2,1]
both are 1) ? If not, then even though you excluded node 0 in the subtour, you still have them in the flow balance and since a constraint of the form above that I wrote is not possible, then the model chooses to assign a 1 to a variable that enters/leaves the depot. $\endgroup$