Double summation

1,553 views
Skip to first unread message

Feras Matar

unread,
Oct 20, 2015, 3:42:22 PM10/20/15
to AMPL Modeling Language





Hi,


Please how can I write the following in AMPL

 

I tried several times but always there is an error

victor.z...@gmail.com

unread,
Oct 20, 2015, 8:13:36 PM10/20/15
to am...@googlegroups.com
If this is a constraint then something like

s.t. c{k in K, s in S}: sum{i in 1..n, j in F[i]} q[i, s] * a[j, k] * x[i, j] >= R[k, s];

provided that all the entities are declared accordingly and F(i) can be represented as an indexing set.

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.

Feras Matar

unread,
Oct 21, 2015, 6:10:19 AM10/21/15
to am...@googlegroups.com
Thank you; it is working

But as you can seen in the formula that summation over j comes before i. and you stated i before j

will this make a difference in model or not ?

Thanks

--
You received this message because you are subscribed to a topic in the Google Groups "AMPL Modeling Language" group.
To unsubscribe from this topic, visit https://groups.google.com/d/topic/ampl/sHNEp-Vru5g/unsubscribe.
To unsubscribe from this group and all its topics, send an email to ampl+uns...@googlegroups.com.

victor.z...@gmail.com

unread,
Oct 21, 2015, 11:36:45 AM10/21/15
to am...@googlegroups.com
I'd say it's a sloppy use of mathematical notation, because a symbol should be introduced before it's used. AMPL being a programming language is more strict in this respect. Otherwise summation order makes no difference.

HTH,
Victor

Feras Matar

unread,
Oct 21, 2015, 12:19:36 PM10/21/15
to AMPL Modeling Language
Thank you to much

since the the x variables have (i*j) variables (here i = 25,j = 411), when I solve the model only a part of the utput appeared in the AMPL window)

How to export the output to an excel file or text file ? (please give me the command for that; I did not understand what is written in AMPL manual)

So, it will be better if you give me the command directly instead of giving me the reference for that

victor.z...@gmail.com

unread,
Oct 22, 2015, 3:54:48 PM10/22/15
to am...@googlegroups.com
This have already been answered here: https://groups.google.com/d/msg/ampl/0FV5GJBkyDI/fODmqeigAQAJ

- Victor

Ruonan Zhao

unread,
Apr 3, 2023, 6:02:09 PM4/3/23
to AMPL Modeling Language
Hi all, 
Can anyone please kindly help below. I need to do double summation but index l should not equal to k. Below is what I write but seems wrong.  Do you have any suggestions? Thanks!

sum {k in K,l in K diff {k}} y[k,l]

Best,
Ruonan

AMPL Google Group

unread,
Apr 4, 2023, 10:20:57 PM4/4/23
to AMPL Modeling Language
I did a little test where I set K equal to {1,2,3,4,5} and assigned some random numbers to y. Your sum was evaluated without any errors:

ampl: set K := 1..5; 
ampl: var y {K,K} := Uniform01(); 

ampl: display sum {k in K, l in K diff {k}} y[k,l]; 
sum{k in K, l in K diff {k}} y[k,l] = 9.30924 

However, some other error in your model might be causing an error when you use this expression. To get more help, reply with a complete example that we can run to reproduce the error message.


--
Robert Fourer

We're switching to a new, enhanced user forum.
Join it now at discuss.ampl.com.
{#HS:2203350787-115715#}
On Mon, Apr 3, 2023 at 10:02 PM UTC, AMPL Modeling Language <am...@googlegroups.com> wrote:
Hi all,
Can anyone please kindly help below. I need to do double summation but index l should not equal to k. Below is what I write but seems wrong. Do you have any suggestions? Thanks!

sum {k in K,l in K diff {k}} y[k,l]

Best,
Ruonan

On Tuesday, 20 October 2015 at 14:42:22 UTC-5 Feras Matar wrote:





Hi,


Please how can I write the following in AMPL

Model%2BImage.PNG

I tried several times but always there is an error

--
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.
Reply all
Reply to author
Forward
0 new messages