过滤内容,
版本
文本搜索
mip2_vb.vb
版权2023、Gurobi优化LLC狗万app足彩“这个例子从文件读取MIP模型,解决了它和“打印客观值从所有可行解的解决MIP时生成的。然后它创建固定的模型,解决了模型。主要进口系统进口Gurobi类mip2_vb共享子(如果参数值传递参数arg作为String ())。长度< 1然后控制台。WriteLine(用法:mip2_vb文件名)返回如果尽可能暗env GRBEnv = New GRBEnv (“lp1.log”)的模型作为GRBModel = New GRBModel (env, args(0))模型。IsMIP = 0然后控制台。WriteLine(模型不是一个MIP)返回结束如果model.Optimize()暗optimstatus Integer =模型。如果optimstatus = GRB.Status地位。INF_OR_UNBD然后model.Parameters。Presolve = 0 model.Optimize () optimstatus =模型。状态结束如果暗objval如果optimstatus = GRB.Status两倍。最佳objval =模型。ObjVal控制台。WriteLine(最优目标:“& objval) ElseIf optimstatus = GRB.Status。不可行然后控制台。WriteLine(模型是不可行的)model.ComputeIIS () model.Write (model.ilp)返回ElseIf optimstatus = GRB.Status。无限的控制台。其他WriteLine(“模型是无界”)返回控制台。WriteLine("Optimization was stopped with status = " & _ optimstatus) Return End If ' Iterate over the solutions and compute the objectives model.Parameters.OutputFlag = 0 Console.WriteLine() For k As Integer = 0 To model.SolCount - 1 model.Parameters.SolutionNumber = k Dim objn As Double = model.PoolObjVal Console.WriteLine("Solution " & k & " has objective: " & objn) Next Console.WriteLine() model.Parameters.OutputFlag = 1 ' Solve fixed model Dim fixedmodel As GRBModel = model.FixedModel() fixedmodel.Parameters.Presolve = 0 fixedmodel.Optimize() Dim foptimstatus As Integer = fixedmodel.Status If foptimstatus <> GRB.Status.OPTIMAL Then Console.WriteLine("Error: fixed model isn't optimal") Return End If Dim fobjval As Double = fixedmodel.ObjVal If Math.Abs(fobjval - objval) > 0.000001 * (1.0 + Math.Abs(objval)) Then End If Dim fvars() As GRBVar = fixedmodel.GetVars() Dim x() As Double = fixedmodel.Get(GRB.DoubleAttr.X, fvars) Dim vnames() As String = fixedmodel.Get(GRB.StringAttr.VarName, fvars) For j As Integer = 0 To fvars.Length - 1 If x(j) <> 0 Then Console.WriteLine(vnames(j) & " " & x(j)) End If Next ' Dispose of models and env fixedmodel.Dispose() model.Dispose() env.Dispose() Catch e As GRBException Console.WriteLine("Error code: " & e.ErrorCode & ". " & e.Message) End Try End Sub End Class