Try our new documentation site (beta).


GRBModel.AddVars()

Add new decision variables to a model.

GRBVar[] AddVars ( int count,
    char type )
    Add count new decision variables to a model. All associated attributes take their default values, except the variable type, which is specified as an argument.

    Arguments:

    count: Number of variables to add.

    type: Variable type for new variables (GRB.CONTINUOUS, GRB.BINARY, GRB.INTEGER, GRB.SEMICONT, or GRB.SEMIINT).

    Return value:

    Array of new variable objects.

GRBVar[] AddVars ( double[] lb,
    double[] ub,
    double[] obj,
    char[] type,
    string[] names )
    Add new decision variables to a model. The number of added variables is determined by the length of the input arrays (which must be consistent across all arguments).

    Arguments:

    lb: Lower bounds for new variables. Can be null, in which case the variables get lower bounds of 0.0.

    ub: Upper bounds for new variables. Can be null, in which case the variables get infinite upper bounds.

    obj: Objective coefficients for new variables. Can be null, in which case the variables get objective coefficients of 0.0.

    type: Variable types for new variables (GRB.CONTINUOUS, GRB.BINARY, GRB.INTEGER, GRB.SEMICONT, or GRB.SEMIINT). Can be null, in which case the variables are assumed to be continuous.

    names: Names for new variables. Can be null, in which case all variables are given default names.

    Return value:

    Array of new variable objects.

GRBVar[] AddVars ( double[] lb,
    double[] ub,
    double[] obj,
    char[] type,
    string[] names,
    int start,
    int len )
    Add new decision variables to a model. This signature allows you to use arrays to hold the various variable attributes (lower bound, upper bound, etc.), without forcing you to add a variable for each entry in the array. The start and len arguments allow you to specify which variables to add.

    Arguments:

    lb: Lower bounds for new variables. Can be null, in which case the variables get lower bounds of 0.0.

    ub: Upper bounds for new variables. Can be null, in which case the variables get infinite upper bounds.

    obj: Objective coefficients for new variables. Can be null, in which case the variables get objective coefficients of 0.0.

    type: Variable types for new variables (GRB.CONTINUOUS, GRB.BINARY, GRB.INTEGER, GRB.SEMICONT, or GRB.SEMIINT). Can be null, in which case the variables are assumed to be continuous.

    names: Names for new variables. Can be null, in which case all variables are given default names.

    start: The first variable in the list to add.

    len: The number of variables to add.

    Return value:

    Array of new variable objects.

GRBVar[] AddVars ( double[] lb,
    double[] ub,
    double[] obj,
    char[] type,
    string[] names,
    GRBColumn[] col )
    Add new decision variables to a model. This signature allows you to specify the list of constraints to which each new variable belongs using an array of GRBColumn objects.

    Arguments:

    lb: Lower bounds for new variables. Can be null, in which case the variables get lower bounds of 0.0.

    ub: Upper bounds for new variables. Can be null, in which case the variables get infinite upper bounds.

    obj: Objective coefficients for new variables. Can be null, in which case the variables get objective coefficients of 0.0.

    type: Variable types for new variables (GRB.CONTINUOUS, GRB.BINARY, GRB.INTEGER, GRB.SEMICONT, or GRB.SEMIINT). Can be null, in which case the variables are assumed to be continuous.

    names: Names for new variables. Can be null, in which case all variables are given default names.

    cols: GRBColumn objects for specifying a set of constraints to which each new column belongs.

    Return value:

    Array of new variable objects.

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.

Search

Gurobi Optimization