Iterative Solving using pyomo and IPOPT

784 views
Skip to first unread message

crazy...@gmail.com

unread,
Nov 22, 2017, 8:42:44 AM11/22/17
to Pyomo Forum
Hello. 

Im am new to Pyomo and IPOPT and looking for a little help. Already tried to post, but can not find the post back anymore. Hope I am not double posting this now.

Until now I did a few optimizations using MATLAB fmincon. It was pretty nice to use and gave good results.
It basically started an iteration feeding the design variables to the objective function. This objective function then rn through a really big script computing a lot of stuff before passing the values back to fmincon.
Fmincon then basically evaluated the new result and set the design variables into the doirection of the optimum and started a new iteration and so on.
Really nice as all the values where not any objects and the script was perfeclty iterable and readable.

Now I wanted to try the same with PYOMO and IPOPT. Starting a script with design variables, see how good the solution is and change the variables for the next iteration in which
these new variables will be feeded to the script. So far so good.
I now tried to start such an iterative run. Unfortunately the run was not iterative and the values fed to the onjective function where model objects which I can not use throughout the whole process.
Therefore I would like to know how to start an iterative process evaluating the design variables and using real values for the script in place of objects.
I hope this is somehow possible. Really would like to understnad PYOMO and IPOPT in order to become a valuable member. ;)
Thanks in advance.



"""Read in aurfoil and split coordinates in upper and lower coorfinates in order to be used later on."""
x, y = xfoil.readfile_profile(os.getcwd() + '\\data\\airfoils_selig\\withcomb135.dat')
x1, y1 = changetcratio(x, y)
xupper, yupper, xlower, ylower = splitairfoil(x1, y1)


"""start optimization"""
vector = [1 for i in range(int(ncst/2)*2)]
var = [1+i for i in range(int(ncst/2)*2)]
#lowerbound = [-1*vec for vec in vector]
#upperbound = [1 * vec for vec in vector]
#x0 = [0 * vec for vec in vector]

"""Define Solver"""
solver = 'ipopt'
solver_io = 'nl'
stream_solver = False # True prints solver output to screen
keepfiles = False # True prints intermediate file names (.nl,.sol,...)
opt = pyomo.opt.SolverFactory(solver, executable=os.getcwd() + '\\data\\ipopt\\bin\\ipopt.exe', solver_io=solver_io)

### Set Ipopt options to accept the scaling_factor suffix
opt.options['nlp_scaling_method'] = 'user-scaling'
###

### Create the example model
model = ConcreteModel()

# Decision Variables
model.cst = Var(var, within=NonNegativeReals)

# This statement is what Pyomo needs to generate one constraint for each plant
model.const1 = Constraint(expr = -1<= model.cst[1] <=1)
model.const2 = Constraint(expr=-1<= model.cst[2] <= 1)
model.const3 = Constraint(expr=-1<= model.cst[3] <= 1)
model.const4 = Constraint(expr=-1<= model.cst[4] <= 1)
model.const5 = Constraint(expr=-1<= model.cst[5] <= 1)
model.const6 = Constraint(expr=-1<= model.cst[6] <= 1)

model.const7 = Constraint(expr=-1<= model.cst[7] <=1)
model.const8 = Constraint(expr=-1<= model.cst[8] <=1)
model.const9 = Constraint(expr=-1<= model.cst[9] <=1)
model.const10 = Constraint(expr=-1<= model.cst[10] <=1)
model.const11 = Constraint(expr=-1<= model.cst[11] <=1)
model.const12 = Constraint(expr=-1<= model.cst[12] <=1)


def objectivefunc():
cstupper = []
cstlower = []
for i in range(ncst):
if i<int(ncst/2):
cstupper.append(model.cst[i+1])
else:
cstlower.append(model.cst[i+1])

output = RJ100_fmincon_airfoilprofile(cstupper, xupper, yupper, cstlower, xlower, ylower, resolution = 99)
return output

# Objective
model.obj = Objective(expr=objectivefunc(), sense=minimize)

### Send the model to ipopt and collect the solution
results = opt.solve(model, keepfiles=keepfiles, tee=stream_solver)
###

model.pprint()
model.solutions.store_to(results)
res = str(results.write())

output = []
for i in model.cst:
output.append(model.cst[i].value)
return output

Nesrine

unread,
Feb 1, 2018, 9:10:06 AM2/1/18
to Pyomo Forum
Hello, 

I am dealing with a similar modelling problem.
I was able to solve my model by implementing all variables as Pyomo components (although just a few of them have to be optimized). But I think it would be much cleaner, if solved itereratively.

I'm very interested to know, how it eventually worked out for you!

Thanks,
Nesrine 

Silvia Fracchia

unread,
Feb 19, 2018, 8:00:42 AM2/19/18
to Pyomo Forum
Hello,

I am also dealing with a very similar problem. Was there any progress on this?

@Nesrine, may I ask you more details about how you solved the model implementing all variables in Pyomo?

Thanks,
Silvia
Reply all
Reply to author
Forward
0 new messages