Parameter and variable multiplication with different index numbers

Asked

Viewed 70 times

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?

  • 2

    Please post the code so we can see the problem.

  • I edited with part of the code... Thank you!

  • 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 the else of if in comprehensilist on? Otherwise, the index size tt reduces by 1

  • 1

    My first tip would be to take these list understandings both from the statement of Lambda how much of the argument obj below, and in its place put the loops for 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; in obj, its expression nests 4!

  • 1

    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 a else there, I think.

  • There is no lack of an Else, I only count the value of Lambda[i][j][tt] in the objective function if i != j.

Show 1 more comment
No answers

Browser other questions tagged

You are not signed in. Login or sign up in order to post.