amplneos-server

AMPL: Model terminals within a destination city


I've encountered a problem which I have not found any solution to reading the AMPL documentation of sets.

What I want to model is that a city, say Kir, must have for instance 9 deliveries from another city, for instance Sto. However, these deliveries must arrive in Kir at some specific terminals, each terminal being open only for a small amount of time (approx 2 minutes) each day. The same must be true for the origin node. The route from Sto must be specified from a specific terminal (so the path can be "followed" in the results).

I've started to model using the "set V within K" operation for sets, but that requires that V must be the same set, or a subset of K where K is the set representing the "nodes" - Kir, Sto and so on and V is the set of names of the terminals "Terminal1", "Terminal2" etc.

I've started to check for instance "set K dimension 4" defined as for instance:

 set K dimension 4;

 data;

 set K:=
 Sto Kir Terminal1 Terminal2
 Bod Kir Terminal3 Terminal2;

Where set K represents from which city (for example Sto) a delivery should be driven (to for example Kir), where the departing terminal in Sto is Terminal1 and the delivering terminal in Kir is Terminal2. This has the downside of having to specifiy a large number of combinations (there are approximately 22 terminals in Kir alone etc) manually. I don't know how to model the constraints then either. For instance the "one dimension" set I've previously had:

subject to yvar{i in V, j in V}:
    sum{k in H} x[i,j,k] <= maxVisits[i,j];

where V is the set of cities alone, and H is the set of vehicles, maxVisits represents the maximum amount of deliviries from city i to city j and x is 1 if a delivery is made from i to j using vehicle k. I don't understand how this could be modeled, using the four dimensional set K.

Regards,


Solution

  • One way to model this is to index x over K and H and change the summation to include terminals:

    var x{K, H} binary;
    subject to yvar{i in V, j in V}:
      sum{(i,j,t,u) in K, k in H} x[i,j,t,u,k] <= maxVisits[i,j];
    

    The indexing (i,j,t,u) in K in the summation will iterate over pairs of terminals that are endpoints of routes from city i to city j. Note that i and j are fixed here because they are defined in the constraint indexing {i in V, j in V}.