Problem!!

Mike C. Fletcher mcfletch at rogers.com
Fri Apr 9 15:03:09 EDT 2004


Balaji wrote:

>Hello everybody..
>
>I have a problem!!!
>
>suppose i want to define
>
>c1=x(i)+y(i)<=b for i in s1 ------------ suppose it is the first
>constraint..
>c2=x(i)+y(i)<=b for i in s2------------- suppose it is the second
>constraint..
>
>now as i is indexed over s1 so is c1.. but what it does is it overites
>the first constraint..
>  
>
You will likely need to define, (preferably with Python code), what you 
are doing, what you are expecting, and what is going wrong (what you 
actually get).  If I'm understanding you correctly, the problem is that 
you want to apply these two constraints to the lists s1 and s2 something 
like:

c1 = [ result for result in [ x(i) + y(i) for i in s1] if result <= b]
c2 = [ result for result in [ x(i) + y(i) for i in s2] if result <= b]

but it could just as readily be that you want:

c1 = [ (x(i)+y(i)<=b) for i in s1 ]
c2 = [ (x(i)+y(i)<=b) for i in s2 ]

just to be clear, that expression will yield a list of True/False 
values, i.e. whether the sum of the results of the two functions on i is 
less than b.  Adding brackets around the first part of the expression:

( x(i)+y(i) ) <= b

will help maintainers of the code by eliminating the need for them to 
verify the order of operations.

Good luck,
Mike

_______________________________________
  Mike C. Fletcher
  Designer, VR Plumber, Coder
  http://members.rogers.com/mcfletch/






More information about the Python-list mailing list