lpmod_vb.vb


lpmod_vb.vb


“Copyright 2021, G狗万app足彩urobi Optimization, LLC”“本示例从文件中读取LP模型并解决它。”如果模型可以被求解,那么它会找到最小的正变量,“将其上界设为零,然后用两种方法求解模型:“先提前开始,然后不提前开始”(即从头开始)。导入系统导入Gurobi类lpmod_vb共享子Main(ByVal args As String())长度< 1然后控制台。如果Try '读取模型并确定它是否为LP Dim env As New GRBEnv() Dim model As New GRBModel(env, args(0))如果模型。IsMIP <> 0然后是Console。WriteLine("模型不是一个线性程序")Environment.Exit(1)结束如果model. optimize () Dim status As Integer = model。If (Status = GRB.Status.INF_OR_UNBD) OrElse _ (Status = GRB.Status.INFEASIBLE) OrElse _ (Status = GRB.Status.UNBOUNDED) Then控制台。If If status <> GRB.Status.OPTIMAL Then Console. exit(1)结束If If status <> GRB.Status.OPTIMAL Then Console. exit(1)结束WriteLine("Optimization was stopped with status " & status) Environment.Exit(0) End If '找到最小的变量值Dim minVal As Double = GRB。getvars () Dim sol As Double = v. x If (sol > 0.0001) AndAlso _ (sol < minVal) AndAlso _ (v. lb = 0.0) Then minVal = sol minVar = v结束如果下一个控制台。WriteLine(vbLf &“***设置”& _ minVar。VarName & " from " & minVal & " to 0 ***" & vbLf) minVar。UB = 0 '从这个起点模型。optimization()求解'保存迭代和时间信息Dim warmCount As Double = model。IterCount Dim warmTime As Double = model。Runtime ' Reset the model and resolve Console.WriteLine(vbLf & "*** Resetting and solving " & _ "without an advanced start ***" & vbLf) model.Reset() model.Optimize() Dim coldCount As Double = model.IterCount Dim coldTime As Double = model.Runtime Console.WriteLine(vbLf & "*** Warm start: " & warmCount & _ " iterations, " & warmTime & " seconds") Console.WriteLine("*** Cold start: " & coldCount & " iterations, " & _ coldTime & " seconds") ' Dispose of model and env model.Dispose() env.Dispose() Catch e As GRBException Console.WriteLine("Error code: " & e.ErrorCode & ". " & e.Message) End Try End Sub End Class