在做一个设置选址问题的CPLEX求解,跟别人的代码逻辑差不多,但是自己的dat文件一直报错
mod文件
int Fixed = ...;
{string}Warehouses=...;
int NbStores=...;
int Scenarios=...;
range Sce=0..Scenarios-1;
range Stores =0..NbStores-1;
int Capacity [Warehouses]=...;
int SupplyCost[Stores][Warehouses][Sce]=...;
float Prob[Sce]=...;
dvar boolean Open[Warehouses];
dvar boolean Supply[Stores][Warehouses][Sce];
minimize
sum(w in Warehouses)
Fixed * Open[w]+
sum (w in Warehouses,s in Stores,x in Sce)
Prob[x]*SupplyCost[s][w][x]*Supply[s][w][x];
subject to
{
forall (s in Stores,x in Sce )
sum (w in Warehouses)
Supply[s][w][x]==1;
}
subject to{
forall( s in Stores ,w in Warehouses,x in Sce)
Supply[s][w][x] <= Open[w];
}
subject to
{
forall(w in Warehouses,x in Sce)
sum(s in Stores)
Supply[s][w][x]<=Capacity[w];
}
Fixed=30;
Warehouses={a,b,c,d,e};
NbStores=10;
Capacity=[1,4,2,1,3];
Scenarios = 3;
Prob= [0.2, 0.3, 0.5];
SupplyCost = [
[
[20, 24, 11, 25, 30],
[28, 30, 82, 83, 74],
[74, 27, 72, 96, 70],
[92, 55, 73, 70, 61],
[49, 96, 59, 83, 44],
[42, 22, 29, 67, 59],
[71, 16, 73, 59, 56],
[10, 73, 13, 43, 96],
[93, 35, 63, 85, 46],
[47, 65, 55, 71, 95]
],
[
[20, 24, 11, 25, 32],
[28, 27, 82, 83, 74],
[74, 97, 70, 96, 70],
[ 2, 55, 73, 69, 61],
[49, 96, 59, 83, 4],
[42, 20, 29, 67, 59],
[ 1, 5, 73, 59, 56],
[10, 73, 13, 43, 96],
[93, 35, 63, 1, 46],
[47, 65, 55, 71, 95]
],
[
[20, 20, 11, 25, 30],
[28, 25, 80, 83, 74],
[74, 97, 70, 96, 70],
[ 2, 56, 73, 69, 61],
[49, 95, 59, 83, 4],
[42, 22, 29, 67, 59],
[ 1, 54, 73, 59, 56],
[10, 73, 13, 43, 96],
[93, 30, 63, 85, 46],
[47, 65, 55, 71, 95]
]];
解决了!
应该按照[Sce][Warehouses][Stores]的顺序来!
你好,我是有问必答小助手,非常抱歉,本次您提出的有问必答问题,技术专家团超时未为您做出解答
本次提问扣除的有问必答次数,将会以问答VIP体验卡(1次有问必答机会、商城购买实体图书享受95折优惠)的形式为您补发到账户。
因为有问必答VIP体验卡有效期仅有1天,您在需要使用的时候【私信】联系我,我会为您补发。