(sec_district_model)= # 🏙️ District Model The district model extends the single-building MILP of {doc}`building` to a **community of buildings** by applying a **Dantzig–Wolfe decomposition** (DWD). The district is modeled as a collection of Building Energy Systems (BES) coordinated by a district-level master problem that optimizes shared infrastructure and enforces community-level constraints. ```{figure} ../../images/model/district_energy_hub.png :align: center :width: 90% :name: fig_des_hub District energy hub: building-scale units are complemented by district-scale conversion and storage units, a shared network interface, and optional district heating/cooling infrastructure. ``` Key district additions over the building model: - **Decomposition algorithm** — tractable MILP for many-building districts - **Demand profile pooling** — realistic aggregated peaks via stochastic perturbation - **District heating/cooling networks** — pipe sizing and connection decisions - **Local mobility services** — multi-modal transport at community scale - **Grid reinforcement** — transformer and line capacity upgrades - **District renovation** — envelope decisions integrated in the master problem --- ## Dantzig–Wolfe decomposition ### Principle Rather than solving a single monolithic MILP over all buildings, the DWD decomposes the problem into: - A **master problem (MP)** that selects a convex combination of pre-generated building configurations and optimizes district-level variables (shared infrastructure, network). - **Building subproblems (SPs)** — one per building — that generate new attractive configurations in response to price signals (dual variables) from the master problem. This iterative procedure generates a decreasing sequence of upper bounds and an increasing sequence of lower bounds that converge to the optimal district solution. ```{figure} ../../images/model/decomposition_workflow.png :align: center :width: 85% :name: fig_dwd_workflow Dantzig–Wolfe decomposition workflow. ``` --- ### Master problem #### Configuration selection Each building $b$ is represented as a **convex combination** of feasible configurations $f \in \mathbb{F}$ generated by the subproblems: ```{math} :label: eq_convexity \sum_{f \in \mathbb{F}} \boldsymbol{\lambda}_{f,b} = 1, \qquad 0 \le \boldsymbol{\lambda}_{f,b} \le 1 \qquad \forall\, b \in \mathbb{B} ``` In the relaxed iterations $\boldsymbol{\lambda}_{f,b}$ can be fractional; in the final integer solve exactly one configuration per building is selected ($\boldsymbol{\lambda}_{f,b} \in \{0,1\}$). #### District energy balance At every timestep, the aggregate net exchange with the external network equals the sum of all building grid exchanges plus district-unit contributions: ```{figure} ../../images/model/DES_balance.png :align: center :width: 85% :name: fig_des_balance Energy balance of the district energy system. ``` ```{math} :label: eq_des_balance \dot{\boldsymbol{E}}_{l,p,t}^{\text{net},+} - \dot{\boldsymbol{E}}_{l,p,t}^{\text{net},-} = \sum_{f,b} \boldsymbol{\lambda}_{f,b} \bigl(\dot{\boldsymbol{E}}_{f,b,l,p,t}^{\text{gr},+} - \dot{\boldsymbol{E}}_{f,b,l,p,t}^{\text{gr},-}\bigr) + \sum_{u_d \in \mathbb{U_D}} \bigl(\dot{\boldsymbol{E}}_{u_d,l,p,t}^{+} - \dot{\boldsymbol{E}}_{u_d,l,p,t}^{-}\bigr) \qquad \forall\, l,p,t ``` The dual variable $\boldsymbol{\pi}_{l,p,t}$ associated with this constraint is the **internal energy price** — the marginal cost of providing one additional unit of carrier $l$ at timestep $(p,t)$. Network interface capacity is bounded by: ```{math} :label: eq_des_grid \dot{\boldsymbol{E}}_{l,p,t}^{\text{net},\pm} \le \dot{E}_{l}^{\text{net,max}} \qquad \forall\, l,p,t ``` #### District cost objective **OPEX** from external network exchanges: ```{math} :label: eq_des_opex \boldsymbol{C}^{\text{OPEX}} = \sum_{l,p,t} \bigl(c_l^+\,\dot{\boldsymbol{E}}_{l,p,t}^{\text{net},+} - c_l^-\,\dot{\boldsymbol{E}}_{l,p,t}^{\text{net},-}\bigr)\,d_p\,d_t ``` **CAPEX** for both building configurations and district-scale units: ```{math} :label: eq_des_capex \boldsymbol{C}^{\text{CAPEX}} = \frac{i(1+i)^n}{(1+i)^n-1}\bigl(\boldsymbol{C}^{\text{inv}} + \boldsymbol{C}^{\text{rep}}\bigr) ``` ```{math} \boldsymbol{C}^{\text{inv}} = \sum_{f,b} \boldsymbol{\lambda}_{f,b}\,C_{f,b}^{\text{inv}} + \sum_{u_d}\bigl(c_{u_d}^1\,\boldsymbol{y}_{u_d} + c_{u_d}^2\,\boldsymbol{f}_{u_d}\bigr) ``` **Total district GWP:** ```{math} :label: eq_des_gwp \boldsymbol{GWP}^{\text{op}} = \sum_{l,p,t}\bigl(cc^+_{l,p,t}\,\dot{\boldsymbol{E}}^{\text{net},+}_{l,p,t} - cc^-_{l,p,t}\,\dot{\boldsymbol{E}}^{\text{net},-}_{l,p,t}\bigr)\,d_t\,d_p ``` ```{math} \boldsymbol{GWP}^{\text{constr}} = \sum_{f,b} \boldsymbol{\lambda}_{f,b}\,GWP_{f,b}^{\text{constr}} + \sum_{u_d} \frac{1}{n_{u_d}}\bigl(cc_{u_d}^1\,\boldsymbol{y}_{u_d} + cc_{u_d}^2\,\boldsymbol{f}_{u_d}\bigr) ``` --- ### Subproblems Each building SP is identical to the single-building MILP from {doc}`building`, except that the OPEX term uses **internal energy prices** $\boldsymbol{\pi}_{l,p,t}$ (fixed dual variables from the latest MP solution) instead of exogenous tariffs: ```{math} :label: eq_sp_opex \boldsymbol{C}_b^{\text{OPEX}} = \sum_{l,p,t} \bigl(\boldsymbol{\pi}_{l,p,t}\,\dot{\boldsymbol{E}}_{b,l,p,t}^{\text{gr},+} - \boldsymbol{\pi}_{l,p,t}\,\dot{\boldsymbol{E}}_{b,l,p,t}^{\text{gr},-}\bigr)\,d_p\,d_t \qquad \forall\, b \in \mathbb{B} ``` The SP objective is: ```{math} :label: eq_sp_obj \min\; \boldsymbol{C}_b^{\text{OPEX}} + \boldsymbol{C}_b^{\text{CAPEX}} - \mu_b ``` A configuration has **negative reduced cost** (i.e., it improves the MP bound) when the SP objective value is negative. Such configurations are added to the global pool $\mathbb{F}$ and the MP is re-solved on the enlarged set. --- ### Dual variables Three dual variables emerge from the MP and steer the SP searches: | Variable | Constraint | Interpretation | |---|---|---| | $\boldsymbol{\pi}_{l,p,t}$ | District energy balance {eq}`eq_des_balance` | Internal energy price [CHF/kWh] or marginal GWP [kgCO₂eq/kWh] | | $\boldsymbol{\mu}_b$ | Convexity {eq}`eq_convexity` | Marginal value of integrating building $b$ into the district | | $\boldsymbol{\beta}$ | MOO $\epsilon$-constraint | Local gradient of the Pareto frontier | When the district objective is economic (TOTEX/OPEX), $\boldsymbol{\pi}$ gives **internal prices**; when environmental (GWP), it gives **marginal carbon impacts**. In multi-objective mode, $\boldsymbol{\beta}$ is passed to the SPs as an additional weight on the secondary objective, guiding the search toward configurations that are better on the Pareto frontier. --- ### Algorithm workflow ```{figure} ../../images/model/decomposition_algorithm.png :align: center :width: 85% :name: fig_dwd_algo Decomposition algorithm flowchart. ``` **Phase 1 — Initiation:** 1. Solve one compact optimization per building using exogenous energy prices (no district coupling). 2. Collect the resulting configurations as the initial pool $\mathbb{F}$. 3. Solve the first *relaxed* MP ($0 \le \boldsymbol{\lambda}_{f,b} \le 1$) to obtain initial dual variables $\boldsymbol{\pi}$, $\boldsymbol{\mu}$ (and $\boldsymbol{\beta}$ if MOO). **Phase 2 — Iteration:** 4. Pass $\boldsymbol{\pi}$, $\boldsymbol{\mu}$ to all SPs as fixed parameters. 5. Each building SP searches for its configuration with the lowest reduced cost. 6. If any SP finds a negative reduced-cost configuration, add it to $\mathbb{F}$. 7. Re-solve the relaxed MP on the enlarged pool; obtain new dual variables. 8. Repeat until no SP can find a negative reduced-cost configuration (or until a maximum iteration count is reached). **Phase 3 — Finalization:** 9. Solve a final integer MP with $\boldsymbol{\lambda}_{f,b} \in \{0,1\}$ to select one configuration per building. 10. Post-process to compute all district KPIs. :::{note} Typical convergence: the gap between the relaxed (lower-bound) and integer (upper-bound) MP objectives is below 0.01% within a few dozen iterations. ::: The SP solves are **independent across buildings** and can be parallelized across CPU cores, significantly reducing wall-clock time for large districts. --- ## Demand profile pooling Norm-based profiles (SIA 2024) are inherently synchronous across buildings, producing unrealistically large peaks when aggregated. Two independent stochastic perturbations are applied per building to introduce diversity while preserving annual energy demand. ### Amplitude factor Each building receives an amplitude scaling factor drawn from a normal distribution: ```{math} :label: eq_pool_amp a_b \sim \mathcal{N}(\mu_a, \sigma_a^2) \qquad\Rightarrow\qquad \tilde{e}_{b,p,t} = a_b\,\dot{e}^{0}_{b,p,t} ``` with $\mu_a \approx 1$ (preserving the norm average) and $\sigma_a \in [0.1, 0.2]$. ### Time-shift factor A random hourly lag (advance or delay) is applied: ```{math} :label: eq_pool_ts ts_b \sim \mathcal{N}(\mu_{\text{ts}}, \sigma_{\text{ts}}^2) \qquad\Rightarrow\qquad \dot{e}_{b,p,t} = \tilde{e}_{b,p,t}(1-|ts_b|) + \tilde{e}_{b,p,t\pm1}|ts_b| ``` with $\mu_{\text{ts}} = 0$ and $\sigma_{\text{ts}} \approx 1$–2 h. Linear interpolation between adjacent hours maintains hourly resolution. ### Aggregated effect The district-level demand is the sum over all buildings: ```{math} :label: eq_pool_agg \dot{e}^{\text{agg}}_{p,t} = \sum_{b \in \mathbb{B}} \dot{e}_{b,p,t} ``` The combined stochastic perturbation reduces aggregated peak power by ~40% and replaces sharp synchronized peaks with smoother, more realistic demand curves. The method applies to all norm-based profiles: electricity, DHW, occupancy, internal gains, ICT, and mobility. --- ## District-scale infrastructure District units follow the same black-box formulation as building units (see {doc}`building`, {ref}`Technologies `) but are sized and operated at utility scale. Available district technologies include large-scale boilers, geothermal heat pumps, batteries, hydrogen storage, data centers, PTES, rSOC, and methanators. ### District heating and cooling networks DHC networks allow buildings to exchange heat with centralized sources and sinks. #### Temperature levels | Architecture | Temperature range | Advantages | Drawbacks | |---|---|---|---| | High-temperature | > 65 °C | Direct DHW/radiator use, smaller pipes | Higher losses, insulation required | | Anergy / low-temperature | ~ambient | Minimal losses, compatible with heat pumps | Widespread temperature lifting needed | Two-phase CO₂ loops are also supported (high transfer coefficients, compact piping, isothermal operation). #### Deployment cost Service pipe diameter is sized from the maximum hourly heat duty: ```{math} :label: eq_dhn_diameter D_b \ge \left(\frac{4\,\dot{E}^{\text{gr},-}_{b,\text{heat},p,t}}{\pi\,v\,\rho\,\Delta h}\right)^{1/2} \qquad \forall\, b,p,t ``` Total network investment cost: ```{math} :label: eq_dhn_cost \boldsymbol{C}^{\text{inv}}_{\text{dhn}} = \sum_{b \in \mathbb{B}} L \bigl(c^{\text{dhn,1}}\,\boldsymbol{y}^{\text{dhn}}_b + c^{\text{dhn,2}}\,D_b\bigr) ``` where the inter-building pipe length is estimated by a geometric surrogate: ```{math} :label: eq_dhn_dist L = K \cdot \frac{N-1}{N} \cdot \left(\frac{A^{\text{district}}}{N}\right)^{1/2} ``` with shape factor $K$, number of buildings $N$, and total district footprint $A^{\text{district}}$. #### Heat exchanger (HEX) at the building interface Each connected building needs a heat exchanger sized to handle peak demand. Its capacity is bounded by the exchanger area $\boldsymbol{A}^{\text{hex}}_b$: ```{math} \dot{\boldsymbol{E}}^{\text{hex},-}_{b,\text{heat},p,t} \le \eta^{\text{in}}_b\,U_{\text{hex}}\,\boldsymbol{A}^{\text{hex}}_b\,T^{\text{in}}_{m,b} ``` ```{math} \dot{\boldsymbol{E}}^{\text{hex},+}_{b,\text{heat},p,t} \le \eta^{\text{out}}_b\,U_{\text{hex}}\,\boldsymbol{A}^{\text{hex}}_b\,T^{\text{out}}_{m,b} ``` Temperature feasibility coefficients $\eta^{\text{in}}_b$, $\eta^{\text{out}}_b$ (0 or 1) encode whether the DHC supply/return temperatures are compatible with the building's heat cascade. --- ### Local mobility services At district scale, all passenger transport (commuting, leisure, errands) is aggregated on a dedicated **Mobility energy layer**. Multiple modes are available: EVs, ICE vehicles, bicycles, e-bikes, and public transport. #### Demand and distance classes The daily mobility demand is segmented by distance class $d \in \mathbb{D}$ (e.g., short, medium, long trips): ```{math} :label: eq_mob_demand D^{\text{mob}}_{d,p,t} = \phi^{\text{dem}}_{\tau(p),d,t}\,D^{\text{day}}_d\,N^{\text{pop}} \qquad \forall\, d,p,t ``` where $\phi^{\text{dem}}_{\tau,d,t}$ is a normalized hourly profile (weekday/weekend), $D^{\text{day}}_d$ [km/person/day] the average daily distance for class $d$, and $N^{\text{pop}}$ the district population. #### Modal split The total demand for each distance class is covered by the set of available modes $\mathbb{U}^{\text{mob}}$: ```{math} :label: eq_mob_balance \sum_{u \in \mathbb{U}^{\text{mob}}} \boldsymbol{M}_{u,d,p,t} = D^{\text{mob}}_{d,p,t} \qquad \forall\, d,p,t ``` Mode shares are bounded per distance class: ```{math} :label: eq_mob_share \underline{s}_{u,d}\,D^{\text{mob}}_{d,p,t} \le \boldsymbol{M}_{u,d,p,t} \le \overline{s}_{u,d}\,D^{\text{mob}}_{d,p,t} \qquad \forall\, u,d,p,t ``` Each mode's energy consumption links its [pkm] service to the energy layers: ```{math} :label: eq_mob_energy \dot{\boldsymbol{E}}^{-}_{l,u,p,t} = \sum_{d} c^{\text{pkm}}_{u,l}\,\boldsymbol{M}_{u,d,p,t} \qquad \forall\, u,p,t ``` #### EV fleet model The EV battery energy is split between vehicles plugged in at the district ($\boldsymbol{E}^{\text{ev,on}}_{p,t}$) and those away ($\boldsymbol{E}^{\text{ev,off}}_{p,t}$): ```{math} :label: eq_ev_split \boldsymbol{E}^{\text{ev}}_{p,t} = \boldsymbol{E}^{\text{ev,on}}_{p,t} + \boldsymbol{E}^{\text{ev,off}}_{p,t} ``` The plugged-in energy evolves as: ```{math} :label: eq_ev_on \boldsymbol{E}^{\text{ev,on}}_{p,t} = \sigma_{\text{EV}}\,\boldsymbol{E}^{\text{ev}}_{p,t-1}\,\alpha_{p,t} - \boldsymbol{E}^{\text{ev,displ}}_{p,t} + \eta^-\,\boldsymbol{E}^{\text{ev,+}}_{p,t} - \frac{1}{\eta^+}\,\boldsymbol{E}^{\text{ev,-}}_{p,t} ``` where $\alpha_{p,t}$ is the plug-on fraction (vehicles available for charging), $\boldsymbol{E}^{\text{ev,displ}}_{p,t}$ is driving energy, and $\eta^{\pm}$ are charge/discharge efficiencies. SoC bounds are enforced separately for plugged-in and plugged-out vehicles, and cyclic constraints close the SoC over each typical period. **Unidirectional (smart charging):** $\boldsymbol{E}^{\text{ev,-}}_{p,t} = 0$ — no vehicle-to-grid. **Bidirectional (V2G/V2D):** $\boldsymbol{E}^{\text{ev,-}}_{p,t}$ is a decision variable, enabling EVs to inject electricity back into the district. #### Public transport and active modes Public transport appears as an external supply on the Mobility layer (import at associated cost and GWP). Conventional bicycles have zero energy consumption. E-bikes consume a small amount of electricity proportional to km ridden. --- ### Grid reinforcement Two types of reinforcement are modeled: the **network interface** (e.g., HV/MV transformer) and individual **building-to-grid lines**. #### Network interface The network capacity $\boldsymbol{f}^{\text{net}}_l$ is chosen from a discrete catalogue $\mathbb{G}^{\text{net}}_l$ of standard transformer ratings, respecting the existing capacity $f^{\text{ex,net}}_l$: ```{math} :label: eq_net_cap \boldsymbol{f}^{\text{net}}_l \ge f^{\text{ex,net}}_l, \quad \boldsymbol{f}^{\text{net}}_l \in \mathbb{G}^{\text{net}}_l, \quad \dot{\boldsymbol{E}}^{\text{net},\pm}_{l,p,t} \le \boldsymbol{f}^{\text{net}}_l ``` Investment cost includes a fixed activation term and a proportional capacity term: ```{math} :label: eq_net_cost \boldsymbol{C}^{\text{inv,net}}_l = c^{\text{net,1}}_l\,\boldsymbol{y}^{\text{net}}_l + c^{\text{net,2}}_l \bigl(\boldsymbol{f}^{\text{net}}_l - f^{\text{ex,net}}_l(1 - \boldsymbol{y}^{\text{net}}_l)\bigr) ``` #### Building-to-grid lines Each building-layer pair has its own line capacity, similarly selected from a discrete catalogue: ```{math} :label: eq_line_cap \boldsymbol{f}^{\text{gr}}_{b,l} \ge f^{\text{ex,gr}}_{b,l}, \quad \boldsymbol{f}^{\text{gr}}_{b,l} \in \mathbb{G}^{\text{gr}}_l, \quad \dot{\boldsymbol{E}}^{\text{gr},\pm}_{b,l,p,t} \le \boldsymbol{f}^{\text{gr}}_{b,l} \qquad \forall\, b,l,p,t ``` --- ## Renovation at district scale At district scale the master problem selects one configuration per building from the pool $\mathbb{F}_b$ that now includes renovation options (see {doc}`building`). Each configuration carries: - Effective envelope coefficient $U_{f,b}$ - Renovation cost $C^{\text{ren}}_{f,b}$ and embodied GWP $\mathrm{GWP}^{\text{ren}}_{f,b}$ - Operational performance from the SP Aggregate renovation cost and GWP are obtained by weighting: ```{math} :label: eq_ren_mp \boldsymbol{C}^{\text{ren}}_b = \sum_{f} C^{\text{ren}}_{f,b}\,\boldsymbol{\lambda}_{f,b} \qquad \boldsymbol{\mathrm{GWP}}^{\text{ren}}_b = \sum_{f} \mathrm{GWP}^{\text{ren}}_{f,b}\,\boldsymbol{\lambda}_{f,b} \qquad \forall\, b \in \mathbb{B} ``` A **minimum renovation share** constraint enforces that at least a fraction $\gamma^{\text{ren}}$ of total district floor area is renovated: ```{math} :label: eq_ren_share \gamma^{\text{ren}} \le \frac{\sum_b \boldsymbol{y}^{\text{ren}}_b\,A^{\text{era}}_b}{\sum_b A^{\text{era}}_b} ``` --- :::{seealso} **District-scale extension** The district model extends the {doc}`Building model ` core to communities of many buildings, and is itself further enriched by the {doc}`Actors model ` at the next scale. Refer to the {doc}`Package structure <../package_structure>` and {doc}`Getting started <../getting_started>` sections for practical usage. :::