Exemplo n.º 1
0
    # This code causes an unwanted tight coupling between the `groupings` and
    # `network` modules, resulting in having to do an import at runtime in the
    # init method of solph's `EnergySystem`. A better way would be to add a
    # method (maybe `constraints`, `constraint_group`, `constraint_type` or
    # something like that) to solph's node hierarchy, which gets overridden in
    # each subclass to return the appropriate value. Then we can just call the
    # method here.
    # This even gives other users/us the ability to customize/extend how
    # constraints are grouped by overriding the method in future subclasses.
    if isinstance(node, Bus) and node.balanced:
        return blocks.Bus
    if type(node) == Transformer:
        return blocks.Transformer


investment_flow_grouping = groupings.FlowsWithNodes(
    constant_key=blocks.InvestmentFlow,
    # stf: a tuple consisting of (source, target, flow), so stf[2] is the flow.
    filter=lambda stf: stf[2].investment is not None)

standard_flow_grouping = groupings.FlowsWithNodes(constant_key=blocks.Flow)

nonconvex_flow_grouping = groupings.FlowsWithNodes(
    constant_key=blocks.NonConvexFlow,
    filter=lambda stf: stf[2].nonconvex is not None)

GROUPINGS = [
    constraint_grouping, investment_flow_grouping, standard_flow_grouping,
    nonconvex_flow_grouping
]
Exemplo n.º 2
0
    if type(node) == ExtractionTurbine:
        return blocks.ExtractionTurbine
    if type(node) == ExtractionTurbineExtended:
        return blocks.ExtractionTurbineExtended
    if type(node) == BackpressureTurbine:
        return blocks.BackpressureTurbine
    if type(node) == BackpressureTurbineExtended:
        return blocks.BackpressureTurbineExtended
    if type(node) == Boiler:
        return solph.blocks.LinearTransformer
    if type(node) == solph.Bus and node.balanced:
        return solph.blocks.Bus


investment_flow_grouping = groupings.FlowsWithNodes(
    constant_key=solph.blocks.InvestmentFlow,
    # stf: a tuple consisting of (source, target, flow), so stf[2] is the flow.
    filter=lambda stf: stf[2].investment is not None)

standard_flow_grouping = groupings.FlowsWithNodes(
    constant_key=solph.blocks.Flow)

binary_flow_grouping = groupings.FlowsWithNodes(
    constant_key=solph.blocks.BinaryFlow,
    filter=lambda stf: stf[2].binary is not None)

discrete_flow_grouping = groupings.FlowsWithNodes(
    constant_key=solph.blocks.DiscreteFlow,
    filter=lambda stf: stf[2].discrete is not None)

GROUPINGS = [
    constraint_grouping, standard_flow_grouping, binary_flow_grouping,
Exemplo n.º 3
0
    # TODO: Refactor this for looser coupling between modules.
    # This code causes an unwanted tight coupling between the `groupings` and
    # `network` modules, resulting in having to do an import at runtime in the
    # init method of solph's `EnergySystem`. A better way would be to add a
    # method (maybe `constraints`, `constraint_group`, `constraint_type` or
    # something like that) to solph's node hierarchy, which gets overridden in
    # each subclass to return the appropriate value. Then we can just call the
    # method here.
    # This even gives other users/us the ability to customize/extend how
    # constraints are grouped by overriding the method in future subclasses.

    cg = getattr(node, "constraint_group", fallback)
    return cg()


standard_flow_grouping = groupings.FlowsWithNodes(constant_key=blocks.Flow)


def _investment_grouping(stf):
    if hasattr(stf[2], 'investment'):
        if stf[2].investment is not None:
            return True
    else:
        return False


investment_flow_grouping = groupings.FlowsWithNodes(
    constant_key=blocks.InvestmentFlow,
    # stf: a tuple consisting of (source, target, flow), so stf[2] is the flow.
    filter=_investment_grouping)