# sasoptpy.VariableGroup.mult¶

VariableGroup.mult(self, vector)[source]

Quick multiplication method for the variable groups

Parameters
vectorlist, dictionary, pandas.Series, or pandas.DataFrame

Vector to be multiplied with the variable group

Returns
rExpression

An expression that is the product of the variable group with the specified vector

Examples

Multiplying with a list

>>> x = so.VariableGroup(4, vartype=so.BIN, name='x')
>>> e1 = x.mult([1, 5, 6, 10])
>>> print(e1)
10.0 * x[3]  +  6.0 * x[2]  +  x[0]  +  5.0 * x[1]


Multiplying with a dictionary

>>> y = so.VariableGroup([0, 1], ['a', 'b'], name='y', lb=0, ub=10)
>>> dvals = {(0, 'a'): 1, (0, 'b'): 2, (1, 'a'): -1, (1, 'b'): 5}
>>> e2 = y.mult(dvals)
>>> print(e2)
2.0 * y[0, 'b']  -  y[1, 'a']  +  y[0, 'a']  +  5.0 * y[1, 'b']


Multiplying with a pandas.Series object

>>> u = so.VariableGroup(['a', 'b', 'c', 'd'], name='u')
>>> ps = pd.Series([0.1, 1.5, -0.2, 0.3], index=['a', 'b', 'c', 'd'])
>>> e3 = u.mult(ps)
>>> print(e3)
1.5 * u['b']  +  0.1 * u['a']  -  0.2 * u['c']  +  0.3 * u['d']


Multiplying with a pandas.DataFrame object

>>> data = np.random.rand(3, 3)
>>> df = pd.DataFrame(data, columns=['a', 'b', 'c'])
>>> print(df)
NOTE: Initialized model model1
a         b         c
0  0.966524  0.237081  0.944630
1  0.821356  0.074753  0.345596
2  0.065229  0.037212  0.136644
>>> y = m.add_variables(3, ['a', 'b', 'c'], name='y')
>>> e = y.mult(df)
>>> print(e)
0.9665237354418064 * y[0, 'a']  +  0.23708064143289442 * y[0, 'b']  +
0.944629500537536 * y[0, 'c']  +  0.8213562592159828 * y[1, 'a']  +
0.07475256894157478 * y[1, 'b']  +  0.3455957019116668 * y[1, 'c']  +
0.06522945752546017 * y[2, 'a']  +  0.03721153533250843 * y[2, 'b']  +
0.13664422498043194 * y[2, 'c']