import pypsa

n = pypsa.examples.ac_dc_meshed(from_master=True)

"""
Explanation: Constraining the total capacity per bus and carrier
In this small example, we limit the nominal capacity of generators of the same production carrier at the same bus. 
Therefore, we introduce a column nom_min_{carrier} and nom_max_{carrier} in the buses dataframe. These are then used as lower and upper bounds of generators of the same carrier at the same bus. 
We start with importing a small example network.
End of explanation
"""


n.add(
    "Generator",
    "Frankfurt Wind 2",
    bus="Frankfurt",
    capital_cost=120,
    carrier="wind",
    p_nom_extendable=True,
)

n.buses.loc[["Frankfurt", "Manchester"], "nom_min_wind"] = 2000
n.buses.loc[["Frankfurt"], "nom_max_wind"] = 2200

"""
Explanation: Now add a second wind generator at bus 'Frankfurt' and limit the combined capacity.
End of explanation
"""


n.lopf(pyomo=False)

print(n.generators.p_nom_opt)

"""
Explanation: We are running the lopf and check whether the constraint is fulfilled.
End of explanation
"""


