friendlysam.parts.FlowNetwork

class friendlysam.parts.FlowNetwork(resource, name=None)

Manages flows between nodes.

FlowNetwork creates flow variables and can connect Node instances by changing their inflows and outflows.

Parameters:
  • resource – The resource flowing in the network.
  • name (str, optional) – The name of the network.

Examples

We create three nodes: A producer, a storage, and a consumer.

>>> producer = Node(name='producer')
>>> producer.production['R'] = VariableCollection('prod')
>>> consumer = Node(name='consumer')
>>> consumer.consumption['R'] = VariableCollection('cons')
>>> storage = Storage(resource='R', name='storage')

Connect the producer to the storage, and the storage to the consumer.

>>> network = FlowNetwork(resource='R', name='network')
>>> network.connect(producer, storage)
>>> network.connect(storage, consumer)
>>> for part in [producer, consumer, storage]:
...     for constr in part.constraints.make(5):
...         print(constr.origin.owner)
...         print(constr.expr)
...         print()
...
producer
prod(5) == network.flow(producer-->storage)(5)

consumer
network.flow(storage-->consumer)(5) == cons(5)

storage
network.flow(producer-->storage)(5) == network.flow(storage-->consumer)(5) + storage.volume(6) - storage.volume(5)
FlowNetwork.add_part(part) Add a part to this part.
FlowNetwork.connect(n1, n2[, bidirectional, ...]) Connect two nodes.
FlowNetwork.find(name) Try to find a part by name.
FlowNetwork.get_flow(n1, n2) Get a flow between two nodes.
FlowNetwork.iter_times(start, *range_args) A generator yielding a sequence of times.
FlowNetwork.iter_times_between(start, end) A generator yielding all times between two points.
FlowNetwork.parts([depth, include_self]) Get contained parts, recursively.
FlowNetwork.remove_part(part)
FlowNetwork.state_variables(index) The state variables are all the flow variables.
FlowNetwork.step_time(index, num_steps) A function for stepping forward or backward in time.
FlowNetwork.times(start, *range_args) Get a sequence of times.
FlowNetwork.times_between(start, end) Get a tuple of all times between two points.
FlowNetwork.children Parts in this part, excluding self.
FlowNetwork.children_and_self Parts in this part, including self.
FlowNetwork.constraints For defining and generating constraints.
FlowNetwork.descendants All children, children of children, etc, excluding self.
FlowNetwork.descendants_and_self All children, children of children, etc, including self.
FlowNetwork.graph A graph of all the flows.
FlowNetwork.name A name for the object.
FlowNetwork.time_unit The time unit used in step_time().