Include range of costs instead of a single value into the objective function
AnsweredHi,
I am doing an hourly optimization using gurobipy for multiple variables. The sample code I am using is as follows:
Parameters:
AA = ['a', 'b']
price_a = 1
price_b = 2
price_AA = dict(zip(AA,[price_a, price_b]))
min_lim_AA = dict(zip(AA, [0, 0]))
max_lim_AA = dict(zip(AA, [np.inf, np.inf]))
Optimization equation:
prob = grb.Model("Optimization")
prob.modelSense = grb.GRB.MINIMIZE
AAcap = prob.addVars(AA, obj = 0.0, lb=min_lim_AA , ub=max_lim_AA ,
vtype = grb.GRB.CONTINUOUS, name = 'AA Capacity)
AAout = prob.addVars(AA, time_index, obj = 0.0, lb=min_lim_AA , ub=max_lim_AA ,
vtype = grb.GRB.CONTINUOUS, name = 'AA Output)
for c, t in itertools.product(A, time_index):
AAout[c,t].obj = price_AA[c]
prob.update()
Instead of one value for price_a and price_b, I want to use different values for different hours in the time_index. When I do that (by inputting the values in a CSV format and linking it to the code with csv_reader) and modify the objective constraint as shown below:
AAout = prob.addVars(AA, time_index, obj = 0.0, lb=min_lim_AA , ub=max_lim_AA ,
vtype = grb.GRB.CONTINUOUS, name = 'AA Output)
for c, t in itertools.product(A, time_index):
AAout[c,t].obj = price_AA[c][t]
the error that I get is :
AttributeError: Attribute 'obj' takes double value
How can I solve this issue?
-
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 Ansari,
It looks like your \(\texttt{price_AA[c][t]}\) values are not doubles. You could try printing them to see what they actually are
for c, t in itertools.product(A, time_index):
print(price_AA[c][t])
AAout[c,t].obj = price_AA[c][t]Best regards,
Jaromił0
Post is closed for comments.
Comments
2 comments