Reputation: 1
hi all currently working on a LP modal using CPLEX
I have an error which is saying the data element has already been set. After searching on the error i get that it will occur when the data existed somewhere, already set but in my case i dont see it therefore need help debugging it. Below will attached two codes to show my .mod and .dat file
.dat file
cellTowers = {0, 1, 2, 3, 4, 5}; // List of possible tower locations
Regions = {0, 1, 2, 3, 4, 5, 6, 7, 8}; // List of regions to cover
Population = [523, 690, 420, 1010, 1200, 850, 400, 1008, 950];
Coverage = [
[1, 1, 0, 0, 0, 1, 0, 0, 0], // Tower 0 coverage
[1, 0, 0, 0, 0, 0, 0, 1, 1], // Tower 1 coverage
[0, 0, 1, 1, 1, 0, 1, 0, 0], // Tower 2 coverage
[0, 0, 1, 0, 0, 1, 1, 0, 0], // Tower 3 coverage
[1, 0, 1, 0, 0, 0, 1, 1, 1], // Tower 4 coverage
[0, 0, 0, 1, 1, 0, 0, 0, 1], // Tower 5 coverage
];
Cost = [4.2, 6.1, 5.2, 5.5, 4.8, 9.2];
// Total budget in millions
Budget = 20;
.mod file
setof(int) cellTowers;
setof(int) Regions;
int Population[Regions];
int Coverage[cellTowers][Regions];
int Cost[cellTowers];
int Budget;
// Decision Variables
dvar boolean x[cellTowers]; // Binary variable: 1 if a tower is built, 0 otherwise
// Objective Function (to maximize coverage of all towers)
maximize sum(t in cellTowers, r in Regions) Population[r] * Coverage[t][r] * x[t];
// Constraints
subject to {
// Budget Constraint
sum(t in cellTowers) Cost[t] * x[t] <= Budget;
// Optional: If specific constraints are needed, like mandatory coverage for certain regions
}
I tried deleting all and using a new .mod and .dat file, copying and paste the exact same code but still getting the same error. Also made sure there is no other files using the same element as well
Upvotes: 0
Views: 22
Reputation: 10062
Since
cellTowers is defined in .dat
In the .mod
Turn
setof(int) cellTowers;
Into
setof(int) cellTowers=…;
Upvotes: 0