#!/usr/bin/python3

"""
Maximize
  1 x1 + 2 x2
Subject To
  C1: x1 + x2 <= 40
  Nickel: 2 x1 + 1 x2 <= 60
Bounds
  x1 >= 0
  x2 >= 0
End
"""

from gurobipy import * 

m = Model("simple")
x1 = m.addVar(name="x1")
x2 = m.addVar(name="x2")
m.update()

print("x1:%s x2:%s" % (x1,x2))

#m.setObjective(x1 + 2*x2, GRB.MAXIMIZE)
coef=[1,2]
var=[x1,x2]

s=[]
for c,v in zip(coef,var):
    print(c,v)
    s.append(c*v)
m.setObjective(sum(s),GRB.MAXIMIZE)

m.addConstr(x1 + x2 <= 40, "C1")
m.addConstr(2*x1 + x2 <= 60, "C2")

m.optimize()

print("Solution: %f" % (m.objVal,))
for v in m.getVars():
    print("%s:%f" % (v.varName, v.x))


@@ -319,32 +319,268 @@
 ZE)%0A
-coef=%5B1,2%5D%0Avar=%5Bx1,x
+%0Aclass Power:%0A    def __init__(self):%0A        self.coef=None%0A        self.var =None%0A        %0A    def __repr__(self):%0A        return %22%3C%25s %25s%3E%22 %25 (self.coef,self.var)%0A%0Ap1=Power()%0Ap2=Power()%0Aprint(p1)%0Ap1.coef=1%0Ap2.coef=2%0Ap1.var=x1%0Ap2.var=x2%0A%0Ap=%5Bp1,p
 2%5D%0A%0A
+print(p)%0A%0A
 s=%5B%5D
@@ -588,43 +588,38 @@
 for 
-c,v
+i
  in 
-zip(coef,var):%0A    print(c,v
+p:%0A    print(i.coef,i.var
 )%0A  
@@ -633,11 +633,20 @@
 end(
-c*v
+i.coef*i.var
 )%0Am.

Use classes to create constraints.