[AMPL 2917] Conditions on Sum

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

[AMPL 2917] Conditions on Sum

by enhany75 :: Rate this Message:

Reply to Author | View Threaded | Show Only this Message


Hi,

I am trying to put conditions on a sum but it fails, here is the code
and the error;

sum{k in t2, i in prodk[k],q in seqk[k], b in prodk[k]: b <> i, l in
seqk[k]:l> q} (HRki[k,i]*Dki[k,i] * (Ski[k,b]* Ykiqbl [k,i,q,b,l]+
m1*m2*(Dki[k,b]/Pki[k,b]) * Zkiqbl [k,i,q,b,l]))

syntax error
context:  +sum{k in t2, i in prodk[k],q in seqk[k], b in prodk[k]: b
<>  >>> i, <<<  l in seqk[k]:l> q} (HRki[k,i]*Dki[k,i] * (Ski[k,b]*
Ykiqbl [k,i,q,b,l]+ m1*m2*(Dki[k,b]/Pki[k,b]) * Zkiqbl [k,i,q,b,l]))

could you please help me,
thanks
--~--~---------~--~----~------------~-------~--~----~
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 2919] Re: Conditions on Sum

by pietro belotti :: Rate this Message:

Reply to Author | View Threaded | Show Only this Message


I believe all conditions should be at the end, after the ":". In your
case, I suppose you can also write it this way:

sum{k in t2, i in prodk[k], q in seqk[k], b in prodk[k], l in seqk[k]:
b <> i and l > q}
   (HRki[k,i]*Dki[k,i] * (Ski[k,b]* Ykiqbl
[k,i,q,b,l]+m1*m2*(Dki[k,b]/Pki[k,b]) * Zkiqbl [k,i,q,b,l]))

If this doesn't work, let's suppose there are a set Prod and a set Seq
such that all prodk[k]'s are subsets of Prod and seqk[k]'s are subsets
of Seq. Try re-writing it like this:

sum{k in t2, i in Prod, q in Seq, b in Prod, l in Seq:
       i in prodk[k] and q in seqk[k] and b in prodk[k] and b <> i and
l in seqk[k] and l> q}
   (HRki[k,i]*Dki[k,i] * (Ski[k,b]* Ykiqbl
[k,i,q,b,l]+m1*m2*(Dki[k,b]/Pki[k,b]) * Zkiqbl [k,i,q,b,l]))

Hope this helps.
Regards



On Mon, Oct 26, 2009 at 9:32 PM, enhany75 <enhany75@...> wrote:

>
> Hi,
>
> I am trying to put conditions on a sum but it fails, here is the code
> and the error;
>
> sum{k in t2, i in prodk[k],q in seqk[k], b in prodk[k]: b <> i, l in
> seqk[k]:l> q} (HRki[k,i]*Dki[k,i] * (Ski[k,b]* Ykiqbl [k,i,q,b,l]+
> m1*m2*(Dki[k,b]/Pki[k,b]) * Zkiqbl [k,i,q,b,l]))
>
> syntax error
> context:  +sum{k in t2, i in prodk[k],q in seqk[k], b in prodk[k]: b
> <>  >>> i, <<<  l in seqk[k]:l> q} (HRki[k,i]*Dki[k,i] * (Ski[k,b]*
> Ykiqbl [k,i,q,b,l]+ m1*m2*(Dki[k,b]/Pki[k,b]) * Zkiqbl [k,i,q,b,l]))
>
> could you please help me,
> thanks
> >
>

--~--~---------~--~----~------------~-------~--~----~
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 2921] Re: Conditions on Sum

by enhany75 :: Rate this Message:

Reply to Author | View Threaded | Show Only this Message


Thanks a lot, it works well, conditions should be at the end after ":"
as you mentioned.

On Oct 27, 3:41 am, Pietro Belotti <petr....@...> wrote:

> I believe all conditions should be at the end, after the ":". In your
> case, I suppose you can also write it this way:
>
> sum{k in t2, i in prodk[k], q in seqk[k], b in prodk[k], l in seqk[k]:
> b <> i and l > q}
>    (HRki[k,i]*Dki[k,i] * (Ski[k,b]* Ykiqbl
> [k,i,q,b,l]+m1*m2*(Dki[k,b]/Pki[k,b]) * Zkiqbl [k,i,q,b,l]))
>
> If this doesn't work, let's suppose there are a set Prod and a set Seq
> such that all prodk[k]'s are subsets of Prod and seqk[k]'s are subsets
> of Seq. Try re-writing it like this:
>
> sum{k in t2, i in Prod, q in Seq, b in Prod, l in Seq:
>        i in prodk[k] and q in seqk[k] and b in prodk[k] and b <> i and
> l in seqk[k] and l> q}
>    (HRki[k,i]*Dki[k,i] * (Ski[k,b]* Ykiqbl
> [k,i,q,b,l]+m1*m2*(Dki[k,b]/Pki[k,b]) * Zkiqbl [k,i,q,b,l]))
>
> Hope this helps.
> Regards
>
> On Mon, Oct 26, 2009 at 9:32 PM, enhany75 <enhan...@...> wrote:
>
> > Hi,
>
> > I am trying to put conditions on a sum but it fails, here is the code
> > and the error;
>
> > sum{k in t2, i in prodk[k],q in seqk[k], b in prodk[k]: b <> i, l in
> > seqk[k]:l> q} (HRki[k,i]*Dki[k,i] * (Ski[k,b]* Ykiqbl [k,i,q,b,l]+
> > m1*m2*(Dki[k,b]/Pki[k,b]) * Zkiqbl [k,i,q,b,l]))
>
> > syntax error
> > context:  +sum{k in t2, i in prodk[k],q in seqk[k], b in prodk[k]: b
> > <>  >>> i, <<<  l in seqk[k]:l> q} (HRki[k,i]*Dki[k,i] * (Ski[k,b]*
> > Ykiqbl [k,i,q,b,l]+ m1*m2*(Dki[k,b]/Pki[k,b]) * Zkiqbl [k,i,q,b,l]))
>
> > could you please help me,
> > thanks
>
>
--~--~---------~--~----~------------~-------~--~----~
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
-~----------~----~----~----~------~----~------~--~---