Syntax Error

72 views
Skip to first unread message

Senam Sedzro

unread,
Jun 15, 2015, 10:21:50 AM6/15/15
to am...@googlegroups.com
Hi All,

I encounter the following errors: ''t is undefined" and "j is undefined". I am solving a supply-demand scheduling problem. I indexed the set of demand I and the set of suppliers J. T is the time horizon.

My objective  is to jointly minimize the supplier and consumer costs: 
Min CC+SC ;  

s.t. CC=sum{t in 1..T} sum{i in I} z[i,t]*demand[i,t]*dc[t];
​s.t. SC=sum{t in 1..T} sum{j in J} w[j,t]*supply[j,t]*sc[j,t];​
​. . .

Prior to the objective and the variable definition, I defined the sets and parameters. I don't really know why I am getting these errors for the 2nd constraint.

Thank you for helping me out.​

--
​Senam


victor.z...@gmail.com

unread,
Jun 15, 2015, 11:54:28 AM6/15/15
to am...@googlegroups.com
Hi Senam,

Constraint names are missing from your declarations. here's a corrected declaration (provided that CC, T, etc. are defined appropriately):

  s.t. cc_con: CC=sum{t in 1..T} sum{i in I} z[i,t]*demand[i,t]*dc[t];

where cc_con is the constraint name.

HTH,
Victor

--
You received this message because you are subscribed to the Google Groups "AMPL Modeling Language" group.
To unsubscribe from this group and stop receiving emails from it, send an email to ampl+uns...@googlegroups.com.
To post to this group, send email to am...@googlegroups.com.
Visit this group at http://groups.google.com/group/ampl.
For more options, visit https://groups.google.com/d/optout.

Senam

unread,
Jun 15, 2015, 1:02:33 PM6/15/15
to am...@googlegroups.com
Hi Victor,

Thanks for your answer. In fact, below is the complete form of what I wrote (objective and the 2 constraints):

minimize Total_Cost: alpha*CC+(1-alpha)*GC;

 subject to const01: CC = sum {t in 1..T} (B*(1+Klow*Xlow[t]+Khigh*Xhigh[t])+Ehigh[t]*(1+Khigh)-Elow[t]*(1+Klow))*Cbase;
 subject to const02: GC = sum {t in 1..T} sum {j in J} w[j,t]*Pg[j,t]*C[j]+su[j,t]*SUC[j]; 


Thanks,
Senam

victor.z...@gmail.com

unread,
Jun 15, 2015, 1:14:41 PM6/15/15
to am...@googlegroups.com
You get an error in the second constraint because the sum operator has the same precedence as binary + and addition is left associative, so const02 is equivalent to

  subject to const02: GC = (sum {t in 1..T} sum {j in J} w[j,t]*Pg[j,t]*C[j])+su[j,t]*SUC[j]; 

and therefore j and t are not in scope for the term su[j,t]*SUC[j]. This can be fixed by adding parentheses:

  subject to const02: GC = sum {t in 1..T} sum {j in J} (w[j,t]*Pg[j,t]*C[j]+su[j,t]*SUC[j]); 

HTH,
Victor

Senam

unread,
Jun 16, 2015, 7:21:00 AM6/16/15
to am...@googlegroups.com
Oh.... I see!

Thank you Victor.
It is hard to find these small details.

Thank you so much Victor!

Senam
Reply all
Reply to author
Forward
0 new messages