Post · 10 min read· pp. 290–298

Objective

The objective is to minimise total system costs (i.e. the sum of all costs) subject to meeting all constraints of the optimisation problem (e.g. energy balance, dispatch limits, etc.) for the selected snapshots.

The objective function is composed of investment costs and multiple forms of operational costs, such as marginal costs, quadratic marginal costs, marginal storage costs, spillage costs, start-up, shut-down and stand-by costs, and ramp costs.

Which cost components are included in the objective function depends on the data provided for the network components. For instance, if no extendable components are present ({p,s,e}_nom_extendable=False), the investment cost terms are skipped. Or, if no components are marked as committable (committable=False), the start-up, shut-down and stand-by costs are skipped. All cost coefficients default to zero, so that the objective function is empty if no costs are defined.

Investment Costs

For extendable components ({p,s,e}_nom_extendable=True), the investment costs of expanding their capacity are given by

∑n,scn,sGn,s+∑n,scn,sHn,s+∑n,scn,sEn,s+∑lclFl+∑mcmRm+∑lclPl\sum_{n,s} c_{n,s} G_{n,s} + \sum_{n,s} c_{n,s} H_{n,s} + \sum_{n,s} c_{n,s} E_{n,s} + \sum_{l} c_{l} F_l + \sum_{m} c_{m} R_m + \sum_{l} c_{l} P_l

where c∗c_{*} are the capital costs per unit of nominal capacity for generators (Gn,s∈RG_{n,s} \in \mathbb{R}), storage units (Hn,s∈RH_{n,s} \in \mathbb{R}), stores (En,s∈RE_{n,s} \in \mathbb{R}), links (Fl∈RF_l \in \mathbb{R}), processes (Rm∈RR_m \in \mathbb{R}), and lines and transformers (Pl∈RP_l \in \mathbb{R}). The subscript nn labels the bus, ss labels the particular generator/storage type at the bus, ll labels the branch, and mm labels the process. The decision variables Gn,sG_{n,s}, Hn,sH_{n,s}, FlF_l, RmR_m, and PlP_l are the nominal power capacities, whereas En,sE_{n,s} is the nominal energy capacity of the store. The capital costs are given in currency/MW for generators, links, processes, lines and transformers, and in currency/MWh for stores.

To minimise long-run annual system costs (currency/a), capital costs for components should be set to annualised investment costs (i.e. currency/MW/a and currency/MWh/a ), marginal costs for dispatch in currency/MWh, and the weightings (h/a) are chosen such that ∑twto=8760\sum_t w_t^o = 8760 hours per annum.

If no extendable components are present, only the dispatch of the components is optimised as in a short-run market model.

Specifying Capital Costs

PyPSA supports two approaches for specifying investment costs:

Direct periodized capital cost (default)Overnight cost with automatic periodization

Provide capital_cost directly as annualized cost per unit capacity (currency/MW or currency/MWh) per model period:

text
n.add("Generator", "wind",
      bus="bus",
      p_nom_extendable=True,
      capital_cost=50000)  # Already periodized: €/MW

Provide overnight_cost (upfront investment cost), discount_rate, and lifetime. PyPSA automatically calculates the periodized cost:

text
n.add("Generator", "wind",
      bus="bus",
      p_nom_extendable=True,
      overnight_cost=1200000,  # Upfront cost: €/MW
      discount_rate=0.07,      # 7% discount rate
      lifetime=25)             # 25 years

The effective periodized cost per MW installation used in optimization is calculated as:

@@MATHPH31@@@@MATH_PH_31@@ where NyearsN_{\text{years}} refers to the model time span in units of years, derived from n.snapshot_weightings["objective"]. The annuity factor converts overnight cost to annual payments:

annuity(r,n)=r1−(1+r)−n\text{annuity}(r, n) = \frac{r}{1 - (1 + r)^{-n}}

or

1nifr=0\frac{1}{n} \text{if} r=0

Fixed Operation & Maintenance Costs

Fixed O&M costs (fom_cost) represent another type of periodized costs that are incurred regardless of dispatch, such as maintenance, insurance, and land lease:

text
# Wind turbine with 2% of overnight cost as annual FOM
n.generators.loc["wind", "fom_cost"] = 0.02 * n.generators.loc["wind", "overnight_cost"]

Mapping of symbols to attributes

