I'm doing a model at the moment which I need to adjust in quite a big way. Basically I need to extend my current set V which is a set of cities to become a set of cities and time. For instance, the element Kir in V must be extended from simply "Kir" to "Kir1", "Kir2",...,"Kir72" to represent the city Kir as well as the time frame specified by the number.
I've started to define this as (in the .mod file): set V; set K within V;
and in the .dat file I'm quite unsure of how to write this. If there is no simple way of including the "string" Kir in the set K, I'll guess I'm going to write:
set V := 1 2 3 4 5;
set K := 1 2;
for instance. My question is how do I do this? Can I include the city name Kir? And specifically I've defined a pivot table of distances between the cities in the original V set. The distances in the original set V between, say, the cities Kir and Sto must be the same as the distance between Kir1 and Sto1 in the extended set. It must also be the same distance between Kir1 and Sto72. The original distance must be the same that is, independent of which time frame it is. Is there a simple way of doing this within AMPL?
EDIT: Added the tag Python. I would guess this can be achieved in Python as well. I've managed to define the new sets, using:
text = 'Kir'
string2 = [i for i in range(1,49)]
for i in string2:
print (text+str(i))
for instance. I'm stuck in regards to the distance matrix though
Although you can build a set by concatenating city name and time, I think it's better to use a two-dimensional set with the first index representing city and the second time:
set K dimen 2;
data;
set K :=
Kir 1
Kir 2
Kir 3;
The set K
will contain pairs ('Kir', 1)
, ('Kir', 2)
, ('Kir', 3)
.