autarky constraint for simple network

41 views
Skip to first unread message

Philipp

unread,
Aug 10, 2022, 9:37:23 AM8/10/22
to pypsa
Hello all,

I am trying to run an optimization based on a fixed autarky.

Pyomo is set to false, so the constraint needs to be formulated by various linear expressions. The autarky in my case is defined as 1-(grid_import/electrical_demand). I want to have the ability to set the autarky to a specific value (e.g. 0,9) and the model is optimized to this respect.

Right now my approach looks something like this:

join_exprs(linexpr((1, get_var(network, 'Generator', 'p')['grid_import'])))  (which should be my summerized grid import)

For the demand I can use a similar expression as in the "optimization without pyomo"-example for pypsa.readthedocs.io.

Out of this I want to formulate a constraint following x = 1-(grid_import/electrical_demand)

does anyone have a suggestion how i could build the linear expressions for the constraint?

Thanks and best wishes,

Philipp

Fabian Hofmann

unread,
Aug 15, 2022, 4:12:01 AM8/15/22
to py...@googlegroups.com

Hey Philipp,


how about reformulating the constraint, i.e.


grid_import <= x * electrical_demand


?


Best,

Fabian H

--
You received this message because you are subscribed to the Google Groups "pypsa" group.
To unsubscribe from this group and stop receiving emails from it, send an email to pypsa+un...@googlegroups.com.
To view this discussion on the web, visit https://groups.google.com/d/msgid/pypsa/4c141d19-9929-47a9-93c1-61eb8a0f55b3n%40googlegroups.com.
-- 
Fabian Hofmann 

Postdoctoral Researcher
Institute of Energy Technology
Technische Universität Berlin

Group website: https://tub-ensys.github.io/
Message has been deleted

Philipp

unread,
Aug 16, 2022, 7:02:45 AM8/16/22
to pypsa
Hi Fabian,

thanks, I will give it a try. Without testing my constraint currently looks like this:

def target_autarky(network, x):
    total_demand = network.loads_t.p_set.electricity_load.sum().sum()
    lhs = join_exprs(linexpr((1, get_var(network, 'Generator', 'p')['grid_import'])))
    rhs = x*total_demand
    define_constraints(
        network, lhs, "<=", rhs, "Generator", "proportional"
    )

At the moment I can't execute the command get_var(network, 'Generator', 'p').
This is the error massage:


It is not the first time i ran into this. Does anyone else experience this?

Best wishes,
Philipp

Philipp

unread,
Dec 12, 2022, 4:33:43 AM12/12/22
to pypsa
Hello all,

i want to reopen the question. I managed the constraint to optimize my network to a set autarky. Autarky was defined as 1-(grid_import/electrical_demand)

Since my network now contains heat_pumps, the autarky is now defined as 1-(grid_import/(electrical_demand+heat_pump_demand). So i need to adjust my rhs.

My attempt to form the overall load as sum of base demand and heat pump demand looks like this:

linexpr((1, get_var(network, 'Link', 'p')['heat_pump']), (1, get_var(network, 'Load', 'p')['electrical_load']))

, but it seems like get_var() can't deal with the 'Load'.

Despite the above problem, I am not sure if this kind of problem can by solved by a linear optimization. Maybe someone can help me with these two questions.

Many thanks,
Philipp

Fabian Neumann

unread,
Dec 12, 2022, 4:51:49 AM12/12/22
to pypsa
Hi Philipp,

this is because the load is not a variable, but a constant of the optimisation problem. You can just access n.loads_t.p_set.

Best wishes,

Fabian N

Philipp

unread,
Dec 12, 2022, 9:46:56 AM12/12/22
to pypsa
Hi Fabian,

thanks for your reply. I knew that I could use n.loads_t.p_set since I did this before in my scenario without a heat pump, but my problem was to merge this constant with a variable to form the rhs.

I solved my issue by rearranging the equation of the autarky so my rhs is just the constant load and my lhs looks like this:

lhs = join_exprs(
        linexpr(
            (1, get_var(network, 'Generator', 'p')['grid_import']), (-x, get_var(network, 'Link', 'p')['heat_pump']))
            )
x is 1-(my desired) autarky. Maybe this helps someone with a similar problem :)

Best wishes,
Philipp
Reply all
Reply to author
Forward
0 new messages