SymbolAttributeType
Gn,sG_{n,s}n.generators.p_nom_optDecision variable
Hn,sH_{n,s}n.storage_units.p_nom_optDecision variable
En,sE_{n,s}n.stores.p_nom_optDecision variable
FlF_ln.links.p_nom_optDecision variable
RmR_mn.processes.p_nom_optDecision variable
PlP_ln.lines.s_nom_optDecision variable
cn,sc_{n,s}n.{generators,storage_units,stores}.capital_costParameter
clc_{l}n.{links,lines,transformers}.capital_costParameter
cmc_{m}n.processes.capital_costParameter
covernightc_{\text{overnight}}n.{generators,...}.overnight_costParameter
rrn.{generators,...}.discount_rateParameter
nnn.{generators,...}.lifetimeParameter
cfomc_{\text{fom}}n.{generators,...}.fom_costParameter

Marginal Costs

The marginal costs of dispatch are given by

+∑twto(∑n,son,s,tgn,s,t+∑n,son,s,thn,s,t−+∑n,son,s,thn,s,t+∑lol,tfl,t+∑mom,trm,t)+ \sum_{t} w_t^o \left( \sum_{n,s} o_{n,s,t} g_{n,s,t} + \sum_{n,s} o_{n,s,t} h_{n,s,t}^- + \sum_{n,s} o_{n,s,t} h_{n,s,t} + \sum_{l} o_{l,t} f_{l,t} + \sum_{m} o_{m,t} r_{m,t} \right)

where o∗o_{*} are the marginal costs per unit of power for generator (gn,s,t∈Rg_{n,s,t} \in \mathbb{R}), storage unit (hn,s,t−∈Rh_{n,s,t}^- \in \mathbb{R}), store (hn,s,t∈Rh_{n,s,t} \in \mathbb{R}), link (fl,t∈Rf_{l,t} \in \mathbb{R}) and process (rm,t∈Rr_{m,t} \in \mathbb{R}) dispatch. Note here the difference between storage unit dispatch hn,s,t−h_{n,s,t}^- (where costs are only incurred for discharging) and store dispatch hn,s,th_{n,s,t} (where marginal costs incur a cost for discharging and a revenue for charging; the store attributes marginal_cost_dispatch and marginal_cost_store apply to one direction only, see storage). The subscript tt indicates the snapshot.

Mapping of symbols to attributes

SymbolAttributeType
gn,s,tg_{n,s,t}n.generators_t.pDecision variable
hn,s,t−h_{n,s,t}^-n.storage_units_t.p_dispatchDecision variable
hn,s,th_{n,s,t}n.stores_t.pDecision variable
fl,tf_{l,t}n.links_t.pDecision variable
rm,tr_{m,t}n.processes_t.pDecision variable
on,s,to_{n,s,t}n.{generators,storage_units,stores}_t.marginal_costParameter
ol,to_{l,t}n.links_t.marginal_costParameter
om,to_{m,t}n.processes_t.marginal_costParameter
wtow_t^on.snapshots.weightings.objectiveParameter

Quadratic Marginal Costs

Quadratic marginal costs can be included, which turn the problem into a quadratic program (QP):

+∑twto(∑n,sqmcn,s,tgn,s,t2+∑n,sqmcn,s,thn,s,t−2+∑n,sqmcn,s,thn,s,t2+∑lqmcl,tfl,t2+∑mqmcm,trm,t2)+ \sum_{t} w_t^o \left( \sum_{n,s} qmc_{n,s,t} g_{n,s,t}^2 + \sum_{n,s} qmc_{n,s,t} {h_{n,s,t}^-}^2 + \sum_{n,s} qmc_{n,s,t} h_{n,s,t}^2 + \sum_{l} qmc_{l,t} f_{l,t}^2 + \sum_{m} qmc_{m,t} r_{m,t}^2 \right)

where qmc∗qmc_{*} are the quadratic marginal costs per unit of dispatch for generators (gn,s,tg_{n,s,t}), storage units (hn,s,t−h_{n,s,t}^-), stores (hn,s,th_{n,s,t}), links (fl,tf_{l,t}) and processes (rm,tr_{m,t}), weighted by the objective snapshot weightings wtow_t^o.

Mapping of symbols to attributes

SymbolAttributeType
gn,s,tg_{n,s,t}n.generators_t.pDecision variable
hn,s,t−h_{n,s,t}^-n.storage_units_t.p_dispatchDecision variable
hn,s,th_{n,s,t}n.stores_t.pDecision variable
fl,tf_{l,t}n.links_t.pDecision variable
rm,tr_{m,t}n.processes_t.pDecision variable
qmcn,s,tqmc_{n,s,t}n.{generators,storage_units,stores}_t.marginal_cost_quadraticParameter
qmcl,tqmc_{l,t}n.links_t.marginal_cost_quadraticParameter
qmcm,tqmc_{m,t}n.processes_t.marginal_cost_quadraticParameter
wtow_t^on.snapshots.weightings.objectiveParameter

