2
votes

Currently solving a LP problem by GEKKO Library in python. The problem has like 8,000 variables. it runs fine with 462 variables if I increase the number of variables. The program shows an error "Exception: @error: Model Expression *** Error in syntax of function string: Invalid element: ,>=0"

Any comment will be helpful.

#Initialize Model
m = GEKKO() 
#Set global options
m.options.solver = 3
m.options.IMODE = 3 #steady state optimization

#define parameter
Num_Cell= 463
H2 = m.Array(m.Var,Num_Cell,value = 0)
Demand = m.Const(value=20000000) 
D = np.zeros(Num_Cell)
F = Hardwood_Sawlog.SumOfTotal

for i in range(Num_Cell):
    H2[i].lower = 0
    H2[i].upper = F[i]
    D[i] = i

m.Equation(m.sum(H2[0:Num_Cell])==Demand)
m.Obj(np.dot(D,H2))
m.solve(disp=False,debug=True)

print('') 
print(H2)
1
where is this error found on which line of your program? Please provide the stacktrace.. - Nikos M.

1 Answers

1
votes

The problem is that the symbolic form of m.Obj(np.dot(D,H2)) exceeds the maximum length of 15,000 characters with the larger problem. Here is a version of your problem that produces an error:

from gekko import GEKKO
import numpy as np
m = GEKKO() 
m.options.solver = 3
m.options.IMODE = 3
Num_Cell= 1000
H2 = m.Array(m.Var,Num_Cell,value = 0)
Demand = m.Const(value=20000000) 
D = np.zeros(Num_Cell)
for i in range(Num_Cell):
    H2[i].lower = 0
    H2[i].upper = 100
    D[i] = i
m.Equation(m.sum(H2[0:Num_Cell])==Demand)
m.Obj(np.dot(D,H2))
m.solve(disp=False,debug=True)
print('') 
print(H2)

Here is an alternative version that overcomes the problem with np.dot() constructing the long (>15,000 character) symbolic expression.

from gekko import GEKKO
import numpy as np
m = GEKKO() 
m.options.solver = 1
m.options.IMODE = 3
Num_Cell= 1000
H2 = m.Array(m.Var,Num_Cell,value = 0)
Demand = m.Const(value=20000000) 
D = np.zeros(Num_Cell)
for i in range(Num_Cell):
    H2[i].lower = 0
    H2[i].upper = 1e10
    D[i] = i
m.Equation(m.sum(H2[0:Num_Cell])==Demand)
m.Minimize(m.sum([D[i]*H2[i] for i in range(Num_Cell)]))
m.solve(disp=True)
print('') 
print(H2)

There are linear programming model building functions in gekko that help with constructing large-scale LP problems with sparse matrices or large dense matrices:

linear programming

An even more efficient way is to use the built-in model building functions.