python pyomo : how to maximize the sum of maximum in the objective function

186 views
Skip to first unread message

Bhartendu Awasthi

unread,
Oct 29, 2019, 3:43:37 AM10/29/19
to Pyomo Forum

I am struggling to pick the maximum value from a list of values, such that the sum of the maximum values should be maximum. Please consider the below example:

Orders : O1, O2 and O3 ; Stores : str_1, str_2 and str_3 orders are fulfilled from 1 store which has the maximum weighted score

wtd_scores = {
("O1", "str_1") = 90.03,
("O1", "str_2") = 83.03,
("O1", "str_3") = 83.07,
("O2", "str_1") = 70.84,
("O2", "str_2") = 96.90,
("O2", "str_3") = 90.92,
}

the above scores are arrived by giving a certain weights to factors x, y and z -> decision variables (in other words the above wtd_scores are a function of x, y, z). I need to pick the best set of weights for factors x, y, z such that sum of maximum scores for each order is maximum. In the above example the value of objective function should be 90.03 + 96.90 = 186.93 by selecting str_1 for O1 and str_2 for O2

Weighted score will always be b/w 0 to 100

I tried to do sth like below:

def dv_bounds2(m, i):
    return (0, 100)

# decision variable x2 should hold the maximum wtd score corresponding to each order
model.x2 = Var(model.orders, within=NonNegativeReals, bounds=dv_bounds2)

def const(m,i,j):
    return m.x2[i] >= wtd_scores[i,j]

model.const = Constraint(model.orders, model.stores, rule=const)

def obj_rule(m):
    return sum(m.x2[i] for i in m.orders)
model.obj = Objective(rule=obj_rule, sense=maximize)

However, the solver always selects value of x2['O1'] = x2['O2'] = 100, which makes sense since I want to maximize the sum of x2['O1'] + x2['O2] and the upper bound = 100

But, I need to pick the actual maximum score for each order. i.e for O1 -> 90.03 and for O2 -> 96.90 And preferably the corresponding store id.

I am new to pyomo and optimization, any help is greatly appreciated!

Reply all
Reply to author
Forward
0 new messages