Marginal Storage Costs

Marginal storage costs can also be applied to storage units and stores, which represent the cost of holding energy in storage. The objective function includes these costs as follows:

+∑twto(∑n,smcsn,s,tsocn,s,t+∑n,smcsn,s,ten,s,t)+ \sum_{t} w_t^o \left( \sum_{n,s} mcs_{n,s,t} soc_{n,s,t} + \sum_{n,s} mcs_{n,s,t} e_{n,s,t} \right)

where mcs∗mcs_{*} are the marginal storage costs per unit of energy for storage units (socn,s,t∈Rsoc_{n,s,t} \in \mathbb{R}) and stores (en,s,t∈Re_{n,s,t} \in \mathbb{R}), weighted by the objective snapshot weightings wtow_t^o.

Mapping of symbols to attributes

SymbolAttributeType
socn,s,tsoc_{n,s,t}n.storage_units_t.state_of_chargeDecision variable
en,s,te_{n,s,t}n.stores_t.eDecision variable
mcsn,s,tmcs_{n,s,t}n.storage_units_t.marginal_cost_storageParameter
mcsn,s,tmcs_{n,s,t}n.stores_t.marginal_cost_storageParameter
wtow_t^on.snapshots.weightings.objectiveParameter

Spillage Costs

Spillage costs, e.g. sending water in a hydro reservoir over a spillway without generating electricity, can be given for storage units by

+∑n,s,twtoscn,s,tspillagen,s,t+ \sum_{n,s,t} w_t^o sc_{n,s,t} \textrm{spillage}_{n,s,t}

where scn,s,tsc_{n,s,t} are the spillage costs per unit of spillage (spillagen,s,t∈R\textrm{spillage}_{n,s,t} \in \mathbb{R}), weighted by the objective snapshot weightings wtow_t^o.

Mapping of symbols to attributes

SymbolAttributeType
spillagen,s,t\textrm{spillage}_{n,s,t}n.storage_units_t.spillageDecision variable
scn,s,tsc_{n,s,t}n.storage_units_t.spill_costParameter
wtow_t^on.snapshots.weightings.objectiveParameter

Start-Up, Shut-Down, Stand-By Costs

For generators, links and processes with unit commitment (committable=True), stand-by costs sbc∗,tsbc_{*,t}, start-up costs suc∗,tsuc_{*,t} and shut-down costs sdc∗,tsdc_{*,t} are given by

GeneratorLinkProcess

+∑n,s,twtosbcn,s,tun,s,t+∑n,s,tsucn,s,tsun,s,t+∑n,s,tsdcn,s,tsdn,s,t+ \sum_{n,s,t} w_t^o sbc_{n,s,t} u_{n,s,t} + \sum_{n,s,t} suc_{n,s,t} su_{n,s,t} + \sum_{n,s,t} sdc_{n,s,t} sd_{n,s,t}

+∑l,twtosbcl,tul,t+∑l,tsucl,tsul,t+∑l,tsdcl,tsdl,t+ \sum_{l,t} w_t^o sbc_{l,t} u_{l,t} + \sum_{l,t} suc_{l,t} su_{l,t} + \sum_{l,t} sdc_{l,t} sd_{l,t}

+∑m,twtosbcm,tum,t+∑m,tsucm,tsum,t+∑m,tsdcm,tsdm,t+ \sum_{m,t} w_t^o sbc_{m,t} u_{m,t} + \sum_{m,t} suc_{m,t} su_{m,t} + \sum_{m,t} sdc_{m,t} sd_{m,t}

where sbc∗,tsbc_{*,t}, suc∗,tsuc_{*,t}, and sdc∗,tsdc_{*,t} are the stand-by, start-up, and shut-down costs linked to the status (u∗,t∈Bu_{*,t} \in \mathbb{B}), start-up (su∗,t∈Bsu_{*,t} \in \mathbb{B}), and shut-down (sd∗,t∈Bsd_{*,t} \in \mathbb{B}) unit commitment variables. Only the stand-by costs are weighted by the objective snapshot weightings wtow_t^o. Components with unit commitment constraints turn the problem into a mixed-integer linear program (MILP).

Mapping of symbols to attributes

GeneratorLinkProcess

