Skip to main content

Can we not solve 2 models in a single python file with Gurobipy?

Answered

Comments

5 comments

  • Official comment
    Simranjit Kaur
    • Gurobi Staff Gurobi Staff
    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?.
  • Jaromił Najman
    • Gurobi Staff Gurobi Staff

    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
  • BISWAJIT KAR
    • Gurobi-versary
    • Conversationalist
    • Investigator

    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
  • Eli Towle
    • Gurobi Staff Gurobi Staff

    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
  • BISWAJIT KAR
    • Gurobi-versary
    • Conversationalist
    • Investigator

    Thank You so much Eli Towle. The alternative method has resolved my problem. Thanks again.

    0

Post is closed for comments.