[AMPL 2901] Summation Index Notation for i > j

View: New views
5 Messages — Rating Filter:   Alert me  

[AMPL 2901] Summation Index Notation for i > j

by Emily Heeb :: Rate this Message:

Reply to Author | View Threaded | Show Only this Message


I have a quick syntax question regarding AMPL programming. If I have a
set, say {profit} and I want to do an operation such as:


 sum {j in profit, i in profit} 2 * Covariance [j,i]

but ONLY for j > i.

How do I incorporate this constraint into the model?

--~--~---------~--~----~------------~-------~--~----~
You received this message because you are subscribed to the Google Groups "AMPL Modeling Language" group.
To post to this group, send email to ampl@...
To unsubscribe from this group, send email to ampl+unsubscribe@...
For more options, visit this group at http://groups.google.com/group/ampl?hl=en
-~----------~----~----~----~------~----~------~--~---


[AMPL 2902] Re: Summation Index Notation for i > j

by pietro belotti :: Rate this Message:

Reply to Author | View Threaded | Show Only this Message


Try

sum {j in profit, i in profit: j > i} 2 * Covariance [j,i]

Best,
P

On Oct 21, 11:10 pm, Emily Heeb <emily.h...@...> wrote:
> I have a quick syntax question regarding AMPL programming. If I have a
> set, say {profit} and I want to do an operation such as:
>
>  sum {j in profit, i in profit} 2 * Covariance [j,i]
>
> but ONLY for j > i.
>
> How do I incorporate this constraint into the model?
--~--~---------~--~----~------------~-------~--~----~
You received this message because you are subscribed to the Google Groups "AMPL Modeling Language" group.
To post to this group, send email to ampl@...
To unsubscribe from this group, send email to ampl+unsubscribe@...
For more options, visit this group at http://groups.google.com/group/ampl?hl=en
-~----------~----~----~----~------~----~------~--~---


[AMPL 2903] Re: Summation Index Notation for i > j

by Gideon-12 :: Rate this Message:

Reply to Author | View Threaded | Show Only this Message


One labourious way is in the way you treat your data i.e. remove
symmetry by entrying zero values on the other side of the diagonal and
allow your sum over the entire metric

/Gideon

Emily Heeb skrev:

> I have a quick syntax question regarding AMPL programming. If I have a
> set, say {profit} and I want to do an operation such as:
>
>
>  sum {j in profit, i in profit} 2 * Covariance [j,i]
>
> but ONLY for j > i.
>
> How do I incorporate this constraint into the model?
>
> >
>
>  


--
Gideon Mbiydzenyuy
PhD Candidate, e-Transactions,

Avdelningen för programvarusystem,   Dept. of Systems and Software Eng.,
Sektionen för teknik                 School of Engineering,
Blekinge Tekniska Högskola           Blekinge Institute of Technology

                        Box 214
                        SE - 374 24 Karlshamn
                        Sweden

                        Tel: +46 454 385904 (Karlshamn)
                        Tel: +46 457 385897 (Ronneby)
                        Mob: +46 768 856713
                        Fax: +46 454 191 04 (Karlshamn)
                        Homepage: http://www.bth.se/tek/gmb


--~--~---------~--~----~------------~-------~--~----~
You received this message because you are subscribed to the Google Groups "AMPL Modeling Language" group.
To post to this group, send email to ampl@...
To unsubscribe from this group, send email to ampl+unsubscribe@...
For more options, visit this group at http://groups.google.com/group/ampl?hl=en
-~----------~----~----~----~------~----~------~--~---


[AMPL 2906] Re: Summation Index Notation for i > j

by Vikas Phanse :: Rate this Message:

Reply to Author | View Threaded | Show Only this Message

How about defining set as follows:

{ j in profit, i in profit: j>i}



--- On Thu, 10/22/09, Gideon <gideon.mbiydzenyuy@...> wrote:

From: Gideon <gideon.mbiydzenyuy@...>
Subject: [AMPL 2903] Re: Summation Index Notation for i > j
To: ampl@...
Date: Thursday, October 22, 2009, 7:27 AM