SymbolAttributeType
un,s,tu_{n,s,t}n.generators_t.statusDecision variable
sun,s,tsu_{n,s,t}n.generators_t.start_upDecision variable
sdn,s,tsd_{n,s,t}n.generators_t.shut_downDecision variable
sbcn,s,tsbc_{n,s,t}n.generators_t.stand_by_costParameter
sucn,s,tsuc_{n,s,t}n.generators_t.start_up_costParameter
sdcn,s,tsdc_{n,s,t}n.generators_t.shut_down_costParameter
wtow_t^on.snapshots.weightings.objectiveParameter
SymbolAttributeType
ul,tu_{l,t}n.links_t.statusDecision variable
sul,tsu_{l,t}n.links_t.start_upDecision variable
sdl,tsd_{l,t}n.links_t.shut_downDecision variable
sbcl,tsbc_{l,t}n.links_t.stand_by_costParameter
sucl,tsuc_{l,t}n.links_t.start_up_costParameter
sdcl,tsdc_{l,t}n.links_t.shut_down_costParameter
wtow_t^on.snapshots.weightings.objectiveParameter
SymbolAttributeType
um,tu_{m,t}n.processes_t.statusDecision variable
sum,tsu_{m,t}n.processes_t.start_upDecision variable
sdm,tsd_{m,t}n.processes_t.shut_downDecision variable
sbcm,tsbc_{m,t}n.processes_t.stand_by_costParameter
sucm,tsuc_{m,t}n.processes_t.start_up_costParameter
sdcm,tsdc_{m,t}n.processes_t.shut_down_costParameter
wtow_t^on.snapshots.weightings.objectiveParameter

Ramp Costs

For generators, links and processes, the ramp-up costs ruc∗,truc_{*,t} and ramp-down costs rdc∗,trdc_{*,t} are given by

GeneratorLinkProcess

+∑n,s,trucn,s,trn,s,t++∑n,s,trdcn,s,trn,s,t−+ \sum_{n,s,t} ruc_{n,s,t} r^+_{n,s,t} + \sum_{n,s,t} rdc_{n,s,t} r^-_{n,s,t}

+∑l,trucl,trl,t++∑l,trdcl,trl,t−+ \sum_{l,t} ruc_{l,t} r^+_{l,t} + \sum_{l,t} rdc_{l,t} r^-_{l,t}

+∑m,trucm,trm,t++∑m,trdcm,trm,t−+ \sum_{m,t} ruc_{m,t} r^+_{m,t} + \sum_{m,t} rdc_{m,t} r^-_{m,t}

where the increase in dispatch (p0 for links and processes) r∗,t+≥max⁡(0,p∗,t−p∗,t−1)r^+_{*,t} \geq \max(0, p_{*,t} - p_{*,t-1}) is defined in define_ramp_cost_constraints(), and the decrease r∗,t−=r∗,t+−(p∗,t−p∗,t−1)r^-_{*,t} = r^+_{*,t} - (p_{*,t} - p_{*,t-1}) is its slack. Both are only defined where a ramp cost is set and are not weighted by the snapshot weightings. The objective omits the constant rdc∗,trdc_{*,t} p_init at the first snapshot, which n.statistics.opex() includes.

Ramp costs of committable units

Ramp costs do not require unit commitment. For committable units, the change from zero output at start-up and to zero at shut-down is also charged, on top of start_up_cost and shut_down_cost.

Mapping of symbols to attributes

GeneratorLinkProcess

SymbolAttributeType
rn,s,t+r^+_{n,s,t}n.generators_t.ramp_upDecision variable
rn,s,t−r^-_{n,s,t}n.generators_t.ramp_downDerived Output
rucn,s,truc_{n,s,t}n.generators_t.ramp_up_costParameter
rdcn,s,trdc_{n,s,t}n.generators_t.ramp_down_costParameter
SymbolAttributeType
rl,t+r^+_{l,t}n.links_t.ramp_upDecision variable
rl,t−r^-_{l,t}n.links_t.ramp_downDerived Output
rucl,truc_{l,t}n.links_t.ramp_up_costParameter
rdcl,trdc_{l,t}n.links_t.ramp_down_costParameter
SymbolAttributeType
rm,t+r^+_{m,t}n.processes_t.ramp_upDecision variable
rm,t−r^-_{m,t}n.processes_t.ramp_downDerived Output
rucm,truc_{m,t}n.processes_t.ramp_up_costParameter
rdcm,trdc_{m,t}n.processes_t.ramp_down_costParameter

Some decision variables do not show up in the objective function, such as the power flow on lines and transformers (pl,t∈Rp_{l,t} \in \mathbb{R}) and the storage unit charging (hn,s,t+∈Rh_{n,s,t}^+ \in \mathbb{R}). They are only used to enforce constraints, e.g. the power flow on lines and transformers.

The objective function is defined in the function define_objective().

diagram 2026-12-01

diagram 2025-10-09