Groups keyboard shortcuts have been updated
Dismiss
See shortcuts

Minimize Power Loss, Electrical System

29 views
Skip to first unread message

luis gustavo cordero bautista

unread,
Feb 3, 2025, 11:39:06 PMFeb 3
to pyomo...@googlegroups.com
Hi dear community,

I am trying to minimize power loss of an electrical system with 33 buses (IEEE 33 buses). The model is based on current injection (real and imaginary parts), I declare the parameters and variables for the currents, voltages and power injection from the substation.

I am trying to fix the variable of line current (Ilinere and Ilineim) that means current from line i to j has to be equal to current from line j to i, but the set for Ilinere only accepts direction from i to j, and not j to i because the initial set. I am wondering how to fix this, I share the code lines below.

I would appreciate your help guys, thank you.

Best regards,
Luis
Pyomo_training_11.py

Ahmad Heidari

unread,
Mar 12, 2025, 10:56:50 AMMar 12
to Pyomo Forum
Hello Luis,

I hope you are doing well.

You have two options: 
1- You can define the lines based on the BUS sets
2- You can define the lines based on their unique sets.

For case 1, please refer to 
and go to chapter 4. Please search "model.CONEX".

For case 2, you can write as follows:

MP0.LINE = Set(initialize=[f'LN{i+1}' for i in range(32)], doc='Number of Transmission Lines')
file_path  = "your_file.xlsx"
sheet_name = "your_sheet_name"
df  = pd.read_excel(file_path, sheet_name=sheet_name)

line_data = {}
for _, row in df.iterrows():
    line_id     = row["LineID"]        
    from_bus    = row["From"]          
    to_bus      = row["To"]            
    x_val       = row["X"]            
    limit_val   = row["LIMIT"]        

    line_data[line_id] = {
        "from" : from_bus,
        "to"   :   to_bus,
        "X"    :    x_val,
        "LIMIT":limit_val
    }

MP0.from_bus = Param(MP0.LINE, initialize=lambda m, ln: line_data[ln]["from"], within=Any)
MP0.to_bus      = Param(MP0.LINE, initialize=lambda m, ln: line_data[ln]["to"],   within=Any)
MP0.X               = Param(MP0.LINE, initialize=lambda m, ln: line_data[ln]["X"],     doc="Reactance of each line")
MP0.LIMIT        = Param(MP0.LINE, initialize=lambda m, ln: line_data[ln]["LIMIT"], doc="Thermal limit of each line")

MP0.Pij   = Var(MP0.LINE, MP0.T, domain=Reals,  doc='Optimal Transmission DC Power Flow')

Finally, you can use the "fix" keyword to fix a variable:

for i in MP0.I:
    for t in MP0.T:
        MP0.Pij[i, t].fix(10)
Reply all
Reply to author
Forward
0 new messages