poolsearch_vb.vb


Gurobi优化版权2023年,LL狗万app足彩C的我们找到替代epsilon-optimal解决一个给定的背包的问题通过使用PoolSearchMode进口Gurobi类poolsearch_vb共享子主要()尝试的示例数据模糊groundSetSize Integer = 10暗objCoef如双()= New双(){_ 32岁,32岁,15日,15日,6日,6日,1,1,1,1}昏暗knapsackCoef作为双()= New双(){_ 16 16 8、8、4、4、2、2、1、1}的预算双e = 33昏暗的整数,整数,地位nSolutions整数“新建环境昏暗env GRBEnv (“poolsearch_vb.log”)“创建初始模型的模型作为新GRBModel (env)模型。ModelName = " poolsearch_vb "的地面设置初始化决策变量:x [e] = = k元素e是否选择k乘以。昏暗的Elem GRBVar() =模型。AddVars (groundSetSize GRB.BINARY)模型。[设置](GRB.DoubleAttr。Obj, Elem objCoef 0 groundSetSize) e = 0到groundSetSize - 1 Elem (e)。VarName =字符串。格式(“{0}”,e)下的约束:限制元素的总数是最多预算昏暗的韩新GRBLinExpr () e = 0 groundSetSize - 1 lhs.AddTerm (knapsackCoef (e), Elem (e))下模型。AddConstr (lh、伽马线暴。LESS_EQUAL、预算、预算)树立全球意识对所有目标模型。ModelSense =伽马线暴。最大化的收集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