Try our new documentation site (beta).
Filter Content By
Version
Text Search
${sidebar_list_label} - Back
Filter by Language
mip1_vb.vb
' Copyright 2020, Gurobi Optimization, LLC ' ' This example formulates and solves the following simple MIP model: ' ' maximize x + y + 2 z ' subject to x + 2 y + 3 z <= 4 ' x + y >= 1 ' x, y, z binary Imports System Imports Gurobi Class mip1_vb Shared Sub Main() Try Dim env As GRBEnv = New GRBEnv("mip1.log") Dim model As GRBModel = New GRBModel(env) ' Create variables Dim x As GRBVar = model.AddVar(0.0, 1.0, 0.0, GRB.BINARY, "x") Dim y As GRBVar = model.AddVar(0.0, 1.0, 0.0, GRB.BINARY, "y") Dim z As GRBVar = model.AddVar(0.0, 1.0, 0.0, GRB.BINARY, "z") ' Set objective: maximize x + y + 2 z model.SetObjective(x + y + 2 * z, GRB.MAXIMIZE) ' Add constraint: x + 2 y + 3 z <= 4 model.AddConstr(x + 2 * y + 3 * z <= 4.0, "c0") ' Add constraint: x + y >= 1 model.AddConstr(x + 2 * y + 3 * z <= 4.0, "c1") ' Optimize model model.Optimize() Console.WriteLine(x.VarName & " " & x.X) Console.WriteLine(y.VarName & " " & y.X) Console.WriteLine(z.VarName & " " & z.X) Console.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