lpmod_vb.vb


“版权所有2023,Gurobi O狗万app足彩ptimization, LLC”“此示例从文件中读取LP模型并求解它。”如果模型可以求解,那么它会找到最小的正变量,并将其上限设置为零,并以两种方式求解模型:“首先有一个提前的开始,然后没有提前的开始”(即从头开始)。Imports System Imports Gurobi Class lpmod_vb Shared Sub Main(ByVal args As String())如果参数。长度< 1则为Console。WriteLine("Usage: lpmod_vb filename")返回结束If Try ' Read模型并确定它是否是LP Dim env As New GRBEnv() Dim model As New GRBModel(env, args(0)) If模型。IsMIP <> 0则为Console。WriteLine("The model is not a linear program") Environment.Exit(1)结束If model. optimize () Dim status As Integer = model. exit ()Status If (Status = GRB.Status.INF_OR_UNBD) OrElse _ (Status = grb .Status. inviable) OrElse _ (Status = GRB.Status.UNBOUNDED) ThenWriteLine("该模型不能被解决,因为它是" & _ "不可行或无界")Environment.Exit(1)结束If If status <> GRB.Status.OPTIMAL Then控制台。WriteLine(“优化已停止状态”& status) Environment.Exit(0)结束如果“找到最小的变量值Dim minVal As Double = GRB.”INFINITY Dim minVar As GRBVar = Nothing For Each v As GRBVar In model.GetVars() Dim sol As Double = v. x If (sol > 0.0001) AndAlso _ (sol < minVal) AndAlso _ (v. lb = 0.0) Then minVal = sol minVar = v End If Next Console。WriteLine(vbLf & "*** Setting " & _ minVar. txt)VarName & " from " & minVal & " to zero ***" & vbLf) minVar。从这个起始点模型求解。optimize () '保存迭代和时间信息Dim warmCount As Double =模型。IterCount Dim warmTime As Double =模型。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