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
where are the capital costs per unit of nominal capacity for generators (), storage units (), stores (), links (), processes (), and lines and transformers (). The subscript labels the bus, labels the particular generator/storage type at the bus, labels the branch, and labels the process. The decision variables , , , , and are the nominal power capacities, whereas 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 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:
n.add("Generator", "wind",
bus="bus",
p_nom_extendable=True,
capital_cost=50000) # Already periodized: €/MWProvide overnight_cost (upfront investment cost), discount_rate, and lifetime. PyPSA automatically calculates the periodized cost:
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 yearsThe effective periodized cost per MW installation used in optimization is calculated as:
where 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:
or
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:
# 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
| Symbol | Attribute | Type |
|---|---|---|
n.generators.p_nom_opt | Decision variable | |
n.storage_units.p_nom_opt | Decision variable | |
n.stores.p_nom_opt | Decision variable | |
n.links.p_nom_opt | Decision variable | |
n.processes.p_nom_opt | Decision variable | |
n.lines.s_nom_opt | Decision variable | |
n.{generators,storage_units,stores}.capital_cost | Parameter | |
n.{links,lines,transformers}.capital_cost | Parameter | |
n.processes.capital_cost | Parameter | |
n.{generators,...}.overnight_cost | Parameter | |
n.{generators,...}.discount_rate | Parameter | |
n.{generators,...}.lifetime | Parameter | |
n.{generators,...}.fom_cost | Parameter |
Marginal Costs
The marginal costs of dispatch are given by
where are the marginal costs per unit of power for generator (), storage unit (), store (), link () and process () dispatch. Note here the difference between storage unit dispatch (where costs are only incurred for discharging) and store dispatch (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 indicates the snapshot.
Mapping of symbols to attributes
| Symbol | Attribute | Type |
|---|---|---|
n.generators_t.p | Decision variable | |
n.storage_units_t.p_dispatch | Decision variable | |
n.stores_t.p | Decision variable | |
n.links_t.p | Decision variable | |
n.processes_t.p | Decision variable | |
n.{generators,storage_units,stores}_t.marginal_cost | Parameter | |
n.links_t.marginal_cost | Parameter | |
n.processes_t.marginal_cost | Parameter | |
n.snapshots.weightings.objective | Parameter |
Quadratic Marginal Costs
Quadratic marginal costs can be included, which turn the problem into a quadratic program (QP):
where are the quadratic marginal costs per unit of dispatch for generators (), storage units (), stores (), links () and processes (), weighted by the objective snapshot weightings .
Mapping of symbols to attributes
| Symbol | Attribute | Type |
|---|---|---|
n.generators_t.p | Decision variable | |
n.storage_units_t.p_dispatch | Decision variable | |
n.stores_t.p | Decision variable | |
n.links_t.p | Decision variable | |
n.processes_t.p | Decision variable | |
n.{generators,storage_units,stores}_t.marginal_cost_quadratic | Parameter | |
n.links_t.marginal_cost_quadratic | Parameter | |
n.processes_t.marginal_cost_quadratic | Parameter | |
n.snapshots.weightings.objective | Parameter |
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:
where are the marginal storage costs per unit of energy for storage units () and stores (), weighted by the objective snapshot weightings .
Mapping of symbols to attributes
| Symbol | Attribute | Type |
|---|---|---|
n.storage_units_t.state_of_charge | Decision variable | |
n.stores_t.e | Decision variable | |
n.storage_units_t.marginal_cost_storage | Parameter | |
n.stores_t.marginal_cost_storage | Parameter | |
n.snapshots.weightings.objective | Parameter |
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
where are the spillage costs per unit of spillage (), weighted by the objective snapshot weightings .
Mapping of symbols to attributes
| Symbol | Attribute | Type |
|---|---|---|
n.storage_units_t.spillage | Decision variable | |
n.storage_units_t.spill_cost | Parameter | |
n.snapshots.weightings.objective | Parameter |
Start-Up, Shut-Down, Stand-By Costs
For generators, links and processes with unit commitment (committable=True), stand-by costs , start-up costs and shut-down costs are given by
GeneratorLinkProcess
where , , and are the stand-by, start-up, and shut-down costs linked to the status (), start-up (), and shut-down () unit commitment variables. Only the stand-by costs are weighted by the objective snapshot weightings . Components with unit commitment constraints turn the problem into a mixed-integer linear program (MILP).
Mapping of symbols to attributes
GeneratorLinkProcess
| Symbol | Attribute | Type |
|---|---|---|
n.generators_t.status | Decision variable | |
n.generators_t.start_up | Decision variable | |
n.generators_t.shut_down | Decision variable | |
n.generators_t.stand_by_cost | Parameter | |
n.generators_t.start_up_cost | Parameter | |
n.generators_t.shut_down_cost | Parameter | |
n.snapshots.weightings.objective | Parameter |
| Symbol | Attribute | Type |
|---|---|---|
n.links_t.status | Decision variable | |
n.links_t.start_up | Decision variable | |
n.links_t.shut_down | Decision variable | |
n.links_t.stand_by_cost | Parameter | |
n.links_t.start_up_cost | Parameter | |
n.links_t.shut_down_cost | Parameter | |
n.snapshots.weightings.objective | Parameter |
| Symbol | Attribute | Type |
|---|---|---|
n.processes_t.status | Decision variable | |
n.processes_t.start_up | Decision variable | |
n.processes_t.shut_down | Decision variable | |
n.processes_t.stand_by_cost | Parameter | |
n.processes_t.start_up_cost | Parameter | |
n.processes_t.shut_down_cost | Parameter | |
n.snapshots.weightings.objective | Parameter |
Ramp Costs
For generators, links and processes, the ramp-up costs and ramp-down costs are given by
GeneratorLinkProcess
where the increase in dispatch (p0 for links and processes) is defined in define_ramp_cost_constraints(), and the decrease 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 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
| Symbol | Attribute | Type |
|---|---|---|
n.generators_t.ramp_up | Decision variable | |
n.generators_t.ramp_down | Derived Output | |
n.generators_t.ramp_up_cost | Parameter | |
n.generators_t.ramp_down_cost | Parameter |
| Symbol | Attribute | Type |
|---|---|---|
n.links_t.ramp_up | Decision variable | |
n.links_t.ramp_down | Derived Output | |
n.links_t.ramp_up_cost | Parameter | |
n.links_t.ramp_down_cost | Parameter |
| Symbol | Attribute | Type |
|---|---|---|
n.processes_t.ramp_up | Decision variable | |
n.processes_t.ramp_down | Derived Output | |
n.processes_t.ramp_up_cost | Parameter | |
n.processes_t.ramp_down_cost | Parameter |
Some decision variables do not show up in the objective function, such as the power flow on lines and transformers () and the storage unit charging (). 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().
2026-12-01
2025-10-09