Minimize cost based on purchased volume Pyomo

こ雲淡風輕ζ 提交于 2021-01-07 02:59:09

问题


I'd like to find the optimal solution for buying goods from suppliers where the shipping cost is dependent on the cost of goods bought from given supplier. I'm using Pyomo. My code so far is:

model = ConcreteModel(name="(MN_2)")

# products
N = ['prod1', 'prod2', 'prod3']

# suppliers
M = ['A', 'B']

# price
p = {('prod1', 'A'): 10,
     ('prod2', 'A'): 9,
     ('prod3', 'A'): 50,
     ('prod1', 'B'): 16,
     ('prod2', 'B'): 20,
     ('prod3', 'B'): 35}

# user quantity contraint
q_u = {('prod1', 'A'): 2,
     ('prod2', 'A'): 1,
     ('prod3', 'A'): 1,
     ('prod1', 'B'): 1,
     ('prod2', 'B'): 1,
     ('prod3', 'B'): 1}

# seller quantity contraint
q_s = {('prod1', 'A'): 20,
     ('prod2', 'A'): 10,
     ('prod3', 'A'): 10,
     ('prod1', 'B'): 10,
     ('prod2', 'B'): 10,
     ('prod3', 'B'): 10}


# quantity of product n bough in shop m
model.x = Var(N, M, bounds=(0,10))

def obj_rule(model):
    return sum(p[n,m]*model.x[n,m] for n in N for m in M)
model.obj = Objective(rule=obj_rule)

def user_quantity(model, n, m):
    return model.x[n,m] >= q_u[n,m]
model.user_quantity = Constraint(N, M, rule=user_quantity)

def seller_quantity(model, n, m):
    return model.x[n,m] <= q_s[n,m]
model.seller_quantity = Constraint(N, M, rule=seller_quantity)

solver = SolverFactory('glpk')
solver.solve(model)
model.x.pprint()

What I'm struggling with is how to include the shipping cost that is dependent on the cost of goods bought from given supplier. For example:

For supplier A: shipping cost is =

  • 10 if the sum of costs of products bought from them is <= 100,
  • 0 if the sum of costs of products bought from them is > 100

For supplier B: shipping cost is =

  • 8 if the sum of costs of products bought from them is <= 150,
  • 0 if the sum of costs of products bought from them is > 150

来源:https://stackoverflow.com/questions/65369002/minimize-cost-based-on-purchased-volume-pyomo

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!