CyLP
CyLP copied to clipboard
Summing over axis
First off, thank you for a wonderful, wonderful tool. CyLP has saved me so much time already :+1:
I may well be doing things wrong, but I often find myself wishing I could write constraints like
s += my_binary_matrix.sum(axis = 1) == 1
but it appears that the variables' sum()
function doesn't support it. Is there another way of expressing sums across a subset of dimensions (that doesn't require writing loops)?
@skosch Have you found a solution for this type of constraint? I'm facing a similar problem
Hmm, looking back at this now, if I understand correctly, this could be accomplished just by taking a dot product of the vector of variables with a single row of the constraint matrix.
s += a*x == 1
where a
is the row you want to use for generating the constraint. I imagine that taking a slice of the matrix should work, but I'd have to play around to see the best way of accomplishing what you're trying to accomplish.