Solving a Problem Modeled with Gurobi Formatting

68 views
Skip to first unread message

Taner Cokyasar

unread,
Jun 18, 2018, 8:41:33 PM6/18/18
to Pyomo Forum
Hello,

I am a newbie in Pyomo. I have been using Gurobi with Python 2.7 so far. I have the following model with the attached data file. I am looking for an easy way to solve the problem with GLPK solver. I have got GLPK installed on my laptop. I would like to learn if there is any way to convert the problem to Pyomo format and solve it with GLPK. If you may provide the code, I would really appreciate it.

Best,
Taner

###################################IMPORTING USEFUL PACKAGES###################################
from gurobipy import *
import xlwt
from __future__ import division
import math
import xlrd
import numpy as np
###############################################################################################

################################EXPORTING PARAMETERS FROM EXCEL################################
b = xlrd.open_workbook("./SmartManufacturingExperimentalData.xls") #Opening the excel file
sheet0 = b.sheet_by_index(0) #Reaching the sheet in excel
I = len(sheet0.col_values(1,2)) #Number of projects
S = sheet0.col_values(1,2)[:I] #Annual savings
CS = sheet0.col_values(2,2)[:I] #Annual investment cost
FS = sheet0.col_values(3,2)[:I] #Short Term Sampling Freq. in Hz
FA = sheet0.col_values(4,2)[:I] #Archival Samplig Freq. in Hz
FS = [i*60 for i in FS] #Converted Hz to CPM (cycle per minute)
FA = [i*60 for i in FA] #Converted Hz to CPM (cycle per minute)
CF = sheet0.cell_value(1,8) #Fixed Cost of a Server
CE = sheet0.cell_value(2,8) #IT Employment Cost
B = sheet0.cell_value(3,8) #Annual Budget
TS = sheet0.cell_value(4,8) * 24 * 60 #Process Control Time Interval: 10 days
TA = sheet0.cell_value(5,8) * 24 * 60 * 365 #Archival Time Interval: 10 years
R = sheet0.cell_value(6,8) / 1000000 #Size of a record: 16 bytes
DS = sheet0.cell_value(7,8) * 1000000 #Disk storage capacity of a server: up to 15 TB
DIO = sheet0.cell_value(8,8) * 60 #Disk input/output speed: up to 408 Mbps
P = sheet0.cell_value(9,8) #Number of IT personnel required per server
W = sheet0.cell_value(10,8) #Size of polling window: W=1
H = sheet0.cell_value(11,8) * 60 #Processing power of a server in GFLOPs; 2 processors x 1200 GFLOPs
K = 0.0098*W + 0.24 #billions of flop
###############################################################################################

#######################################CREATING THE MODEL######################################
m = Model("Smart Manufacturing")
###############################################################################################

########################################ADDING VARIABLES#######################################
x = {}
y = {}
z = {}
for i in range(I):
    x[i] = m.addVar(vtype=GRB.BINARY, name = "x%s" % str([i]))
m.addVar(vtype=GRB.CONTINUOUS, name = "y%s" % str([i]))
m.addVar(vtype=GRB.BINARY, name = "z%s" % str([i]))
###############################################################################################

###################################ADDING OBJECTIVE FUNCTION###################################
m.setObjective(quicksum((S[i] - CS[i])*x[i] for i in range(I)) - CF*y - CE*z, GRB.MAXIMIZE)
###############################################################################################

#######################################ADDING CONSTRAINTS######################################
m.addConstr(quicksum(CS[i]*x[i] for i in range(I)) + CF*y + CE*z <= B, name = "Cons1")
m.addConstr(quicksum((FS[i]*TS+FA[i]*TA)*x[i]*R for i in range(I)) <= DS*y, name = "Cons2")
m.addConstr(quicksum((FS[i]+FA[i])*x[i]*R for i in range(I)) <= DIO*y, name = "Cons3")
m.addConstr(quicksum((FS[i]+FA[i])*x[i]*K for i in range(I))/W <= H*y, name = "Cons3")
m.addConstr(y*P <= z, name = "Cons5")
###############################################################################################

m.update()
m.optimize()
m.printAttr("X")
SmartManufacturingExperimentalData.xls

Bynum, Michael Lee

unread,
Jun 18, 2018, 9:00:25 PM6/18/18
to pyomo...@googlegroups.com
I don’t believe Pyomo currently has the capability to convert a Gurobi model to a Pyomo model. However, you could probably just have Gurobi write an LP file and hand it to GLPK.

Michael

--
You received this message because you are subscribed to the Google Groups "Pyomo Forum" group.
To unsubscribe from this group and stop receiving emails from it, send an email to pyomo-forum...@googlegroups.com.
For more options, visit https://groups.google.com/d/optout.
<SmartManufacturingExperimentalData.xls>

Taner Cokyasar

unread,
Jun 18, 2018, 9:12:03 PM6/18/18
to Pyomo Forum
Thanks for your response Michael.  Assume that I have written m.write("example.lp") file after m.update(), what is next? Can you provide an example code to hand it to GLPK? I am a real newbie. I got no idea on how to code it up. It could be easy to code this simple problem in Pyomo though. Thanks!
Reply all
Reply to author
Forward
0 new messages