Workforce1_vb.vb.


Workforce1_vb.vb.


'版权所有2021,Gurobi O狗万app足彩ptimization,LLC''分配工人转移;每个工人可能会或可能无法在某个日子上使用。如果问题无法解决,请使用IIS查找一组“冲突的约束。请注意,除了通过IIS报告的内容,可能存在额外的冲突。导入系统导入Gurobi类Workforce1_vb共享子Main()尝试“示例数据”天数和工人Dim班等作为字符串()= New String(){“mon1”,“tue2”,“wed3”,“thu4”,_“Fri5”,“SAT6”,“Sun7”,“Mon8”,_“Tue9”,“Wed10”,“星期四”,_“Fri12”,“SAT13”,“Sun14”} Dimer Workers作为String()= newstring(){amy“,”bob“,”cathy“,”dan“,_”ed“,”fred“,”gu“,”gu“}暗中nshifts作为整数= shifts.length昏暗nworkers作为整数= workers.length'每个Shift昏暗的工作人员需要双()= new double()= new double(){3,2,4,4,5,6,_ 5,2,2,3,4,6,_ 7,5}'每位工作人员都支付给工作一个Shift Dim Pay作为Double()= new double(){10,12,10,8,8,9,11}'工人可用性:0如果工人不可用于换档暗淡可用性作为双(,)=新的双(,){_ {0,1,1,0,1,0,1,0,1,1,1,1,1,1,1},_ {1,1,0,0,1,1,0,1,0,0,0,1,0,1,0},_ {0,0,1,1,1,0,1,1,1,1,1,1,1,1, 1, 1}, _ {0, 1, 1, 0, 1, 1, 0, 1, 1, 1, 1, 1, 1, 1}, _ {1, 1, 1, 1, 1, 0, 1, 1, 1, 0, 1, 0, 1, 1}, _ {1, 1, 1, 0, 0, 1, 0, 1, 1, 0, 0, 1, 1, 1}, _ {1, 1, 1, 0, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1}} ' Model Dim env As New GRBEnv() Dim model As New GRBModel(env) model.ModelName = "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. Dim x As GRBVar(,) = New GRBVar(nWorkers - 1, nShifts - 1) {} For w As Integer = 0 To nWorkers - 1 For s As Integer = 0 To nShifts - 1 x(w, s) = model.AddVar(0, availability(w, s), pay(w), _ GRB.CONTINUOUS, _ Workers(w) & "." & Shifts(s)) Next Next ' The objective is to minimize the total pay costs model.ModelSense = GRB.MINIMIZE ' Constraint: assign exactly shiftRequirements(s) workers ' to each shift s For s As Integer = 0 To nShifts - 1 Dim lhs As GRBLinExpr = 0 For w As Integer = 0 To nWorkers - 1 lhs.AddTerm(1.0, x(w, s)) Next model.AddConstr(lhs = shiftRequirements(s), Shifts(s)) Next ' Optimize model.Optimize() Dim status As Integer = model.Status If status = GRB.Status.UNBOUNDED Then Console.WriteLine("The model cannot be solved " & _ "because it is unbounded") Exit Sub End If If status = GRB.Status.OPTIMAL Then Console.WriteLine("The optimal objective is " & model.ObjVal) Exit Sub End If If (status <> GRB.Status.INF_OR_UNBD) AndAlso _ (status <> GRB.Status.INFEASIBLE) Then Console.WriteLine("Optimization was stopped with status " & status) Exit Sub End If ' Do IIS Console.WriteLine("The model is infeasible; computing IIS") model.ComputeIIS() Console.WriteLine(vbLf & "The following constraint(s) " & _ "cannot be satisfied:") For Each c As GRBConstr In model.GetConstrs() If c.IISConstr = 1 Then Console.WriteLine(c.ConstrName) End If Next ' Dispose of model and env model.Dispose() env.Dispose() Catch e As GRBException Console.WriteLine("Error code: " & e.ErrorCode & ". " & e.Message) End Try End Sub End Class