我的代码中出现语法错误,是否有人可以帮助我?
set surgery;
set OOR;
set OR{surgery};
set surgeon ordered;
set aa{surgeon};
param S>0;
param time{i in surgery}>=0;
#param aa{i in surgery}>=0;#病人对应的医生
var st{i in surgery,m in OR[i]}>=0;
var et{i in surgery,m in OR[i]}>=0;
var x{i in surgery,m in OR[i]} integer binary;
#var y{i in surgery,a in stage, b in stage:a<>b} binary;
var z{c in surgeon,k in aa[c],l in aa[c],m in OR[k],n in OR[l]:k>l or k<l} binary;
var n{i in surgery,k in surgery,m in OR[i] inter OR[k]:k>i or k<i} binary;
var C;
minimize t:C;
subject to seven{i in surgery,m in OR[i]}:
st[i,m]+time[i]*x[i,m]<=C;#目标
subject to choose{i in surgery}:
sum{m in OR[i]}x[i,m]=1;#至少选择一个
subject to time2{i in surgery,j in OR[i]}:
et[i,j]=st[i,j]+time[i]*x[i,j];#et计算公式
subject to OR1{i in surgery,k in surgery,m in OR[i] inter OR[k]:k>i}:
et[i,m]-st[k,m]<=S*n[i,k,m];
subject to OR2{i in surgery,k in surgery,m in OR[i] inter OR[k]:k>i}:
et[k,m]-st[i,m]<=S*(1-n[i,k,m]);
subject to doctor1{c in surgeon,k in aa[c],l in aa[c],m in OR[k],n in OR[l]:k>l}:
et[l,n]-st[k,m]<=S*z[c,k,l,m,n];
subject to doctor2{c in surgeon,k in aa[c],l in aa[c],m in OR[k],n in OR[l]:k>l}:
et[k,m]-st[l,n]<=S*(1-z[c,k,l,m,n]);
以上是我的代码,我收到了一条消息:
4.mod,第37行(抵消1067): 语法错误
并且第37行是:受医生1 {c在外科医生中,k在aa [c]中,l在aa [c]中,m在OR [k]中,n在OR [1]中:k> l}:
谁能说出原因?非常感谢你!
答案 0 :(得分:0)
您已将n定义为程序第15行的索引变量。现在你在约束定义中指的是n。我猜它不应该和你作为变量创建的那个“n”相同。在任何情况下,都不允许在像这样的约束的索引中使用变量,因此AMPL会给出错误消息。
AMPL“语法错误”消息对于找出此类问题的原因并不是很有帮助。有一件事给我一个线索,即使“m in OR [k]”部分与“l in OR [l]”具有完全相同的格式并出现在它之前,那一个不会触发错误信息。
{c in surgeon,k in aa[c],**m in OR[k]**,l in aa[c],**n in OR[l]**: k>l}
我试过交换k&amp; m与l&amp; amp; n条款:
{c in surgeon,l in aa[c],n in OR[l],k in aa[c],m in OR[k]: k>l}
并且错误仍与“OR [1]中的n”相关联。这很清楚,n或l都有一些特别的东西,所以我去了程序的其他地方,注意到你已经宣布了n。
(顺便说一下,这是使用有意义的变量名称而不是仅仅调用“n”和“aa”的好理由......)