Skip to main content

Gurobi as a function

Answered

Comments

2 comments

  • Official comment
    Simranjit Kaur
    • Gurobi Staff
    This post is more than two 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 try Gurobot, our chatbot interface offering instant, expert-level support.
  • Riley Clement
    • Gurobi Staff

    Hi Akbar,

    The issue here relates to programming in Python, in general, rather than being specific to Gurobi.  You can find a good explanation in the YouTube video: https://www.youtube.com/watch?v=CqvZ3vGoGs0

    So, "Model" is a thing which comes from the gurobipy package, so you need to tell Python this information.  You can achieve this with the following alternatives:

    from gurobipy import Model

    m = Model()
    import gurobipy

    m = gurobipy.Model()
    import gurobipy as gp

    m = gp.Model()

    Note that the last option is the preferred style.

    I also suggest moving your import statements to the top of your file, and taking advantage of our Model.addVars function:

    import gurobipy as gp
    from gurobipy import GRB

    def UPMSet(jobs,machines,workers,activities,oprttime,machining,moving,B):
      m = gp.Model()
      x = m.addVars(
    workers, machines, activities, len(jobs), machines, activities, jobs,
    vtype="B",
    )
    ...

    - Riley

     

     

     

    0

Post is closed for comments.