Writing an Objective Function in Python

43 views
Skip to first unread message

Justin O'Pella

unread,
Nov 28, 2017, 12:35:40 AM11/28/17
to Gurobi Optimization
Hello,
I would like to repost a previous question but with additional critical information that was originally not included. 

I am looking for help coding the objective function (see attached). 

The decision variables are the x_sc's. There are two sets: set S and set C and each pair of the members from S and C form a decision variable x_sc, where x_sc is binary. K is a constant. (I have this value already programmed so this is a non-issue). The e_sc is a parameter obtained from the data supplied to the problem for each pairing of members from S and C. 

One attempt I tried was:

m.setObjective(

....... (quicksum(x_sc['*',c] for c in set_C)) /

....... ((K) - (quicksum(eligibility['*',c] for c in set_C))), GRB.MAXIMIZE)



If you were to expand, the objective function is linear with a fraction as each coefficient.

Any feedback or point toward some documentation is appreciated.
Thanks
Justin
Screen Shot 2017-11-21 at 9.32.59 AM.png

Daniel Espinoza

unread,
Nov 30, 2017, 9:48:51 AM11/30/17
to Gurobi Optimization
Justin,

If each variable x[s,c] has an objective coefficient c[s,c], , i.e. you want to optimize 

max sum(x[s,c] * a[s,c]: s in S c in C)

then you could use 

m.setObjective(x.prod(a), GRB.MAXIMIZE)

Best,
Daniel

Justin O'Pella

unread,
Dec 1, 2017, 3:37:40 PM12/1/17
to Gurobi Optimization
Thanks, Daniel!
Reply all
Reply to author
Forward
0 new messages