Variable Declaration

Top  Previous  Next

The general syntax for variable declaration is

 

Variabletype

  firstvariablename(setdependency)  optional explanatory text                        /optional values for attributes/

  secondvarname(setdependency)      optional explanatory text

         /optional values for attributes/

;

 

where variabletype gives restrictions on the eligible numerical values for a variable.  The following types are allowed

 

Variable type

Nature of restrictions on numerical values of variable

Variable

No restriction, variable value can range from minus to plus infinity.

Free Variable

Same as case just above.

Positive Variable

Non-negative values only, variable value can range from zero to plus infinity Same as nonnegative below.

Nonnegative variable

Non-negative values only, variable value can range from zero to plus infinity Same as positive above

Negative Variable

Non-positive values only, variable value can range from minus infinity to zero.

Binary Variable

Restricted to equal either zero or one in an integer programming setting.

Integer Variable

Integer values only; by default ranging from 0 to 100.

SOS1 Variable

A group of variables only one of which can be non zero and by default are positive.  Details appear in the MIP chapter.

SOS2 Variable

A group of variables only two adjacent ones of which can be non zero and by default are positive.  Details appear in the MIP chapter.

Semicont Variable

Semi-continuous, must be zero or above a given minimum level. Details appear in the MIP chapter.

Semiint Variable

Semi-integer, must be zero or above a given minimum level and integer. Details appear in the MIP chapter.

 

Each variable must fit into one of these cases.  One may also declare all variables in the Variable or Free classes then redefine into one of the others.  This is not recommended as it entails multiple declarations of the same item.

Examples:

(model.gms)

Variables

  Tcost                        'Total Cost Of Shipping- All Routes';

Binary Variables

  Build(Warehouse)Warehouse Construction Variables;

Positive Variables

  Shipsw(Supplyl,Warehouse)Shipment to warehouse 

     tu/S1.a.l 5//

  Shipwm(Warehouse,Market)Shipment from Warehouse

Nonnegative Variables

  Shipsm(Supplyl,Market)Direct ship to Demand;

Semicont Variables

  X,y,z;

Notes:

Variable names, the contained set element names plus the explanatory text must obey the rules presented in the Rules for Item Names, Element names and Explanatory Text chapter.
Labels and long explanatory names should be used where possible as argued in the Writing Models and Good Modeling Practices chapter.
Any of the variable type commands can end with the word variable or variables.
More than one named variable is definable in a single variable statement separated by commas or line feeds with a semicolon terminating the total statement.
Multiple named variables can be defined in a single line of a variable statement set off with commas.
No data may be associated with a named variable in a variable statement.
Named variables can be defined over from 0 up to 20 sets and thus one variable name may be associated with a single case or numerous individual variables, each associated with a specific simultaneous collection of set elements for each of the named sets.
Every optimization model must contain at least one unrestricted named variable (i.e. one defined with just the Variable or the Free Variable type).
Such definitions indicate that these variables are potentially defined for every element of the defining sets (also called the domain).  However the actual definition of variables does not occur until the .. equation specifications are evaluated as discussed later.
The optional attribute data are discussed in the variable and equation attribute section.