Skip to main content

Gurobi as a function

Answered

Comments

1 comment

  • 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

Please sign in to leave a comment.