Hi,
I'm new with the yalmip, so i want to to solve a in binary problem (the fixed charge location problem/warehouse location problem see the annex for the cplex model of this problem) The question is : is it possible to use a loop on variable when constructing identical constraints to simplify the constraint construction ? (see constraint 3)
this example is my first try with yalmip i hope it's easy to understand...
All comments are welcome to improve my model
Example :
Parameters:
fj = [5 6]; %Cost of server
cj = [12 13];%capacity of server
cj1 = diag(cj);%diagonal of server capacity
dij=[1 4;2 4;3 1;5 2];%distance from server j to client i
hi=[2;4;2;4];%client i demand
hi1=diag(hi);%diagonal of the demand
alpha=1;%travel cost
a1=ones(1,2);
b1=ones(4,1);
%variables
y = binvar(4,2); %client i is served by server j
x = binvar(2); %locate a server at j then x=1 else 0
%constraint
Contraints = [y*b1==b1, y'*hi1-cj1*x<=0, y(i,j)-x(j) <=0];
%constraint 1: y*b1==b1 cover all the point of demand
%constraint 2: y'*hi1-cj1*x<=0 contraint of capacity limitation
%constraint 3: y(i,j)-x(j) for each i and j
obj=fj*cj+alpha*sum(sum((hi1*y)'*dij));
solvesdp(Contraints,obj);
Cplex version:
int Fixed = ...;
{string} Warehouses = ...;
int NbStores = ...;
range Stores = 0..NbStores-1;
int Capacity[Warehouses] = ...;
int SupplyCost[Stores][Warehouses] = ...;
dvar boolean Open[Warehouses];
dvar boolean Supply[Stores][Warehouses];
minimize
sum( w in Warehouses )
Fixed * Open[w] +
sum( w in Warehouses , s in Stores )
SupplyCost[s][w] * Supply[s][w];
subject to{
forall( s in Stores )
ctEachStoreHasOneWarehouse:
sum( w in Warehouses )
Supply[s][w] == 1;
forall( w in Warehouses, s in Stores )
ctUseOpenWarehouses:
Supply[s][w] <= Open[w];
forall( w in Warehouses )
ctMaxUseOfWarehouse:
sum( s in Stores )
Supply[s][w] <= Capacity[w];
}