I am trying to start with IBM ILOG CPLEX but I'm having difficulties with iterations... I have two different lists. The first one has 6 entries (A, B, C, ...) each having arguments (a1, a2, a3, a4, a5, a6), and the second list has about a hundred entries in the form city1(x,y), city2(x2,y2), etc. What I would like is to have an objective function that places 6 decision variables with constraints on arguments 2, 3, 4, 5 of the first list to obtain the shortest possible Manhattan distance with the coordinates of the second list. Is it possible to obtain an optimal solution with this kind of project? And if so, I would appreciate some help with iterations in these tuples.
Thank you very much for your help
///// Constants /////////////////////////////////////////////////////////////////////////////////////////////////////
// Limit for Decision variable
int L=400;
// Number of centers
int N =5;
// upper and lower Bound for x and y coordinates (from areas)
int NA =6; // Number of Areas
float XMIN[1..NA, 1..2] = [ // coordinates x,y of Distribution office (DO)
[51.0, 123.5], // Area A
[112.0, 64.0], // Area B
[183.25, 37.5], // Area C
[231.25, 80.0], // Area D
[216.75, 151.25], // Area E
[111.75, 177.75] // Area F
];
float XMAX[1..NA, 1..2] = [
[118.5, 151.75], // Area A
[185.75, 122.0], // Area B
[263.5, 61.75], // Area C
[269.25, 114.0], // Area D
[245.25, 176.5], // Area E
[153.0, 191.25] // Area F
];
// Costs of lands (from areas)
float cl[1..NA] = [
600, // Area A
700, // Area B
1000, // Area C
200, // Area D
400, // Area E
900 // Area F
];
// Costs of Operations (from areas) !!! To remove
float co[1..NA] = [
18000000, // Area A
20000000, // Area B
25000000, // Area C
17000000, // Area D
15000000, // Area E
16000000 // Area F
];
// Distribution offices positions (From Offices)
int NDO = 42; // Number of Distribution Offices (DO)
float XDO[1..NDO, 1..2] = [ // coordinates x,y of Distribution office (DO)
[85.5, 99.25], // 1.Neuchâtel
[58.0, 152.25], // 2.Lausanne
[25.75, 186.0], // 3.Genève
[108.75,83.5], // 4.Biel
[62.75, 122.25], // 5.Yverdon-Les-Bains
[125.0, 104.5], // 6.Bern
[102.75,118.75], // 7.Fribourg
[98.25, 142.75], // 8.Bulle
[138.75,126.5], // 9.Thun
[154.25,135.0], // 10.Interlaken
[246.75,186.75], // 11.Bellinzona
[228.25,188.75], // 12.Locarno
[280.0, 116.5], // 13.Chur
[213.5, 21.0], // 14.Schaffhausen
[118.75,58.5], // 15.Delémont
[133.0, 76.0], // 16.Solothurn
[146.5, 45.25], // 17.Liestal
[205.75,80.25], // 18.Zoug
[214.5, 109.75], // 19.Altdorf
[185.25,110.0], // 20.Sarnen
[195.25,102.0], // 21.Stans
[189.5, 92.75], // 22.Luzern
[170.75,56.0], // 23.Aarau
[208.0, 58.75], // 24.Zürich
[235.5, 38.5], // 25.Frauenfeld
[270.5, 52.75], // 26.Sankt-Gallen
[265.75,56.5], // 27.Herisau
[275.25,61.25], // 28.Appenzell
[246.5, 95.0], // 29.Glaris
[121.5, 180.75], // 30.Sion
[136.25,37.0], // 31.Basel
[214.5, 97.0], // 32.Schwyz
[282.5, 83.0], // 33.Vaduz
[223.5, 46.25], // 34.Winterthur
[171.0, 173.0], // 35.Brig
[95.25, 197.0], // 36.Martigny
[141.0, 211.0], // 37.Zermatt
[241.0, 207.0], // 38.Lugano
[307.5, 116.25], // 39.Davos
[99.0, 53.5], // 40.Porrentruy
[33.5, 165.5], // 41.Nyon
[204.25,154.0] // 42.Airolo
];
///// decision variables ///////////////////////////////////////////////////////////////////////////////////////////
dvar float+ X[1..L, 1..L]; // X[x,y] Coordinates of centers
dvar boolean D[1..N]; // D[n] Decision to build the centers
dvar boolean C[1..NDO, 1..NDO]; // C[nd] Connections between centers and distribution offices
///// objective Function ///////////////////////////////////////////////////////////////////////////////////////////
minimize sum(i in 1..N) sum(j in 1..NDO) (C[i,j]* (abs(X[i][1] - XDO[i][1]) +(abs(X[j][2]-XDO[j][2])))); //minimize Manathan distance beetween offices and DO
///// constraints//////////////////////////////////////////////////////////////////////////////////////////////////
subject to {
//C1 :A Distribution office [DO] must be connected to one and only one facility.
forall(d in 1..NDO) {
sum(n in 1..N) (C[n,d]) == 1; // Cnd
};
//C2: A connection between a DO and a Center can only happen if the decision to build the center has been taken.
forall(n in 1..N, d in 1..NDO) {
C[n][d] <= D[n];
};
//C3: At least one center must be built
sum(n in 1..N) D[n] >= 1;
//C4: Maximum N center must be built
sum(n in 1..N) D[n] <= N;
//C5: The [x,y] Coordinates of the facility must be greater than the lower bound of the area, for all areas.
forall(n in 1..N) {
X[n,1] >= XMIN[n,1] * D[n];
X[n,2] >= XMIN[n,2] * D[n];
}
//C6: The [x,y] Coordinates of the facility must be lower than the upper bound of the area, for all areas.
forall(n in 1..N) {
X[n,1] <= XMAX[n,1] * D[n];
X[n,2] <= XMAX[n,2] * D[n];
}
}