One labourious way is in the way you treat your data i.e. remove
symmetry by entrying zero values on the other side of the diagonal and
allow your sum over the entire metric

/Gideon

Emily Heeb skrev:

> I have a quick syntax question regarding AMPL programming. If I have a
> set, say {profit} and I want to do an operation such as:
>
>
>  sum {j in profit, i in profit} 2 * Covariance [j,i]
>
> but ONLY for j > i.
>
> How do I incorporate this constraint into the model?
>
> >
>
>   


--
Gideon Mbiydzenyuy
PhD Candidate, e-Transactions,

Avdelningen för programvarusystem,   Dept. of Systems and Software Eng.,
Sektionen för teknik                 School of Engineering,
Blekinge Tekniska Högskola           Blekinge Institute of Technology

            Box 214
            SE - 374 24 Karlshamn
            Sweden

            Tel: +46 454 385904 (Karlshamn)
            Tel: +46 457 385897 (Ronneby)
            Mob: +46 768 856713
            Fax: +46 454 191 04 (Karlshamn)
            Homepage: http://www.bth.se/tek/gmb



--~--~---------~--~----~------------~-------~--~----~
You received this message because you are subscribed to the Google Groups "AMPL Modeling Language" group.
To post to this group, send email to ampl@...
To unsubscribe from this group, send email to ampl+unsubscribe@...
For more options, visit this group at http://groups.google.com/group/ampl?hl=en
-~----------~----~----~----~------~----~------~--~---


[AMPL 2938] Re: Summation Index Notation for i > j

by dbwork :: Rate this Message:

Reply to Author | View Threaded | Show Only this Message


Unfortunately, the last solution may not work if profit was defined as
a set in the model file, ie:
set profit;
{ j in profit, i in profit: j>i}  # will not work

since a set has no order.  Instead, the set needs to be ordered.

set profit ordered # use the ampl keyword ordered

Then you can use the ord() function to do the comparison:

{ j in profit, i in profit: ord(j)>ord(i)}

This should do the trick.

Cheers,
Dan


On Oct 22, 4:15 pm, Vikas Phanse <phanse...@...> wrote:

> How about defining set as follows:
>
> { j in profit, i in profit: j>i}
>
> --- On Thu, 10/22/09, Gideon <gideon.mbiydzen...@...> wrote:
>
> From: Gideon <gideon.mbiydzen...@...>
> Subject: [AMPL 2903] Re: Summation Index Notation for i > j
> To: ampl@...
> Date: Thursday, October 22, 2009, 7:27 AM
>
> One labourious way is in the way you treat your data i.e. remove
> symmetry by entrying zero values on the other side of the diagonal and
> allow your sum over the entire metric
>
> /Gideon
>
> Emily Heeb skrev:
>
> > I have a quick syntax question regarding AMPL programming. If I have a
> > set, say {profit} and I want to do an operation such as:
>
> >  sum {j in profit, i in profit} 2 * Covariance [j,i]
>
> > but ONLY for j > i.
>
> > How do I incorporate this constraint into the model?
>
> >   
>
> --
> Gideon Mbiydzenyuy
> PhD Candidate, e-Transactions,
>
> Avdelningen för programvarusystem,   Dept. of Systems and Software Eng.,
> Sektionen för teknik                 School of Engineering,
> Blekinge Tekniska Högskola           Blekinge Institute of Technology
>
>             Box 214
>             SE - 374 24 Karlshamn
>             Sweden
>
>             Tel: +46 454 385904 (Karlshamn)
>             Tel: +46 457 385897 (Ronneby)
>             Mob: +46 768 856713
>             Fax: +46 454 191 04 (Karlshamn)
>             Homepage:http://www.bth.se/tek/gmb

--~--~---------~--~----~------------~-------~--~----~
You received this message because you are subscribed to the Google Groups "AMPL Modeling Language" group.
To post to this group, send email to ampl@...
To unsubscribe from this group, send email to ampl+unsubscribe@...
For more options, visit this group at http://groups.google.com/group/ampl?hl=en
-~----------~----~----~----~------~----~------~--~---