How to write optimized solution to excel?

82 views
Skip to first unread message

Annelies De Meyer

unread,
Jul 18, 2017, 8:30:35 AM7/18/17
to Gurobi Optimization
Hi,

I'm using pandas to read the input data to be used in the optimisation model I've developed.

Now, I also want to use pandas to write the solution (mainly the values of the decision variables) to excel.

How should I do this? I don't find any examples. Is this even possible?

Thank you in advance,

Annelies

Taner Cokyasar

unread,
Jul 18, 2017, 10:35:45 AM7/18/17
to Gurobi Optimization
Hi Annelies,

Yes, it is possible. You can see the following example, I haven't used pandas though.



# Preparing x and y variables to writing format
var_x = []
var_y = []

for var in m.getVars():
    if 'x' == str(var.VarName[0]) and var.X > 0.1:
        var_x.append(var.VarName)
    if 'y' == str(var.VarName[0]) and var.X > 0.1:
        var_y.append(var.VarName)

# Write results to csv
with open('WHAT EVER YOU WANT.csv', 'wb') as myfile:
    wr = csv.writer(myfile, quoting=csv.QUOTE_ALL)
    wr.writerows(zip(var_x, var_y))

Annelies De Meyer

unread,
Aug 8, 2017, 7:31:12 AM8/8/17
to Gurobi Optimization
It works! Thank you!

Op dinsdag 18 juli 2017 16:35:45 UTC+2 schreef Taner Cokyasar:
Reply all
Reply to author
Forward
0 new messages