예제 #1
0
def define_mga_objective(n):

    components, pattern, sense = n.mga_obj

    if isinstance(components, str):
        components = [components]

    terms = []
    for c in components:

        variables = get_var(n, c,
                            nominal_attrs[c]).filter(regex=to_regex(pattern))

        if c in ["Link", "Line"] and pattern in ["", "LN|LK", "LK|LN"]:
            coeffs = sense * n.df(c).loc[variables.index, "length"]
        else:
            coeffs = sense

        terms.append(linexpr((coeffs, variables)))

    joint_terms = pd.concat(terms)

    write_objective(n, joint_terms)

    # print objective to console
    print(joint_terms)
예제 #2
0
def mga_objective(network, snapshots, direction, options):
    mga_variables = options['mga_variables']
    expr_list = []
    for i, variable in enumerate(mga_variables):
        if variable == 'transmission':
            expr_list.append(
                linexpr((direction[i], get_var(network, 'Link',
                                               'p_nom'))).sum())
        if variable == 'co2_emission':
            expr_list.append(
                linexpr((direction[i], get_var(
                    network, 'Generator', 'p').filter(network.generators.index[
                        network.generators.type == 'ocgt']))).sum().sum())
        elif variable == 'H2' or variable == 'battery':
            expr_list.append(
                linexpr((direction[i], get_var(
                    network, 'StorageUnit',
                    'p_nom').filter(network.storage_units.index[
                        network.storage_units.carrier == variable]))).sum())
        else:
            expr_list.append(
                linexpr(
                    (direction[i],
                     get_var(network, 'Generator',
                             'p_nom').filter(network.generators.index[
                                 network.generators.type == variable]))).sum())

    mga_obj = join_exprs(np.array(expr_list))
    write_objective(network, mga_obj)
예제 #3
0
def add_mga_objective(net, sense='min'):

    # Minimize transmission capacity
    link_p_nom = get_var(net, 'Link', 'p_nom')
    sense = 1 if sense == 'min' else -1
    link_capacity_expr = linexpr((sense, link_p_nom)).sum()

    write_objective(net, link_capacity_expr)
예제 #4
0
def add_mga_objective(net: pypsa.Network, mga_type: str):

    if mga_type == 'link':
        # Minimize transmission capacity (in TWkm)
        p_nom = get_var(net, 'Link', 'p_nom')[net.components_to_minimize]
        capacity_expr = linexpr(
            (net.links.length[net.components_to_minimize], p_nom)).sum()
        write_objective(net, capacity_expr)

    elif mga_type == 'storage':
        # Minimize storage energy/power capacity
        p_nom = get_var(net, 'StorageUnit',
                        'p_nom')[net.components_to_minimize]
        capacity_expr = linexpr((1, p_nom)).sum()
        write_objective(net, capacity_expr)

    elif mga_type == 'generator-cap':
        # Minimize generators power capacity
        p_nom = get_var(net, 'Generator', 'p_nom')[net.components_to_minimize]
        capacity_expr = linexpr((1, p_nom)).sum()
        write_objective(net, capacity_expr)

    elif mga_type == 'generator-power':
        # Minimize generators power generation
        p = get_var(net, 'Generator', 'p')[net.components_to_minimize]
        capacity_expr = linexpr((1, p)).sum().sum()
        write_objective(net, capacity_expr)
