mip1_vb.vb


mip1_vb.vb


“Copyright 2021, G狗万app足彩urobi Optimization, LLC”本示例阐述并解决了以下简单的MIP模型:“最大化x + y + 2 z '受到x + 2 y + 3 z < = 4 x + y > = 1的x, y, z二进制系统进口Gurobi类进口mip1_vb共享子主要()尽可能暗env GRBEnv = New GRBEnv(“mip1.log”)的模型作为GRBModel = New GRBModel (env) '创建变量Dim x As GRBVar = model.AddVar(0.0, 1.0, 0.0, GRB。二进制、“x”)的y GRBVar = model.AddVar(0.0, 1.0, 0.0,伽马线暴。当GRBVar = model.AddVar(0.0, 1.0, 0.0, GRB. 0)时,将GRBVar设置为0。二,“z”)”设定目标:最大化x + y + 2z模型。setobject (x + y + 2 * z, GRB.MAXIMIZE) '添加约束:x + 2 y + 3 z <= 4模型。AddConstr(x + 2 * y + 3 * z <= 4.0, "c0") '添加约束:x + y >= 1模型。AddConstr(x + 2 * y + 3 * z <= 4.0, "c1") '优化模型model.Optimize()VarName & " " & x.X) Console.WriteLine(y。VarName & " " & y.X)控制台。VarName & " " & z.X)控制台。WriteLine("Obj: " & model.ObjVal) ' 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