Docplex: Building expression to get a value from an array

157 views Asked by At

I have an array defined as follows

A = [
[10,20],
[20,10]
]

Now I want to get the entry at a position (i, j). The thing is, j is a CpoFunctionCall object (where i will be an Int), so is not able to be indexed. Is it possible to have the operation of getting the (i,j)-th elemement as a CpoExpression in docplex or is there some other clever way to solve this?

1

There are 1 answers

0
Stackd On BEST ANSWER

So the way I solved this is by conversting A[i] to an expression and converting the function call to an expression of boolean array and then taking the inner product.

POSITION = [0,1]
b = build_cpo_expr(A[i])
c = list(map(lambda x: x==j, POSITION))
distance = scal_prod(c, b)