我在 GAMS 中编写了以下代码,它可能不是世界上最好的,但我不明白为什么当它应该是每行正好有 2 个。
请你帮助我好吗?
set
ii set of bays /1*10/
ss set of solutions /1*45/
Parameters
H Number of bays /10/
C Number of cranes /2/
r Safety Margin /1/
p(ii)
pp(ss,ii)
;
p(ii) = 0;
Scalar i; i=1;
Scalar j; j=i;
Scalar k; k=C;
Scalar qq;
Scalar q;
Scalar kk;
Scalar m;
Scalar n;
Scalar stop /0/;
Scalar stop1 /0/;
Scalar stop2 /0/;
Scalar F /1/;
Scalar k1 /0/;
Scalar k2 /0/;
while ((i <= H-(C-1)*r-1*(C-1)),
while((j<=H and stop=0),
if (sum(ii, p(ii)) = C,
stop = 1;
);
loop(ii$(ord(ii)=j),
p(ii) = 1;
);
j = j+r+1;
);
if (sum(ii, p(ii)) = C,
loop((ss,ii)$(ord(ss)=F),
pp(ss,ii) = p(ii);
);
);
F = F+1;
qq=0;
for (q = 1 to H-(C-1)*r-1*(C-1)-1,
loop (ii$((ord(ii) = q) and (stop1 = 0)),
if ((p(ii) = 1) ,
qq=1;
stop1 = 1;
);
);
);
* if (qq=0,
* if (p(ii)$(ord(ii)= H-(C-1)*r-1*(C-1))=1 and p(ii)$(ord(ii)=H) = 1,
* abort "finished";
* );
*
* );
k1 = 0;
k2 = 0;
if(qq=0,
loop(ii$(ord(ii)= H-(C-1)*r-1*(C-1)),
if (p(ii) = 1,
k1 = 1;
);
);
loop(ii$(ord(ii)=H),
if (p(ii) = 1,
k2 = 1;
);
);
abort$(k1 + k2 = 2) "Finished";
);
if (j-r-1 = H,
loop(ii$(ord(ii)=H-(C-k)*r-(C-k)) ,
if(k = C,
k = k-1;
elseif (p(ii)= 1),
k = k-1;
);
);
if(k=1,
loop(ii,
p(ii)=0;
);
i = i+1;
j = i;
k = C;
else
loop(ii$(ord(ii)=H),
p(ii) = 0;
);
m=1;
n=0;
while((n<k),
loop(ii$(ord(ii)=m),
if(p(ii) = 1,
n = n+1;
);
m = m+1;
);
);
loop(ii$(ord(ii) = m-1),
p(ii) = 0;
);
loop(ii$(ord(ii) = m),
p(ii) = 1;
);
j = m+r+1;
);
else
loop(ii$(ord(ii) = j-r-1),
p(ii)=0;
);
loop(ii$(ord(ii) = j-r),
p(ii)= 1;
);
j=j+1;
);
);
Display pp;