API Reference
ElectricityNetworkReduction._solve_miqp_model — Method
Linearized MILP formulation using Ipopt that enforces exactly one binding line per transaction. Objective: minimize sum of absolute TTC errors (L1 norm).
ElectricityNetworkReduction.calculate_all_ttc_results — Method
calculate_all_ttc_results(Ybus, lines_df, tie_lines_df)Computes TTC for all canonical transactions (a < b) WITHOUT storing PTDFs. Memory-optimized for large-scale systems.
ElectricityNetworkReduction.calculate_single_injection_ptdfs — Method
calculate_single_injection_ptdfs(Ybus; reference_bus=1)Core Engine: Factorizes B matrix once and solves for unit injections.
ElectricityNetworkReduction.calculate_ttc_from_ptdfs — Method
calculate_ttc_from_ptdfs(ptdf_df, line_capacities)Calculate the Total Transfer Capacity (TTC) for every canonical transaction (A < B). Returns DataFrame with TTC values and limiting line information.
ElectricityNetworkReduction.clean_line_data — Method
clean_line_data(lines_df::DataFrame)Clean line data by removing self-loops and assigning fake EIC codes to missing entries.
ElectricityNetworkReduction.convert_line_to_pu! — Method
convert_line_to_pu!(lines_df::DataFrame, Sbase::Float64; in_pu::Bool=false)Convert line parameters to per-unit values based on system base power. If in_pu is true, assumes R, X, B are already in per-unit and only converts capacity.
ElectricityNetworkReduction.create_ttc_results_from_optimization — Method
create_ttc_results_from_optimization(
ttc_vals::Vector{Float64},
ttc_canonical::DataFrame;
model=model,
Type = CONFIG.optimization_type,
synth_lines::Vector{Tuple{Int,Int}} = Tuple{Int,Int}[],
binding_dict::Union{Dict,Nothing} = nothing
)Create TTC results directly from optimization variables.
ElectricityNetworkReduction.detect_islands — Method
detect_islands(lines_df::DataFrame, tielines_df::DataFrame, node_info::DataFrame)ElectricityNetworkReduction.export_bus_id_map — Method
export_bus_id_map(node_info, export_path)Export a CSV file containing the mapping between old bus names and new numerical IDs.
Arguments
node_info::DataFrame: Node information with oldname and newid columnsexport_path::String: Path where the CSV file will be saved
Output CSV Format
- old_name: Original bus names from input data
- new_id: Numerical IDs assigned during processing
ElectricityNetworkReduction.export_detailed_line_info — Method
export_detailed_line_info(lines_df, tielines_df, export_path)Export comprehensive line information including both original names and numerical IDs.
Arguments
lines_df::DataFrame: Regular transmission lines datatielines_df::DataFrame: Tie lines dataexport_path::String: Path where the CSV file will be saved
Output CSV Columns
- EIC_Code: European Identification Code for the line
- Fromnode, Tonode: Original bus names
- NewIDFrom, NewIDTo: Numerical bus IDs
- Voltage_level: Operating voltage level
- Length_km: Line length in kilometers
- CapacityMW, Capacitypu: Line capacity in MW and per-unit
- Rpu, Xpu, B_pu: Line parameters in per-unit
- IsTieLine: Boolean flag indicating if this is a tie line
ElectricityNetworkReduction.form_ybus_with_shunt — Method
form_ybus_with_shunt(lines_df, tie_lines_df, node_info, Sbase)Form the network admittance matrix (Y-bus) including shunt elements. Returns a sparse complex matrix representing the network admittance.
ElectricityNetworkReduction.kron_reduce_ybus — Method
kron_reduce_ybus(Ybus, rep_node_ids)Perform Kron reduction on the original Ybus matrix to eliminate non-representative nodes.
The Kron reduction technique eliminates internal nodes while preserving the electrical relationships between the representative nodes. This creates an equivalent network with fewer nodes but equivalent transfer characteristics.
Arguments
Ybus::SparseMatrixCSC{ComplexF64}: Original network admittance matrixrep_node_ids::Vector{Int}: Indices of representative nodes to retain
Returns
Y_kron::SparseMatrixCSC{ComplexF64}: Reduced admittance matrix
Mathematical Background
The Kron reduction partitions the admittance matrix as:
Y = [K L_T]
[L M ]where K connects representative nodes, M connects eliminated nodes, and L connects representative to eliminated nodes.
The reduced matrix is: Ykron = K - LT * M^(-1) * L
ElectricityNetworkReduction.load_excel_data — Method
load_excel_data(file_path::String)Load network data from Excel file with multiple sheets. Returns a dictionary containing DataFrames for lines, tielines, nodes, and generators.
ElectricityNetworkReduction.main_full_analysis — Method
main_full_analysis(input_data_dir, output_data_dir)Complete network reduction analysis workflow including:
- Data loading and preprocessing
- Island detection (optional, when
CONFIG.enable_plots = true) - Original network Y-bus and TTC/PTDF analysis
- Representative node selection
- Kron reduction
- Virtual line filtering (when
CONFIG.allow_virtual_lines = false) - Reduced network PTDF analysis
- Optimization of equivalent capacities
- Results comparison and export
Returns
Nothing. All results are written to CSV files in output_data_dir.
Output Files
All filenames use CONFIG.suffix as a postfix:
Bus_ID_Map_<suffix>.csv: Mapping of original bus names to sequential integer IDsLine_Details_<suffix>.csv: Comprehensive line informationRepresentative_Nodes_<suffix>.csv: Selected representative nodes per zoneTTC_Original_Network_<suffix>.csv: Original network TTC valuesPTDF_Reduced_Network_<suffix>.csv: Reduced network PTDF valuesEquivalent_Capacities_<suffix>.csv: Optimized synthetic line capacities and reactancesTTC_Comparison_<suffix>.csv: Comparison of original vs equivalent TTC valuesNetwork_Original_<suffix>.png: Original network plot (only whenenable_plots = true)Network_Reduced_<suffix>.png: Reduced network plot (only whenenable_plots = true)Network_Original_vs_Reduced_<suffix>.png: Side-by-side comparison plot (only whenenable_plots = true)
ElectricityNetworkReduction.plot_network — Method
plot_network(g, node_info, lines_df; title, n_size, f_size, show_names)Plot a network graph with nodes coloured by island (connected component). Only called when CONFIG.enable_plots = true. Uses Latitude/Longitude columns for geo-layout if present in node_info, otherwise uses a spring layout.
ElectricityNetworkReduction.plot_original_vs_reduced — Method
plot_original_vs_reduced(g_orig, nodes_orig, lines_orig, g_red, nodes_red, lines_red, output_path)Plot original and reduced networks side-by-side (1400×700 px) and save to output_path. Only called when CONFIG.enable_plots = true.
ElectricityNetworkReduction.process_tielines — Method
process_tielines(tielines_df::DataFrame)Process tie-lines by sorting, removing duplicates, and handling missing EIC codes.
ElectricityNetworkReduction.rename_buses — Function
rename_buses(nodes_df, generators_df, lines_df, tie_lines_df, Sbase)Rename buses, create numerical mapping, convert to per-unit, and preserve the IsRepresentative column from Excel.
ElectricityNetworkReduction.reset_config! — Method
reset_config!()Resets the global CONFIG object to its default values. Useful for batch testing multiple case studies.
ElectricityNetworkReduction.select_representative_nodes — Method
select_representative_nodes(Ybus::SparseMatrixCSC{ComplexF64}, node_info::DataFrame)Select representative nodes using one of two modes controlled by CONFIG.repnodemode:
- "auto" (default): Select top
CONFIG.rep_node_k_per_zonehighest-degree nodes per zone - "manual_excel": Use nodes marked in column
IsRepresentativein the Nodes sheet
If manual mode is selected but the column is missing, falls back to auto mode with a warning. Always ensures :isrepresentative column exists in nodeinfo.
ElectricityNetworkReduction.Config — Type
ConfigCentral configuration struct for the entire network reduction workflow. Modify the default values below to run different case studies.
Exported Functions
This section provides an overview of the main exported functions in ElectricityNetworkReduction.jl, grouped by their role in the overall workflow. These functions are designed to support data ingestion, physical modeling, network reduction, optimization, and result export.
1. Data Loading and Cleaning
These functions handle the initial stage of reading input data from Excel or CSV files and preparing it for mathematical modeling.
load_excel_data(file_path)Reads the mandatoryLines,Tielines,Nodes, andGeneratorssheets from an Excel input file and returns structured data frames.clean_line_data(lines_df)Cleans branch data by removing self-loops and assigning unique identifiers to missing or incomplete EIC codes.process_tielines(tielines_df)Processes inter-zonal transmission lines to ensure consistent representation of connections across zone boundaries.rename_buses(nodes_df, lines_df, tielines_df)Assigns sequential integer IDs to all buses and returns updated data frames alongside a mapping from original to new IDs. Used internally to normalise bus identifiers before matrix construction.convert_line_to_pu!(df, baseMVA)Converts line parameters from physical units (Ohms) to per-unit values using Voltage (kV) and Current (A), if required. This function modifies the data frame in place.
2. Network Physics and Matrix Construction
These functions construct the mathematical representation of the electrical network.
form_ybus_with_shunt(nodes, lines)Assembles the bus admittance matrix ($Y_{bus}$), including the contribution of line shunt susceptances.calculate_ptdfs_dc_power_flow(ybus)Computes Power Transfer Distribution Factors (PTDFs) using DC power flow assumptions.calculate_ttc_from_ptdfs(ptdfs, capacities)Calculates the original Total Transfer Capacities (TTCs) for a set of transactions based on PTDFs and line limits.
3. Network Reduction Logic
These functions implement the core algorithms used to reduce the size of the network while preserving its physical behavior.
select_representative_nodes(ybus, node_info, numbered_lines, numbered_tielines)Identifies representative nodes within each zone. Supports two modes controlled byCONFIG.rep_node_mode:"auto": selects the topCONFIG.rep_node_k_per_zonenodes per zone ranked by interconnection degree (line capacity as tiebreaker)."manual_excel": reads theIsRepresentativecolumn from theNodessheet.
kron_reduce_ybus(ybus, representative_nodes)Applies Kron reduction to eliminate internal nodes while preserving sensitivity relationships between representative nodes.
4. Capacity Optimization
These functions use mathematical programming to determine synthetic line capacities for the reduced network.
optimize_equivalent_capacities(ttc_orig, ptdf_red)Primary interface for solving the capacity fitting problem using LP, QP, or MIQP formulations.
5. Workflow and Configuration
These functions and objects control the full end-to-end execution of the model.
main_full_analysis(input_dir, output_dir)High-level wrapper that executes the complete network reduction pipeline, from data loading to result export. Returnsnothing; all results are written to CSV files inoutput_dir.CONFIGGlobal configuration object. Key parameters:optimization_type,lambda,ptdf_epsilon,base,bus_names_as_int,in_pu,allow_virtual_lines,rep_node_mode,rep_node_k_per_zone,enable_plots. See the Model Usage guide for details.reset_config!()Resets all configuration parameters to their default values. Always call this between case studies in batch runs.
6. Visualisation (optional)
Network plots are generated when CONFIG.enable_plots = true. The plotting functions use Plots and GraphRecipes, which are regular dependencies installed with the package.
plot_network(g, node_info, lines_df; title, n_size, f_size, show_names)Plots a single network. Nodes are coloured by connected component (island). UsesLatitude/Longitudecolumns for geo-layout if present in theNodessheet, otherwise uses a spring layout.plot_original_vs_reduced(g_orig, nodes_orig, lines_orig, g_red, nodes_red, lines_red, output_path)Produces a side-by-side 1400×700 px comparison plot of the original and reduced networks, saved tooutput_path.
Internal Module Structure
The package follows a modular architecture, with each file responsible for a specific component of the workflow.
| File | Responsibility |
|---|---|
config.jl | Centralized settings and global constants |
data-loading.jl | Excel/CSV ingestion and per-unit normalization |
export-functions.jl | CSV export and reporting utilities |
island-detection.jl | Connected-component detection (used when enable_plots = true) |
kron-reduction.jl | Mathematical node elimination |
main-analysis.jl | The top-level wrapper executing the full pipeline |
network-visualisation.jl | Network plot functions (only called when enable_plots = true) |
optimization.jl | JuMP models for LP, QP, and MILP formulations |
ptdf-calculations.jl | DC power flow sensitivity analysis |
representative-nodes.jl | Groups buses and identifies boundary nodes per zone |
ttc-calculations.jl | Transfer capacity evaluation |
ybus-formation.jl | Physical matrix assembly ($Y_{bus}$) |