| 1 | initial version |
With a bit of effort, due to how Python handles lambda functions, I found a way. Given the above set-up, the following code returns a list of constraints for n variables:
from itertools import chain
def constraints(n):
def lb(i):
return lambda p: lower_bound(p[i])
def ub(i):
return lambda p: upper_bound(p[i])
return list(chain([c1], *map(lambda i: [lb(i), ub(i)], range(n))))
Copyright Sage, 2010. Some rights reserved under creative commons license. Content on this site is licensed under a Creative Commons Attribution Share Alike 3.0 license.