manbet体育手机客户端


工作力1.py


#!/ usr / bin / env python3.7#版权所有2019,guro狗万app足彩bi优化,llc#分配工人转移;每个工人都可能或可能无法在#特定日期上使用。如果问题无法解决,请使用IIS查找一组#冲突约束。请注意,除了#通过IIS报告的内容可能存在额外的冲突。从Gurobipy导入Gurobipy导入Gurobipy导入Grb导入Sys#每个班次班次所需的工人数量,ShiftRecivements = GP.MutIdict({Mon1“:3,”Tue2“:2,”Wed3“:4,”Thu4“:4,“星期五5”:5,“SAT6”:6,“Sun7”:5,“Mon8”:2,“Tue9”:2,“Wed10”:3,“星期六”:4,“星期五12”:6,“SAT13“:7,”Sun14“:5,})#金额每位工作人员都支付给工作一班工人,支付= GP.Multigict({amy”:10,“鲍勃”:12,“凯茜”:10,“凯茜”:10,“丹”:8,“ed”:8,“fred”:9,“gu”:11,})#工作者可用性可用性= gp.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','星期六'), ('Cathy', 'Wed3'), ('Cathy', 'Thu4'), ('Cathy', 'Fri5'), ('Cathy', 'Sun7'), ('Cathy', 'Mon8'), ('Cathy', 'Tue9'), ('Cathy', 'Wed10'), ('Cathy', 'Thu11'), ('Cathy', 'Fri12'), ('Cathy', 'Sat13'), ('Cathy', 'Sun14'), ('Dan', 'Tue2'), ('Dan', 'Wed3'), ('Dan', 'Fri5'), ('Dan', 'Sat6'), ('Dan', 'Mon8'), ('Dan', 'Tue9'), ('Dan', '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 = gp.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(gp.quicksum(pay[w]*x[w, s] for w, s in availability), GRB.MINIMIZE) # Constraints: assign exactly shiftRequirements[s] workers to each shift s reqCts = m.addConstrs((x.sum('*', s) == shiftRequirements[s] for s in shifts), "_") # Using Python looping constructs, the preceding statement would be... # # reqCts = {} # for s in shifts: # reqCts[s] = m.addConstr( # gp.quicksum(x[w,s] for w,s in availability.select('*', s)) == # shiftRequirements[s], s) # Save model m.write('workforce1.lp') # Optimize m.optimize() status = m.status if status == GRB.UNBOUNDED: print('The model cannot be solved because it is unbounded') sys.exit(0) if status == GRB.OPTIMAL: print('The optimal objective is %g' % m.objVal) sys.exit(0) if status != GRB.INF_OR_UNBD and status != GRB.INFEASIBLE: print('Optimization was stopped with status %d' % status) sys.exit(0) # do IIS print('The model is infeasible; computing IIS') m.computeIIS() if m.IISMinimal: print('IIS is minimal\n') else: print('IIS is not minimal\n') print('\nThe following constraint(s) cannot be satisfied:') for c in m.getConstrs(): if c.IISConstr: print('%s' % c.constrName)