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.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()Complete network reduction analysis workflow including:
- Data loading and preprocessing
- Original network PTDF/TTC analysis
- Representative node selection
- Kron reduction
- Reduced network analysis
- Optimization of equivalent capacities
- Results comparison and export
Returns
Tuple containing:
- ttc_results: Original network TTC calculations
- ptdfreducedresults: Reduced network PTDF calculations
- equivalentcapacitiesdf: Optimized equivalent capacities
Data Directory
Modify the inputdatadir and outputdatadir variables to change the location.
Output Files
- BusIDMap_QP.csv: Mapping of bus names to numerical IDs
- LineDetailsQP.csv: Comprehensive line information
- RepresentativeNodesQP.csv: Selected representative nodes
- TTCOriginalNetwork_QP.csv: Original network TTC values
- PTDFReducedNetwork_QP.csv: Reduced network PTDF values
- EquivalentCapacitiesQP.csv: Optimized synthetic line capacities
- TTCComparisonQP.csv: Comparison of original vs equivalent TTC values
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 to uppercase, create numerical mapping, and convert data to per-unit. Returns processed line DataFrames and node information.
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, node_info)Select a single representative node (RN) from each unique 'Zone' based on the highest interconnection degree.
Arguments
Ybus::SparseMatrixCSC{ComplexF64}: Network admittance matrixnode_info::DataFrame: Node information DataFrame
Returns
rep_nodes::DataFrame: DataFrame with selected representative nodesnode_info::DataFrame: Updated nodeinfo with isrepresentative flag set
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.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(nodes_df, zone)Identifies boundary or representative nodes within each zone based on interconnection degree and network topology.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.CONFIGGlobal configuration object containing parameters such asoptimization_type,lambda,ptdf_epsilon, base power, and unit settings.reset_config!()Resets all configuration parameters to their default values.
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 |
kron-reduction.jl | Mathematical node elimination |
main-analysis.jl | The top-level wrapper executing the full pipeline |
optimization.jl | JuMP models for LP, QP, and MILP formulations [cite: 11] |
ptdf-calculations.jl | DC power flow sensitivity analysis |
representative-nodes.jl | Groups buses and identifies the "boundary" nodes to keep based on their connectivity degree |
ttc-calculations.jl | Transfer capacity evaluation [cite: 10] |
ybus-formation.jl | Physical matrix assembly ($Y_{bus}$) |