Can we not solve 2 models in a single python file with Gurobipy?
AnsweredI have been running 2 models, namely m1 and m2.
In one of them, I used constraints like
y=m.addVars(list(product(P,N)),vtype=GRB.BINARY,name='Y'), which is working fine.
and in model 2 named m1, I used
xmtn=m1.addVars(list(product(M,TN)),vtype=GRB.INTEGER,name='xmtn') whis is showing an error saying
"List object not callable".
Kindly help me in this regard.
-
Official comment
This post is more than three years old. Some information may not be up to date. For current information, please check the Gurobi Documentation or Knowledge Base. If you need more help, please create a new post in the community forum. Or why not try our AI Gurobot?. -
Hi,
Could you provide a minimal working example to reproduce the issue? In this case, one would at least need the definition of \(\texttt{P, N, M, TN}\).
Best regards,
Jaromił0 -
Hi @Jaromil.... Here P, N , M, TN are the list consists of natural integer numbers
For example
P=[i for i in range(5)]...
Like wise all the lists...0 -
It's hard to help without a working code example that reproduces the issue. There is something else in your code that is contributing to the error. My best guess is that you assigned a list object to a Python variable named \( \texttt{list} \) or \( \texttt{product} \), which would overwrite the \( \texttt{list} \) built-in or \( \texttt{itertools.product} \). The following code runs fine:
import gurobipy as gp
from gurobipy import GRB
from itertools import product
M = [i for i in range(5)]
TN = [i for i in range(10)]
m1 = gp.Model()
xmtn = m1.addVars(list(product(M, TN)), vtype=GRB.INTEGER, name='xmtn')By the way, the above code can be simplified (and made more efficient) as follows:
import gurobipy as gp
from gurobipy import GRB
m1 = gp.Model()
xmtn = m1.addVars(5, 10, vtype=GRB.INTEGER, name='xmtn')0 -
Thank You so much Eli Towle. The alternative method has resolved my problem. Thanks again.
0
Post is closed for comments.
Comments
5 comments