# Variables¶

Variables are intended to ultimately be given values by an optimization package. They are declared and optionally bounded, given initial values, and documented using the Pyomo Var function. If index sets are given as arguments to this function they are used to index the variable. Other optional directives include:

• bounds = A function (or Python object) that gives a (lower,upper) bound pair for the variable
• domain = A set that is a super-set of the values the variable can take on.
• initialize = A function (or Python object) that gives a starting value for the variable; this is particularly important for non-linear models
• within = (synonym for domain)

The following code snippet illustrates some aspects of these options by declaring a singleton (i.e. unindexed) variable named model.LumberJack that will take on real values between zero and 6 and it initialized to be 1.5:

model.LumberJack = Var(within=NonNegativeReals, bounds=(0,6), initialize=1.5)


Instead of the initialize option, initialization is sometimes done with a Python assignment statement as in

model.LumberJack = 1.5


For indexed variables, bounds and initial values are often specified by a rule (a Python function) that itself may make reference to parameters or other data. The formal arguments to these rules begins with the model followed by the indexes. This is illustrated in the following code snippet that makes use of Python dictionaries declared as lb and ub that are used by a function to provide bounds:

model.A = Set(initialize=['Scones', 'Tea'])
lb = {'Scones':2, 'Tea':4}
ub = {'Scones':5, 'Tea':7}
def fb(model, i):
return (lb[i], ub[i])
model.PriceToCharge = Var(model.A, domain=PositiveIntegers, bounds=fb)


Note

Many of the pre-defined virtual sets that are used as domains imply bounds. A strong example is the set Boolean that implies bounds of zero and one.