> ## Documentation Index
> Fetch the complete documentation index at: https://docs.plantpredict.com/llms.txt
> Use this file to discover all available pages before exploring further.

# Dispatch Algorithms

export const StateOfCharge = () => <Tooltip tip="Energy currently stored in the battery, bounded by zero (empty) and usable capacity (full).">
    state of charge
  </Tooltip>;

export const MV = () => <Tooltip tip="Medium Voltage: electrical infrastructure between inverter output and the plant collection point, including step-up transformers and AC cabling.">
    MV
  </Tooltip>;

export const LGIA = () => <Tooltip tip="Large Generator Interconnection Agreement: contract defining the maximum power export limit at the point of interconnection.">
    LGIA
  </Tooltip>;

## Summary

Dispatch Algorithms determine when the battery energy storage system should attempt to charge or discharge. PlantPredict implements three dispatch algorithms:

* **<LGIA /> Excess**: charges from clipped PV energy
* **Energy Available**: charges when PV energy is available
* **Custom Dispatch**: user-defined time series

The dispatch algorithm sets binary charge/discharge flags for each timestep, which control the battery <StateOfCharge /> calculation. These flags set the *intent* to charge or discharge; the [Charge & Discharge Limits](charge_discharge_limits) determine *how much* power is actually available for each operation.

## Inputs

| Name                            | Symbol         | Units   | Description                                                                                   |
| ------------------------------- | -------------- | ------- | --------------------------------------------------------------------------------------------- |
| **PV Power After Availability** | $P_{PV,avail}$ | W       | PV output after availability losses, before LGIA curtailment                                  |
| **Grid Limit (LGIA)**           | $P_{POI}$      | MW      | Maximum allowed power at point of interconnection                                             |
| **Available Charge Power**      | $P_{charge}$   | W       | Maximum charge power at battery DC (see [Charge & Discharge Limits](charge_discharge_limits)) |
| **Dispatch Table**              | $D_{m,h}$      | boolean | Discharge command for month $m$, hour $h$ (LGIA Excess / Energy Available)                    |
| **Custom Time Series**          | $C_t$          | —       | Per-timestep charge/discharge command (Custom Dispatch)                                       |

***

## Outputs

| Name               | Symbol | Units   | Description                                 |
| ------------------ | ------ | ------- | ------------------------------------------- |
| **Charge Flag**    | $F_c$  | boolean | True if battery should attempt to charge    |
| **Discharge Flag** | $F_d$  | boolean | True if battery should attempt to discharge |

***

## Detailed Description

The dispatch algorithms set charge and discharge *intent* flags ($F_c$, $F_d$) for each timestep. Both flags default to FALSE. These flags do not guarantee that charging or discharging will occur—feasibility depends on the available charge/discharge power (already computed by [Charge & Discharge Limits](charge_discharge_limits)) and whether the battery has remaining capacity to accept or deliver energy—is the battery fully charged or discharged?—evaluated in the [Battery Model](battery_model). $P_{POI}$ is converted from MW to W before use in equations.

### Discharging

#### LGIA Excess and Energy Available

For these algorithms, the target discharge period is determined from a monthly dispatch table ($D_{m,h}$). For each month of the year, the table specifies which hours of the day are designated as discharge periods. The discharge flag is set when the current timestep falls within a target period:

$$
\text{If } D_{m,h} = \text{TRUE} \implies F_d = \text{TRUE}
$$

#### Custom Dispatch

The discharge flag is set directly from the user-defined time series:

$$
\text{If } C_t = \text{Discharge} \implies F_d = \text{TRUE}
$$

### Charging

#### LGIA Excess

The charge flag is set when PV output after availability losses exceeds the LGIA limit, including during target discharge periods. The excess energy is diverted to charge the battery, subject to ESS inverter capacity and available battery capacity.

$$
\text{If } P_{PV,avail} > P_{POI} \implies F_c = \text{TRUE}
$$

#### Energy Available

The charge flag is set when there is available capacity to charge and the current timestep is not within a target discharge period. $P_{charge}$ is the maximum charge power available at the battery DC terminals, derived from the total PV output at the <MV /> bus through the ESS MV transformer and inverter losses and limits (see [Charge & Discharge Limits](charge_discharge_limits) for the full calculation).

$$
\text{If } P_{charge} > 0 \text{ and } D_{m,h} = \text{FALSE} \implies F_c = \text{TRUE}
$$

#### Custom Dispatch

The charge flag is set directly from the user-defined time series:

$$
\text{If } C_t = \text{Charge} \implies F_c = \text{TRUE}
$$

### Charge/Discharge Priority

When both charge and discharge flags are active in the same timestep—possible with the LGIA Excess algorithm during a target discharge period when PV exceeds the LGIA limit—charging takes priority.

***
