Handling variables in the denominator of an objective function in CPLEX Python

Viewed 173

I wish to solve a linear program with an objective function:

enter image description here

Here x[i][j] are decision variables and y[i][j] are already precomputed.

I was writing the code for this in CPLEX python (DOcplex) and was receiving the error that the denominator can only be a number. Is there a way to do this correctly?

This is my code:

l_model.minimize(l_model.sum(l_model.sum(x[i,j]*y[(i,j)] for j in A)/l_model.sum(x[i,j] for j in A) for i in B))
1 Answers

In the code above, I see x variables in the denominator, which explains the error message; Docplex (and CPLEX too) expect a linear objective, with float coefficients.

Moreover, if y is also a decision variable dictionary, then the numerator expression is interpreted as a quadratic expression, whether or not variables in y are fixed. This in turn leads CPLEX to pick a QP algorithm, which is probably not what you want.

To summarize: you need to provide as objective a linear expression made exclusively from variables and Python numbers.

Related