sasoptpy.Model.add_variable

Model.add_variable(self, name, vartype=None, lb=None, ub=None, init=None)[source]

Adds a new variable to the model

New variables can be created via this method or existing variables can be added to the model.

Parameters
namestring

Name of the variable to be created

vartypestring, optional

Type of the variable, either sasoptpy.BIN, sasoptpy.INT or sasoptpy.CONT

lbfloat, optional

Lower bound of the variable

ubfloat, optional

Upper bound of the variable

initfloat, optional

Initial value of the variable

Returns
varVariable

Variable that is added to the model

Notes

  • name is a mandatory field for this method.

Examples

Adding a variable on the fly

>>> m = so.Model(name='demo')
>>> x = m.add_variable(name='x', vartype=so.INT, ub=10, init=2)
>>> print(repr(x))
NOTE: Initialized model demo
sasoptpy.Variable(name='x', lb=0, ub=10, init=2, vartype='INT')

Adding an existing variable to a model

>>> y = so.Variable(name='y', vartype=so.BIN)
>>> m = so.Model(name='demo')
>>> m.include(y)