0
Good night,
I’m doing an implementation of a mathematical model of optimization in Python 3.4. I need to multiply a parameter "Lambda" indexed in i,j,tt and a variable "x" indexed in i,t. The multiplication is contained in a sum of i,j,tt and t. However, when implementing it in Python and trying to solve the problem by Cplex I have the following message:
cplex.exceptions.errors.Cplexerror: Inconsistent Arguments
Part of code with error
dat.IT = [(i,t) for i in dat.I for t in dat.T[i]]
nx = ["x(" + str(i) + "," + str(t) + ")" for (i,t) in dat.IT]
Lambda = [[[0.0 for t in dat.T[j]] for j in dat.I] for i in dat.I]
When declaring the objective function of the problem:
sp.variables.add(obj = [-Lambda[i][j][tt] for i in dat.I for j in dat.I if i != j for tt in dat.T[j] for t in range(max(0, tt - dat.p[i][0] - dat.SETUP[i][j][0] + 1), min(tt + dat.p[j][0] + dat.SETUP[j][i][0] - 1, dat.h[i] - dat.p[i][0] + 1) + 1)], names = nx)
I’m sure the error lies in this multiplication. Can someone help me?
Please post the code so we can see the problem.
– Pedro von Hertwig Batista
I edited with part of the code... Thank you!
– Fernanda
In this line, operational research,
sp.variables.add(obj = [-Lambda[i][j][tt] for i in dat.I for j in dat.I if i != j for tt in dat.T[j] for t in range(max(0, tt - dat.p[i][0] - dat.SETUP[i][j][0] + 1), min(tt + dat.p[j][0] + dat.SETUP[j][i][0] - 1, dat.h[i] - dat.p[i][0] + 1) + 1)], names = nx)
, did not miss theelse
ofif
in comprehensilist on? Otherwise, the index sizett
reduces by 1– Marcelo Shiniti Uchimura
My first tip would be to take these list understandings both from the statement of
Lambda
how much of the argumentobj
below, and in its place put the loopsfor
own. This way, it becomes extremely difficult to read and understand the code and it is quite possible that you see the problem yourself doing this reorganization. Comprehensions serve well to decrease verbosity in obvious things, and are not a good idea if they significantly impair the readability of the code. In general a good rule is not to nest two understandings; inobj
, its expression nests 4!– Pedro von Hertwig Batista
The statement of
Lambda
I can understand it; it is initiating the matrix with zeros. But this line of optimization is hard to understand! Even more that it lacks aelse
there, I think.– Marcelo Shiniti Uchimura
There is no lack of an Else, I only count the value of Lambda[i][j][tt] in the objective function if i != j.
– Fernanda