Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How can I set a value of an indexed variable? - Pyomo

I'm working on a project related with AC OPF (Optimal Power Flow) and I was trying to solve a problem in python, using pyomo. There are 3 buses and the bus voltage and bus angle are limited. However, the 1st bus must have a voltage=1 and an angle=0.

So, I tried this:

model.busvoltage = Var(model.bus, initialize=1, bounds=(0.95, 1.05), doc='Bus Voltage')
model.busvoltage[1].fixed=True
model.busangle = Var(model.bus, initialize=0, bounds=(-3.14, 3.14), doc='Bus angle')
model.busangle[1].fixed=True

The problem is that I just want to set the busvoltage and busangle for the first bus, without initializing the other ones with those values. I don't know if this is important to write, but I'm using ipopt as solver.

(This is my first time programming in Python) Any help would be appreciated!

like image 893
cata oliveira Avatar asked Oct 19 '25 20:10

cata oliveira


1 Answers

You're after the .value attribute of the variable. Furthermore, setting the value of a variable and fixing it at the same time can be simplified to calling .fix():

model.busvoltage = Var(model.bus, bounds=(0.95, 1.05), doc='Bus Voltage')
model.busvoltage[1].fixed = True
model.busvoltage[1].value = 1

model.busangle = Var(model.bus, bounds=(-3.14, 3.14), doc='Bus angle')
model.busangle[1].fix(0)
like image 189
ruaridhw Avatar answered Oct 22 '25 12:10

ruaridhw