Type Error Objective Function
AnsweredHi! I am having this error come up when I run my code and I am unsure as to why. Can I get help fixing this?
error: TypeError: 'int' object is not callable
code:
import math
from gurobipy import GRB,Model
x = [0.1, 0.15, 0.35, 0.5, 0.65, 0.85, 0.95]
y = [2.5, 2.2, 1.8, 1.5, 1.3, 0.9, 0.4]
m = Model()
# Set parameters
m.setParam('OutputFlag',True)
# Add variables
z1 = m.addVar(name='z1')
z2 = m.addVar(name='z2')
z3 = m.addVar(name='z3')
z4 = m.addVar(name='z4')
z5 = m.addVar(name='z5')
z6 = m.addVar(name='z6')
z7 = m.addVar(name='z7')
a = m.addVar(name='a')
b = m.addVar(name='b')
c = m.addVar(name='c')
# Add constraints
m.addConstr(2.5-(a+(b*(0.1**3))+ c*math.log(0.1)) <= z1, name='c1')
m.addConstr(-(2.5-(a+(b*(0.1**3))+ c*math.log(0.1))) <= z1, name='c2')
m.addConstr(2.2-(a+(b*(0.15**3))+ c*math.log(0.15)) <= z2 ,name='c3')
m.addConstr(-(2.2-(a+(b*(0.15**3))+ c*math.log(0.15))) <= z2, name='c4')
m.addConstr(1.8-(a+(b*(0.35**3))+ c*math.log(0.35)) <= z3 ,name='c5')
m.addConstr(-(1.8-(a+(b*(0.35**3))+ c*math.log(0.35))) <= z3, name='c6')
m.addConstr(1.5-(a+(b*(0.5**3))+ c*math.log(0.5)) <= z4, name='c7')
m.addConstr(-(1.5-(a+(b*(0.5**3))+ c*math.log(0.5))) <= z4, name='c8')
m.addConstr(1.3-(a+(b*(0.65**3))+ c*math.log(0.65)) <= z5 ,name='c9')
m.addConstr(-(1.3-(a+(b*(0.65**3))+ c*math.log(0.65))) <= z5, name='c10')
m.addConstr(0.9-(a+(b*(0.85**3))+ c*math.log(0.85)) <= z6 ,name='c11')
m.addConstr(-(0.9-(a+(b*(0.85**3))+ c*math.log(0.85))) <= z6, name='c12')
m.addConstr(0.4-(a+(b*(0.95**3))+ c*math.log(0.95)) <= z7 ,name='c13')
m.addConstr(-(0.4-(a+(b*(0.95**3))+ c*math.log(0.95))) <= z7, name='c14')
# Set the objective
m.setObjective((1/7)*(z1 + z2 + z3 + z4 + z5 + z6 + z7), GRB.MINIMIZE())
m.optimize()
-
Official comment
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. -
Hi Abbigail,
You'll want to remove the brackets from GRB.MINIMIZE, it's not a function, and is just an integer in disguise. (Try print(GRB.MINIMIZE) for example).
- Riley
1 -
thank you so much!
0
Post is closed for comments.
Comments
3 comments