Try our new documentation site (beta).


' Copyright 2016, Gurobi Optimization, Inc.
' Solve a model with different values of the Method parameter;
' show which value gives the shortest solve time.

Imports System
Imports Gurobi

Class lpmethod_vb

    Shared Sub Main(ByVal args As String())

        If args.Length < 1 Then
            Console.WriteLine("Usage: lpmethod_vb filename")
        End If

            ' Read model and verify that it is a MIP
            Dim env As New GRBEnv()
            Dim model As New GRBModel(env, args(0))
            Dim menv As GRBEnv = model.GetEnv()

            ' Solve the model with different values of Method
            Dim bestMethod As Integer = -1
            Dim bestTime As Double = menv.get(GRB.DoubleParam.TimeLimit)
            For i As Integer = 0 To 2
                menv.Set(GRB.IntParam.Method, i)
                If model.Get(GRB.IntAttr.Status) = GRB.Status.OPTIMAL Then
                    bestTime = model.Get(GRB.DoubleAttr.Runtime)
                    bestMethod = i
                    ' Reduce the TimeLimit parameter to save time
                    ' with other methods
                    menv.Set(GRB.DoubleParam.TimeLimit, bestTime)
                End If

            ' Report which method was fastest
            If bestMethod = -1 Then
                Console.WriteLine("Unable to solve this model")
                Console.WriteLine("Solved in " & bestTime & _
                                  " seconds with Method: " & bestMethod)
            End If

            ' Dispose of model and env

        Catch e As GRBException
            Console.WriteLine("Error code: " & e.ErrorCode & ". " & e.Message)
        End Try
    End Sub
End Class

Try Gurobi for Free

Choose the evaluation license that fits you best, and start working with our Expert Team for technical guidance and support.

Evaluation License
Get a free, full-featured license of the Gurobi Optimizer to experience the performance, support, benchmarking and tuning services we provide as part of our product offering.
Academic License
Gurobi supports the teaching and use of optimization within academic institutions. We offer free, full-featured copies of Gurobi for use in class, and for research.
Cloud Trial

Request free trial hours, so you can see how quickly and easily a model can be solved on the cloud.