Capacity optimization
----------------
### Introduction
In addition to the simulation of operations at hourly resolution, Artelys Crystal Super Grid offers the ability to
**jointly perform the optimization of investments**.
The costs considered include annualized investment costs and fixed operating costs. The model **minimizes total system
costs**, combining **investment and operational expenses**, to determine the optimal set of investments and the
operation of each component within the energy system.
### OPTIM_CAPA context type
To perform a capacity optimization, the context type in the CONTEXT.csv must be set to **OPTIM_CAPA** (instead of
SIMULATION, for instance).

### OPTIM_PMAX behavior
To optimize the capacity of a given asset, use the behavior **OPTIM_PMAX**. Instead of specifying a fixed capacity with
the $PMAX$ attribute, define the minimum ($PMAXMIN$ attribute) and maximum ($PMAXMAX$ attribute) capacities to be
installed. The capacity $PMAX$ of the asset will be optimized such that $PMAXMIN \leq PMAX \leq PMAXMAX$, taking into
account investment costs (annualized $CAPEX$, in €/MW/year) and Fixed Operational Costs ($FOC$, in €/MW/year). Thus, the
cost of installing new capacities for this asset is given by $installedCapacities * (CAPEX + FOC)$.

For more details on the OPTIM_PMAX behavior, please refer to the [Behaviors documentation](../behaviors/index.rst).
### OPTIM_CAPA - SIMULATION sequence
An option allows for directly restarting a simulation at fixed $PMAX$, following the capacity optimization.
The optimal values obtained during the first optimization are retrieved and injected into the context as attributes of
the optimized assets. This enables setting two different Loss of Load values: one for capacity optimization and another
for simulation. This option is highly recommended as it ensures that the marginal costs reflect the short-term marginal
costs at the end of the simulation stage, and not the long-term marginal costs (slightly higher, taking into account
system investments) used during capacity optimization.
#### Setting the option
This sequence is available for contexts of type OPTIM_CAPA and PATHWAY_OPTIM. For these contexts, the Boolean parameter
SIMU_AFTER_OPTIM_CAPA is used to activate or deactivate the option. This parameter can be edited in the CONTEXT.csv file
or via the Map view, by clicking on the context name:


For Loss of Load assets, the PRICE_SIMU_AFTER_OPTIM_CAPA attribute allows for a second LoL price value per asset, which
will be used specifically for the fixed capacity simulation. This attribute is only activated for contexts of type
OPTIM_CAPA or PATHWAY_OPTIM when the SIMU_AFTER_OPTIM_CAPA parameter is set to True. If PRICE_SIMU_AFTER_OPTIM_CAPA is
not specified in LOSS_OF_LOAD.csv, a default value of 3000 €/MWh is applied.

#### Consequences on results
Running a fixed-capacity simulation after the initial optimization is invisible for the user, with results remaining
almost identical. The main difference appears in the Marginal Costs indicator: with the SIMU_AFTER_OPTIM_CAPA
option, energy prices become consistent and directly interpretable in both trajectory and classic capacity optimization,
similar to a simple simulation. Additionally, the Loss of Load cost indicator is impacted, as it now incorporates
the value of PRICE_SIMU_AFTER_OPTIM_CAPA in its calculation.