Note

You can download this example as a Jupyter notebook or start it in interactive mode.

# Multi-Link usage: CHP with fixed heat-power ratio#

This notebook if a demonstration of Link with multiple outputs: Combined-Heat-and-Power (CHP) with fixed heat-power ratio

For a CHP with a more complicated heat-power feasible operational area, see the power-to-gas example

This example demonstrates a Link component with more than one bus output (“bus2” in this case). In general links can have many output buses.

In this example a CHP must be heat-following because there is no other supply of heat to the bus “Frankfurt heat”.

```
[1]:
```

```
import pypsa, numpy as np
```

```
[2]:
```

```
network = pypsa.Network()
network.add("Bus", "Frankfurt", carrier="AC")
network.add("Load", "Frankfurt", bus="Frankfurt", p_set=5)
network.add("Bus", "Frankfurt heat", carrier="heat")
network.add("Load", "Frankfurt heat", bus="Frankfurt heat", p_set=3)
network.add("Bus", "Frankfurt gas", carrier="gas")
network.add("Store", "Frankfurt gas", e_initial=1e6, e_nom=1e6, bus="Frankfurt gas")
network.add(
"Link",
"OCGT",
bus0="Frankfurt gas",
bus1="Frankfurt",
p_nom_extendable=True,
capital_cost=600,
efficiency=0.4,
)
network.add(
"Link",
"CHP",
bus0="Frankfurt gas",
bus1="Frankfurt",
bus2="Frankfurt heat",
p_nom_extendable=True,
capital_cost=1400,
efficiency=0.3,
efficiency2=0.3,
)
```

```
[3]:
```

```
network.optimize();
```

```
WARNING:pypsa.components:The following links have bus2 which are not defined:
Index(['OCGT'], dtype='object', name='Link')
WARNING:pypsa.components:The following links have bus2 which are not defined:
Index(['OCGT'], dtype='object', name='Link')
INFO:linopy.model: Solve problem using Glpk solver
INFO:linopy.io: Writing time: 0.06s
INFO:linopy.constants: Optimization successful:
Status: ok
Termination condition: optimal
Solution: 6 primals, 12 duals
Objective: 1.70e+04
Solver model: not available
Solver message: optimal
INFO:pypsa.optimization.optimize:The shadow-prices of the constraints Link-ext-p-lower, Link-ext-p-upper, Store-fix-e-lower, Store-fix-e-upper, Store-energy_balance were not assigned to the network.
```

```
GLPSOL--GLPK LP/MIP Solver 5.0
Parameter(s) specified in the command line:
--lp /tmp/linopy-problem-ymlh5_rj.lp --output /tmp/linopy-solve-_0rvw0a8.sol
Reading problem data from '/tmp/linopy-problem-ymlh5_rj.lp'...
12 rows, 6 columns, 18 non-zeros
68 lines were read
GLPK Simplex Optimizer 5.0
12 rows, 6 columns, 18 non-zeros
Preprocessing...
~ 0: obj = 1.700000000e+04 infeas = 0.000e+00
OPTIMAL SOLUTION FOUND BY LP PREPROCESSOR
Time used: 0.0 secs
Memory used: 0.0 Mb (39693 bytes)
Writing basic solution to '/tmp/linopy-solve-_0rvw0a8.sol'...
```

```
[4]:
```

```
network.loads_t.p
```

```
[4]:
```

Load | Frankfurt | Frankfurt heat |
---|---|---|

snapshot | ||

now | 5.0 | 3.0 |

```
[5]:
```

```
network.links_t.p0
```

```
[5]:
```

Link | OCGT | CHP |
---|---|---|

snapshot | ||

now | 5.0 | 10.0 |

```
[6]:
```

```
network.links_t.p1
```

```
[6]:
```

Link | OCGT | CHP |
---|---|---|

snapshot | ||

now | -2.0 | -3.0 |

```
[7]:
```

```
network.links_t.p2
```

```
[7]:
```

Link | OCGT | CHP |
---|---|---|

snapshot | ||

now | 0.0 | -3.0 |