Writing this constraint is correct to do?

21 views
Skip to first unread message

ezzati...@gmail.com

unread,
Jun 9, 2017, 4:44:57 PM6/9/17
to AMPL Modeling Language
Hi Guys, I have a problem to write this constraints into AMPL? does anyone can help me?
Thax.


the constraint is 

sum z(r,t-1) <= z(r,t)    for all r

I try to write like this into AMPL, but it gave me syntax error

subject to linking {r in R, t in T}:  sum {t in 1..T} z[r,t-1] <= z[r,t];

Robert Fourer

unread,
Jun 10, 2017, 7:15:09 PM6/10/17
to am...@googlegroups.com
The index t is defined by "subject to linking {r in R, t in T}" so you can't define it again by using "sum {t in 1..T}". I am not sure what constraint you are trying to write, but maybe it is

subject to linking {r in R, t in T}: sum {u in 1..t-1} z[r,u] <= z[r,t];

Use "expand linking;" to see if the constraints are coming out as you expected.

Bob Fourer
am...@googlegroups.com

=======

From: am...@googlegroups.com [mailto:am...@googlegroups.com] On Behalf Of ezzati...@gmail.com
Sent: Friday, June 9, 2017 3:45 PM
To: AMPL Modeling Language
Subject: [AMPL 14174] Writing this constraint is correct to do?

Hi Guys, I have a problem to write this constraints into AMPL? does anyone can help me?

ezzati...@gmail.com

unread,
Jun 19, 2017, 10:59:14 AM6/19/17
to AMPL Modeling Language, 4...@ampl.com
Hi, thanks for your comments:
the constraint is like this:

subject to linking {r in R}:  sum {t in 1..T} z[r,t] >= sum {t in 1..T} z[r,t-1];
 I attached the mathematical form of this as well. (please see attachment). I would appreciate letting me know how can I write it .

Bests/Sattar
hii.PNG

Robert Fourer

unread,
Jun 20, 2017, 11:07:22 AM6/20/17
to am...@googlegroups.com
Your AMPL constraint appears to be a correct representation of the mathematical constraint shown in your attachment.

ezzati...@gmail.com

unread,
Jun 21, 2017, 12:08:44 PM6/21/17
to AMPL Modeling Language, 4...@ampl.com
Hi,

Thanks for your help really:
I try to write down this constraint as you already gave me a hint, could you please take a look on it  

subject to linking {r in R}: sum {t in T} y[r,t] >= sum {r in R, u in 1..t-1} y[r,u]
I attached the math form of the constraint.

Thanks for your consideration.
Sattar
hii.png

Robert Fourer

unread,
Jun 22, 2017, 9:50:07 AM6/22/17
to am...@googlegroups.com
The math form of constraint that you attached, when converted directly to AMPL, looks like this:

subject to matheformconstr {l in A}:
sum {t in T} y[l,t] >= sum {t in T} y[l,t-1];

If you want you can change the name of the set (as in your example):

subject to linking {r in R}:
sum {t in T} y[r,t] >= sum {t in T} y[r,t-1];

I think this is not correct, however; if T is a set of consecutive integers (1, 2, 3, ...), which seems likely, then almost all of the terms on the left also appear on the right, and they will cancel out. So probably you need to study the mathematical form first, to see how to write it correctly. Once you have the correct mathematical form, you can convert it directly to an equivalent AMPL form.
Reply all
Reply to author
Forward
0 new messages