Originally posted by: story_
Hello,
I have just started using the Python API for CPLEX. I have a very simple question.
I have defined a two-dimensional variable named "y" with indices "i" and "k" by using the following:
c.variables.add(names=["y_" + str(i) + "_" + str(k) for k in range(K) for i in range(I)],
types=["C"] * (K * I)
I want to set the coefficients of these variables in the objective function. As far as I am aware, this can be done by adding the "obj=..." argument while declaring variables. To test if I got the syntax/sizes correct, I added the argument below while declaring y_i,j (note that K ranges from 0 to 5 and I ranges from 0 to 2):
obj=[0,0,0]*6
As expected this worked since the size of "obj" is consistent with the variable size. But in the specific problem I am dealing with, each y_i,j variable has a specific coefficient & I cannot declare them using the syntax above for this reason. To declare each coefficient one by one I tried the following:
obj=[[0,0,0],[0,0,0],[0,0,0],[0,0,0],[0,0,0],[0,0,0]]
But this does not seem to work. Could you please inform me on how I might change the objective function coefficients of two-dimensional (or multi-dimensional) variables in Python? Can I use a predefined list of lists (of the same size as y) to set the coefficients?
I might be missing something simple with the syntax - but I couldn't spot where the problem really is.
Thanks!
#CPLEXOptimizers#DecisionOptimization