# Mixed Integer Optimization

Binary variables increase the amount of time it takes to solve an optimization problem, but prevent concurrent charging and discharging in storage systems and allow for minimum power levels for all DERS. They can be turned on or off using the binary model parameter.

Energy storage systems add two continuous variables to every time step - charge power and discharge power (ch and dis). They need to be separate because charging power changes the state of energy (SOE) of the storage system by power * roundtrip efficiency * dt whereas discharging power changes the SOE by -power * dt. Unless the roundtrip efficiency is 100%, these two variables will interact with the rest of the model differently, so need to be separate.

Generators add a single continuous variable - the generating power (gen), equivalent to a storage system's discharge power. Many generators and some storage systems cannot generate or charge/discharge at low power. In this case the gen or ch/dis variables must be either 0 or between the system's minimum and maximum power.

## Concurrent Charge and Discharge

When the optimization problem is solved, the ch and dis variables are added together to get the total storage power. Most storage systems (e.g. Li-ion batteries) are not physically capable of charging and discharging at the same time, but this model indicates they could. Concurrent charge and discharge is a problem because the energy lost by the roundtrip efficiency term is exaggerated and because the charging and discharging levels independently constrain participation in ancillary services, allowing for a more profitable mix of ancillary services that is physically possible.

Two binary variables (0 or 1) at every time step are included to determine if the storage system is "charging" or "discharging" at that time step and constrain ch to be 0 when the system is discharging and vice versa. (ch <= max_charge_power * on_c where on_c is the binary variable indicating the system is charging)

## Minimum Power

The discontinuity in the allowed power values when minimum power is not 0 indicates a binary variable at every time step to decide whether a generator is "on" or "off" and two binary variables to decide whether a storage system is "charging", "off", or "discharging".

# Best Practices

Best practice is to leave binary variables on unless performing size optimization. Size optimization converts the maximum charge/discharge/generation parameters into optimization variables. In the constraint above (ch <= max_charge_power * on_c), the maximum charge power is multiplied by the binary variable on_c. This multiplication of optimization variables represents a nonlinear constraint and breaks the mixed integer linear programming framework of DER-VET, so is not allowed.

If optimal sizing is required for technologies with a minimum generating power, for example, an optimal size without binary variables can be calculated, followed by a second dispatch-only optimization using the size result from the first optimization.

In many cases where there are no minimum power levels on any technology, leaving the binary variables off will not cause a problem. There is a problem when energy prices are below 0 and when ancillary services are included.