multiobj_vb.vb


Gurobi优化版权2023年,LL狗万app足彩C的想覆盖三个不同但受制于公共预算的元素可以被使用。然而,有不同的优先级设置为“被覆盖;我们解决这个问题通过使用多目标优化。进口Gurobi类multiobj_vb共享子Main()尝试的示例数据模糊groundSetSize Integer = 20暗nSubsets如Integer = 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整数“新建环境昏暗env GRBEnv (“multiobj_vb.log”)“创建初始模型的模型作为新GRBModel (env)模型。ModelName = " multiobj_vb "的地面设置初始化决策变量:如果元素x [e] = = 1 e选择覆盖。昏暗的Elem GRBVar() =模型。AddVars (groundSetSize GRB.BINARY) e = 0到groundSetSize - 1暗vname字符串=“El”& e.ToString () Elem (e)。VarName = vname下的约束:限制元素的总数是最多的预算昏暗的韩新GRBLinExpr () e = 0 groundSetSize - 1 lhs.AddTerm (1.0, Elem (e))模型。AddConstr (lh、伽马线暴。LESS_EQUAL、预算、预算) ' 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