multiobj_vb.vb


multiobj_vb.vb


“Copyright 2021, G狗万app足彩urobi Optimization, LLC”想覆盖三套不同的设备,但受“允许使用的元素”的共同预算限制。然而,布景有不同的优先级要“覆盖;我们用多目标优化来解决这个问题。进口Gurobi类multiobj_vb共享子Main()尽可能的示例数据暗groundSetSize整数= 20昏暗nSubsets整数= 4昏暗的预算一样整数= 12昏暗的[设置]双新双(,)(,)= {_ {1,1,1,1,1,1,1,1,1,- 1,0,0,0,0,0,0,0,0,0,0},_ {0,0,0,0,0,1,1,1,1,- 1,0,0,0,0,0,1,1,1,1,1},_ {0,0,0,1,1,0,1, - 1, 0, 0, 0, 0, 0, 1, 1, 0, 1, 1, 0, 0} _{0, 0, 0, 1, 1, - 1, 0, 0, 0, 1, 1, - 1, 0, 0, 0, 1, 1, - 1, 0, 0}}昏暗SetObjPriority为整数()= New整数(){3 2 2 1}昏暗SetObjWeight作为双()= New双(){1.0,0.25,1.25,1.0}昏暗的e为整数,我作为整数,整数,地位nSolutions As Integer ' Create environment Dim env As New GRBEnv("multiobj_vb.log") '创建初始模型Dim模型作为新的GRBModel(env)模型。ModelName = "multiobj_vb" '初始化地面集合的决策变量:' x[e] == 1如果元素e被选择覆盖。当GRBVar() =模型。AddVars(groundSetSize, GRB.BINARY) For e = 0 To groundSetSize - 1 Dim vname As String = "El" & e. tostring () Elem(e)。VarName = vname Next ' Constraint: limit total number of elements to be picked to be at most ' Budget Dim lhs As New GRBLinExpr() For e = 0 To groundSetSize - 1 lhs.AddTerm(1.0, Elem(e)) Next model.AddConstr(lhs, GRB.LESS_EQUAL, Budget, "Budget") ' Set global sense for ALL objectives model.ModelSense = GRB.MAXIMIZE ' Limit how many solutions to collect model.Parameters.PoolSolutions = 100 ' Set and configure i-th objective For i = 0 To nSubsets - 1 Dim vname As String = String.Format("Set{0}", i) Dim objn As New GRBLinExpr() For e = 0 To groundSetSize - 1 objn.AddTerm([Set](i, e), Elem(e)) Next model.SetObjectiveN(objn, i, SetObjPriority(i), SetObjWeight(i), _ 1.0 + i, 0.01, vname) Next ' Save problem model.Write("multiobj_vb.lp") ' Optimize model.Optimize() ' Status checking status = model.Status If status = GRB.Status.INF_OR_UNBD OrElse _ status = GRB.Status.INFEASIBLE OrElse _ status = GRB.Status.UNBOUNDED Then Console.WriteLine("The model cannot be solved " & _ "because it is infeasible or unbounded") Return End If If status <> GRB.Status.OPTIMAL Then Console.WriteLine("Optimization was stopped with status {0}", status) Return End If ' Print best selected set Console.WriteLine("Selected elements in best solution:") Console.Write(vbTab) For e = 0 To groundSetSize - 1 If Elem(e).X < 0.9 Then Continue For End If Console.Write("El{0} ", e) Next Console.WriteLine() ' Print number of solutions stored nSolutions = model.SolCount Console.WriteLine("Number of solutions found: {0}", nSolutions) ' Print objective values of solutions If nSolutions > 10 Then nSolutions = 10 End If Console.WriteLine("Objective values for first {0} solutions:", nSolutions) For i = 0 To nSubsets - 1 model.Parameters.ObjNumber = i Console.Write(vbTab & "Set" & i) For e = 0 To nSolutions - 1 model.Parameters.SolutionNumber = e Console.Write("{0,8}", model.ObjNVal) Next Console.WriteLine() Next model.Dispose() env.Dispose() Catch e As GRBException Console.WriteLine("Error code = {0}", e) Console.WriteLine(e.Message) End Try End Sub End Class