예제 #5
0
def add_to_objective(n, snapshots):
    """
    adds to the pypsa objective function the costs for the Netzbooster,
    these consists of:
        (a) costs for the capacities of the Netzbooster
        (b) costs for compensation dispatch (e.g. paid to DSM consumers, for storage)

    i => bus
    t => snapshot
    k => outage
    """

    logger.info("define objective")

    n.determine_network_topology()
    sub = n.sub_networks.at["0", "obj"]
    sub.calculate_PTDF()
    sub.calculate_BODF()

    buses = sub.buses_i()
    lines = sub.lines_i()
    outages = [l for l in lines if "outage" in l]

    coefficient1 = 18100
    coefficient2 = 10

    #  (a) costs for Netzbooster capacities
    # sum_i ( c_pos * P(i)_pos + c_neg * P(i)_neg)
    # add noise to the netzbooster capacitiy costs to avoid numerical troubles
    coefficient1_noise = np.random.normal(coefficient1, .01, get_var(n, "Bus", "P_pos").shape)
    coefficient1_noise2 = np.random.normal(coefficient1, .01, get_var(n, "Bus", "P_pos").shape)
    netzbooster_cap_cost = linexpr(
                                (coefficient1_noise, get_var(n, "Bus", "P_pos")),
                                (coefficient1_noise2, get_var(n, "Bus", "P_neg"))
                                ).sum()

    write_objective(n, netzbooster_cap_cost)


    # (b) costs for compensation dispatch (paid to DSM consumers/running costs for storage)
    # sum_(i, t, k) ( o_pos * p(i, t, k)_pos + o_neg * p(i, t, k)_pos)
    # add noise to the marginal costs to avoid numerical troubles
    coefficient2_noise = np.random.normal(coefficient2, .00001, get_var(n, "Bus", "p_pos").shape)
    coefficient2_noise2 = np.random.normal(coefficient2, .00001, get_var(n, "Bus", "p_pos").shape)
    compensate_p_cost = linexpr(
                                (coefficient2_noise, get_var(n, "Bus", "p_pos").loc[snapshots]),
                                (coefficient2_noise2, get_var(n, "Bus", "p_neg").loc[snapshots]),
                                ).sum().sum()

    write_objective(n, compensate_p_cost)
예제 #6
0
def add_to_objective(n, snapshots):
    """
    adds to the pypsa objective function the costs for the Netzbooster,
    these consists of:
        (a) costs for the capacities of the Netzbooster
        (b) costs for compensation dispatch (e.g. paid to DSM consumers, for storage)

    i => bus
    t => snapshot
    k => outage
    """

    logger.info("define objective")

    n.determine_network_topology()
    sub = n.sub_networks.at["0", "obj"]
    sub.calculate_PTDF()
    sub.calculate_BODF()

    buses = sub.buses_i()
    lines = sub.lines_i()
    outages = [l for l in lines if "outage" in l]

    coefficient1 = float(snakemake.wildcards.flex_cost)  #18000
    coefficient2 = 1  #float(snakemake.wildcards.flex_cost)*0.001 #1

    #  (a) costs for Netzbooster capacities
    # sum_i ( c_pos * P(i)_pos + c_neg * P(i)_neg)
    netzbooster_cap_cost = linexpr(
        (coefficient1, get_var(n, "Bus", "P_pos").loc[buses]),
        (coefficient1, get_var(n, "Bus", "P_neg").loc[buses])).sum()

    write_objective(n, netzbooster_cap_cost)

    # (b) costs for compensation dispatch (paid to DSM consumers/running costs for storage)
    # sum_(i, t, k) ( o_pos * p(i, t, k)_pos + o_neg * p(i, t, k)_pos)

    compensate_p_cost = linexpr(
        (coefficient2, get_var(n, "Bus", "p_pos").loc[snapshots, buses]),
        (coefficient2, get_var(n, "Bus", "p_neg").loc[snapshots, buses]),
    ).sum().sum()

    write_objective(n, compensate_p_cost)
예제 #7
0
def add_to_objective(n, snapshots):

    logger.info("define objective")

    n.determine_network_topology()
    sub = n.sub_networks.at["0", "obj"]
    sub.calculate_PTDF()
    sub.calculate_BODF()

    buses = sub.buses_i()
    lines = sub.lines_i()
    outages = [l for l in lines if "outage" in l]

    coefficient1 = 1
    coefficient2 = 0.0001

    terms = linexpr(
        (coefficient1, get_var(n, "Bus", "P_pos").loc[buses]),
        (coefficient1, get_var(n, "Bus", "P_neg").loc[buses]),
        (coefficient2, get_var(n, "Bus", "p_pos").loc[buses].sum().sum()))

    write_objective(n, terms)