manbet体育手机客户端


workforce2.py


#!/ usr / bin / python#版权所有2018,guro狗万app足彩bi优化,llc#分配工人转移;每个工人都可能或可能无法在#特定日期上使用。如果问题无法解决,请迭代地使用IIS#查找所有冲突的约束。来自Gurobipy Import *#每个班次班次所需的工人数量,ShiftRequirements = Multidict({Mon1“:3,”Tue2“:2,”Wed3“:4,”Thu4“:4,”Fri5“:5,”周五“:5,”周五“SAT6“:6,”Sun7“:5,”Mon8“:2,”Tue9“:2,”Wed10“:3,”星期六“:4,”星期五12“:6,”SAT13“:7,”Sun14“:5。,“fred”:9,“gu”:11})#工作者可用性可用性= tuplelist([('amy','tue2'),('amy','wed3'),('amy','fri5'),('amy','sun7'),('amy','tue9'),('amy','wed10'),('amy','thu11'),('amy','fri12''),('amy','sat13'),('amy','sun14'),('bob','mon1'),('bob','tue2'),('bob','fri5'),('bob','sat6'),('bob','mon8'),('bob','thu11'),('bob','sat13'),('cathy','wed3'),('Cathy','Thu4'),('Cathy','Fri5'),('Cathy','Sun7'),('Cathy','Mon8'),('Cathy','Tue9')),('Cathy','Wed10'),('Cathy','Thu11'),('Cathy','Fri12'),('Cathy','SAT13'),('Cathy','Sun14''),('dan','tue2'),('丹','wed3'),('dan','fri5'),('dan','sat6'),('dan','mon8'),('dan','tue9'),('丹'','wed10'),('dan','thu11'),('dan','fri12'),('dan','sat13'),('dan','sun14'),('ed','mon1'),('ed','tue2'),('ed','wed3'),('ed','thu4'),('ed','fri5'),('ed'', 'Sun7'), ('Ed', 'Mon8'), ('Ed', 'Tue9'), ('Ed', 'Thu11'), ('Ed', 'Sat13'), ('Ed', 'Sun14'), ('Fred', 'Mon1'), ('Fred', 'Tue2'), ('Fred', 'Wed3'), ('Fred', 'Sat6'), ('Fred', 'Mon8'), ('Fred', 'Tue9'), ('Fred', 'Fri12'), ('Fred', 'Sat13'), ('Fred', 'Sun14'), ('Gu', 'Mon1'), ('Gu', 'Tue2'), ('Gu', 'Wed3'), ('Gu', 'Fri5'), ('Gu', 'Sat6'), ('Gu', 'Sun7'), ('Gu', 'Mon8'), ('Gu', 'Tue9'), ('Gu', 'Wed10'), ('Gu', 'Thu11'), ('Gu', 'Fri12'), ('Gu', 'Sat13'), ('Gu', 'Sun14') ]) # Model m = Model("assignment") # Assignment variables: x[w,s] == 1 if worker w is assigned to shift s. # Since an assignment model always produces integer solutions, we use # continuous variables and solve as an LP. x = m.addVars(availability, ub=1, name="x") # The objective is to minimize the total pay costs m.setObjective(quicksum(pay[w]*x[w,s] for w,s in availability), GRB.MINIMIZE) # Constraint: assign exactly shiftRequirements[s] workers to each shift s reqCts = m.addConstrs((x.sum('*', s) == shiftRequirements[s] for s in shifts), "_") # Optimize m.optimize() status = m.status if status == GRB.Status.UNBOUNDED: print('The model cannot be solved because it is unbounded') exit(0) if status == GRB.Status.OPTIMAL: print('The optimal objective is %g' % m.objVal) exit(0) if status != GRB.Status.INF_OR_UNBD and status != GRB.Status.INFEASIBLE: print('Optimization was stopped with status %d' % status) exit(0) # do IIS print('The model is infeasible; computing IIS') removed = [] # Loop until we reduce to a model that can be solved while True: m.computeIIS() print('\nThe following constraint cannot be satisfied:') for c in m.getConstrs(): if c.IISConstr: print('%s' % c.constrName) # Remove a single constraint from the model removed.append(str(c.constrName)) m.remove(c) break print('') m.optimize() status = m.status if status == GRB.Status.UNBOUNDED: print('The model cannot be solved because it is unbounded') exit(0) if status == GRB.Status.OPTIMAL: break if status != GRB.Status.INF_OR_UNBD and status != GRB.Status.INFEASIBLE: print('Optimization was stopped with status %d' % status) exit(0) print('\nThe following constraints were removed to get a feasible LP:') print(removed)