using the Variable as an index into a Constant

126 views
Skip to first unread message

count...@gmail.com

unread,
Nov 1, 2020, 1:35:41 PM11/1/20
to cvxpy
When I attempted the code below, I got an error about using a non-integral type inside of the brackets. That is was I had wanted to do, though. I expected that the bracket operator on a Constant would have an overload that took a cvxpy primitive. How difficult would it be to make this work? Or maybe there is some other method I should be using? (Note: I know that I can solve my problem this with a boolean mask; I have that working at present. I was just looking for an exponential decrease in variable count.)

A = cvxpy.Constant(my_long_data_vector)
x = cvxpy.Variable(x_len, integer=True)
... add some constraints on x ...
objective = cvxpy.Minimize(A[x[0]]+A[x[1]]...)

Steven Diamond

unread,
Jan 10, 2021, 2:11:35 PM1/10/21
to cvxpy
What you're trying to do with indexing is fundamentally not possible in cvxpy. There may be some workaround involving matrix multiplication (where one multiplicand is a variable), but definitely nothing where you index with the value of a variable.
Reply all
Reply to author
Forward
0 new messages