Network.set_demand

Network.set_demand(data=None, is_label: bool = True, map_label: bool = True, mode: str = 'linear', **kwargs) None[source]

Set demand of network.

Parameters
datademand-like, optional

If data is a DemandFunction, demand is set to data. Else, demand will be set based on mode.

is_labelbool, default=True

Whether commodities in data have labels.

map_labelbool, default=True

Whether to map node labels in data to node ids.

modestr, default=’linear’
1.’linear’:

data is used to build LinearDemandFunction.

2.’affine’:

data is used to build AffineDemandFunction.

3.’to_linear’:

Use current demand direction to build LinearDemandFunction, data must be None.

4.’to_affine’:

Build AffineDemandFunction where base demand is set by data. Demand direction is used from current demand function.

kwargskeyword arguments, optional

Arguments passed to LinearDemandFunction or AffineDemandFunction.

Raises
ValueError

If mode == 'affine' and data is not a tuple of len = 2.

ValueError

If mode == 'to_linear' and data is not None.

TypeError

If mode == 'to_affine' and demand of network is not a LinearDemandFunction.

ValueError

If mode is not in [‘linear’, ‘affine’, ‘to_linear’, ‘to_affine].

Examples

Setting a linear demand function that consists of two commodities. A commodity may be specified by a tuple (source, target, rate) or a dict {source: -rate, target1: rate/2, target2: rate/2}.

>>> import paminco
>>> net = paminco.net.load_sioux()
>>> net.set_demand([(1, 2, 400), {7: -100, 4: 100}], is_label=False)
>>> net.demand(1.5).toarray()[:8]
array([[   0.,    0.],
       [-600.,    0.],
       [ 600.,    0.],
       [   0.,    0.],
       [   0.,  150.],
       [   0.,    0.],
       [   0.,    0.],
       [   0., -150.]])

Setting an affine demand function.

>>> import paminco
>>> net = paminco.net.load_sioux()
>>> net.set_demand(((1, 2, 400), (7, 4, 100)), is_label=False, mode="affine")
>>> net.demand(3).toarray()[:8]
array([[   0.],
       [-400.],
       [ 400.],
       [   0.],
       [ 300.],
       [   0.],
       [   0.],
       [-300.]])