Ask Your Question

Revision history [back]

click to hide/show revision 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))))