Hide navigation sidebar
Hide table of contents sidebar
Back to top
Toggle table of contents sidebar

# mip.R

    # Copyright 2025, 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

    library(gurobi)

    model <- list()

    model$A          <- matrix(c(1,2,3,1,1,0), nrow=2, ncol=3, byrow=T)
    model$obj        <- c(1,1,2)
    model$modelsense <- 'max'
    model$rhs        <- c(4,1)
    model$sense      <- c('<', '>')
    model$vtype      <- 'B'

    params <- list(OutputFlag=0)

    result <- gurobi(model, params)

    print('Solution:')
    print(result$objval)
    print(result$x)

    # Clear space
    rm(model, result, params)

Help and Feedback

Press `/` or click to search this documentation | Gurobi website | Gurobi community forum
Go to other Gurobi documentation | Gurobi download | Contact support