Creating Your First Model

This tutorial will walk you through how to successfully run your first optimization model in studio (current cloud instance) or as a job (hyperscaling configurable cloud resource). Finally, you will learn how to use the debugger to help find and correct any errors within your code. You will be writing your model as a “concrete” model, so data will not be split into separate files.

Step-by-Step Tutorial to Run Your First Model

Below is the math to help you formulate your model. Instructions can be found within the My Models in the Tutorial Model Folder or listed below.

Maximize

x + y + 2

Subject To

x + 2y + 3z <= 4x

x + y >= 1

x, y, z are binary


Create Model in Gurobi

  1. Create a folder called “my_model”
  2. Inside the “my_model” folder, create another folder called “atlas_tutorial”
  3. Right click on the “workshop_example” folder and create a file called “gurobi.py”
  4. Create the model
  5. Right click on the “workshop_example” folder and create a file called “gurobi.py”
    1. Import gurobipy packages
      1. import gurobipy as gp
      2. from gurobipy import GRB
    2. Create the concrete instance of the model and name it “xyz”
      1. m = gp.Model(“xyz”)
    3. Set up the variables for X, Y, and Z as binary variables
      1. x = m.addVar(vtype=GRB.BINARY, name=”x”)
      2. y = m.addVar(vtype=GRB.BINARY, name=”y”)
      3. z = m.addVar(vtype=GRB.BINARY, name=”z”)
    4. Specify the objective function, maximizing the equation: x + y + 2z
      1. m.setObjective(x + y + 2*z, GRB.MAXIMIZE)
    5. Set up the constraint “c0”: x + 2y + 3z <= 4
      1. m.addConstr(x + 2*y + 3*z <= 4, “c0”)
    6. Set up the constraint “c1”: x + y >= 1x + y >= 1
      1. m.addConstr(x + y >= 1, “c1”)
    7. Solve the model
      1. m.optimize()
        1. Objective value should be 3.0
    8. Run the model
      1. You can run your Gurobi model in studio or as a job

Debug Your Gurobi Model

  1. Add print statement to bottom of code file
    1. print(m)
  2. Set breakpoint on m.optimize()
  3. Start debugging session
  4. Step over
  5. Peek at variable to show context
  6. Watch window
    1. Add m.x
    2. Add m.ObjVal