poolsearch_vb.vb


poolsearch_vb.vb


”Gurobi优化版权2021年,L狗万app足彩LC“我们找到替代epsilon-optimal解决一个给定的背包的问题通过使用PoolSearchMode进口Gurobi类poolsearch_vb共享子主要()尝试的示例数据模糊groundSetSize Integer = 10暗objCoef如双()= New双(){_ 32岁,32岁,15日,15日,6日,6日,1,1,1,1}将knapsackCoef设为Double() = New Double(){_ 16,16,8,8,4,4,2,2,2,1,1}将Budget设为Double = 33将status设为Integer, nSolutions设为Integer '创建环境env设为New GRBEnv("poolsearch_vb.log") ') '创建初始模型Dim模型作为新的GRBModel(env)模型。ModelName = "poolsearch_vb" '初始化地面集合的决策变量:' x[e] == k,如果元素e被选中k次。当GRBVar() =模型。AddVars (groundSetSize GRB.BINARY)模型。[设置](GRB.DoubleAttr。为e = 0 To groundSetSize - 1 Elem(e)。VarName =字符串。格式("El{0}", e)下一个'约束:限制总元素的选择最多预算Dim lhs As New GRBLinExpr() For e = 0 to groundSetSize - 1 lhs. addterm (knapsackCoef(e), Elem(e))下一个模型。AddConstr (lh、伽马线暴。LESS_EQUAL、预算、预算)为所有目标树立全局意识。ModelSense =伽马线暴。MAXIMIZE ' Limit how many solutions to collect model.Parameters.PoolSolutions = 1024 ' Limit how many solutions to collect model.Parameters.PoolGap = 0.1 ' Limit how many solutions to collect model.Parameters.PoolSearchMode = 2 ' save problem model.Write("poolsearch_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: ", nSolutions) ' Print objective values of solutions For e = 0 To nSolutions - 1 model.Parameters.SolutionNumber = e Console.Write("{0} ", model.PoolObjVal) If e Mod 15 = 14 Then Console.WriteLine() End If Next Console.WriteLine() model.Dispose() env.Dispose() Catch e As GRBException Console.WriteLine("Error code: {0}. {1}", e.ErrorCode, e.Message) End Try End Sub End Class