manbet体育手机客户端


facility.py


#!/usr/bin/env python3.7 # Copyright 2019, 狗万app足彩Gurobi Optimization, LLC #设施位置:一家公司目前将其产品狗万滚球球从5个工厂#运送到4个仓库。该公司正在考虑关闭一些工厂以降低成本。为了减少运输和固定成本,公司应该关闭哪些工厂?狗万滚球球# #注意这个例子使用列表而不是字典。由于#不能用于稀疏数据,列表是一个合理的选择。# #基于前线系统的一个例子:# http://www.solver.com/disfacility.htm #经过许可使手机万博登录用。进口gurobipy从gurobipy gp进口伽马线暴#仓库需求在成千上万的单位需求=[14日,15日,18日20]#工厂生产能力在成千上万的单位容量=[18]20日,22日,17日,19日#固定成本为每个工厂fixedCosts =(12000、15000、17000、13000、16000]#运输成本每千单位transCosts =[[4000、2000、3000、2500、4500]、[2500、2600、3400、3000、4000],[1200、1800、2600、4100、3000],[2200、2600、3100、3700、3200]]#范围的工厂和仓库工厂=范围(len(能力))仓库=范围(len(需求))#模型m = gp.Model(“设备”)#工厂开放决策变量:打开[p] = = 1如果植物p是开着的。open = m.addVars(植物,vtype=GRB。BINARY, obj=fixedCosts, name="open") # Transportation decision variables: transport[w,p] captures the # optimal quantity to transport to warehouse w from plant p transport = m.addVars(warehouses, plants, obj=transCosts, name="trans") # You could use Python looping constructs and m.addVar() to create # these decision variables instead. The following would be equivalent # to the preceding two statements... # # open = [] # for p in plants: # open.append(m.addVar(vtype=GRB.BINARY, # obj=fixedCosts[p], # name="open[%d]" % p)) # # transport = [] # for w in warehouses: # transport.append([]) # for p in plants: # transport[w].append(m.addVar(obj=transCosts[w][p], # name="trans[%d,%d]" % (w, p))) # The objective is to minimize the total fixed and variable costs m.modelSense = GRB.MINIMIZE # Production constraints # Note that the right-hand limit sets the production to zero if the plant # is closed m.addConstrs( (transport.sum('*', p) <= capacity[p]*open[p] for p in plants), "Capacity") # Using Python looping constructs, the preceding would be... # # for p in plants: # m.addConstr(sum(transport[w][p] for w in warehouses) # <= capacity[p] * open[p], "Capacity[%d]" % p) # Demand constraints m.addConstrs( (transport.sum(w) == demand[w] for w in warehouses), "Demand") # ... and the preceding would be ... # for w in warehouses: # m.addConstr(sum(transport[w][p] for p in plants) == demand[w], # "Demand[%d]" % w) # Save model m.write('facilityPY.lp') # Guess at the starting point: close the plant with the highest fixed costs; # open all others # First open all plants for p in plants: open[p].start = 1.0 # Now close the plant with the highest fixed cost print('Initial guess:') maxFixed = max(fixedCosts) for p in plants: if fixedCosts[p] == maxFixed: open[p].start = 0.0 print('Closing plant %s' % p) break print('') # Use barrier to solve root relaxation m.Params.method = 2 # Solve m.optimize() # Print solution print('\nTOTAL COSTS: %g' % m.objVal) print('SOLUTION:') for p in plants: if open[p].x > 0.99: print('Plant %s open' % p) for w in warehouses: if transport[w, p].x > 0: print(' Transport %g units to warehouse %s' % (transport[w, p].x, w)) else: print('Plant %s closed!' % p)