title: Solve Gurobi model repeatedly in Python
body: <p>I need to solve a gurobi model repeatedly (with different variable values each iteration). Rather than rebuild the model each iteration, I have tried setting up the model, then looping through repeated optimizations, but the variable values do not update. Here is a simple example.</p>
  
  <pre><code>n = Model("Test")
  a = n.addVar(lb=0,name = "a")
  b = n.addVar(lb=0,name = "b")
  a=1
  b=1
  x = n.addVar(lb=0,name = "x")
  y = n.addVar(lb=0,name = "y")
  n.update()
  n.setObjective(a*x + b*y,GRB.MAXIMIZE)
  n.addConstr(x + y &lt;= 10)
  n.addConstr(2*x + 3*y &lt;= 20)
  n.addConstr(y&lt;=5)
  n.update
  n.optimize()
  for v in n.getVars():
      print('%s %g' % (v.varName, v.x))
  
  print('Obj: %g' % n.objVal)
  
  for i in (1,10):
      n.update()
      a=i*2
      b=100/i
      n.optimize()
      for v in n.getVars():
          print('%s %g' % (v.varName, v.x))
  </code></pre>
  
  <p>How do I use the existing model over and over again?</p>