Thank you so much for your reply!
I was indeed mostly struggling with the creation of the distance matrix in the .dat file. I was wondering how to correctly indicate which distance is linked to which vehicle so far I have (unsuccessfully) tried several options such as:
d=[
[vehicle 1 dist1 dist 2 dist 3 etc.],
[vehicle 2 dist1 dist 2 dist 3 etc.],
or
d[1]=[
[dist1 dist 2 dist 3 etc.],
or
d=[
[1][dist1 dist 2 dist 3 etc.],
[2]vehicle 2 dist1 dist 2 dist 3 etc.],
Regarding the u[1]==1, It should be stated for each vehicle as it is the first observation in my dataset and therefore does not include parameters such as the length at the customer but also the distance towards the first point.
I would also like to thank you for the big loop, I had no idea that this was an possibility and it removes an error in a different model I am using!!
------------------------------
Fiona T
------------------------------
Original Message:
Sent: Mon May 25, 2020 01:12 AM
From: Daniel Junglas
Subject: TSP with vehicle selection
Could you be more specific about what your problem is?
Your objective function looks correct to me. So does the distance matrix (or is the question how to create the distance matrix in the .dat file?).
What looks wrong are things lie this:
forall (i in N: v in V)
This should produce an error that "v is not defined". As far as I can tell, you want to loop over all i and all v. This is done using
forall (i in N, v in V)
In your case another option is to wrap the whole constraint section into a big "forall (v in V)", like so:
forall (v in V) {
// What follows is the TSP model for one particular vehicle, namely vehicle v
forall (i in N) sum (j in N) x[v][i][j] == 1;
forall (j in N) sum (i in N) x[v][i][j] == 1;
forall (i,j in N :i != j && j != 1) u[i] + 1 <= u[j] + 10 * (1-x[v][i][j]);
forall ( i in N) x[v][i][i] == 0;
forall (j in N) x[v][j][j] == 0;
}
I am not sure about constraint u[1] == 1. Should this be stated for each vehicle?
------------------------------
Daniel Junglas
------------------------------