I am trying to output the solution of one of the array variables into an excel workbook. I am not able to get anything other than the representation of the variables within PULP as opposed to the solved value (which is what I am after).
I have tried a number of different pandas/numpy data frames and arrays but no success. Tried using the excel writer library as well but no dice.
YPER = 30
HE = 24
yearlyhours = []
yearlyhours = [(i,j) for i in range(YPER) for j in range(HE)]
MAHLDIFF = pulp.LpVariable.dicts("MAHLDIFF", (range(YPER), range(HE)), lowBound=0, cat='Continuous')
MAHLDIFFOUTPUT = []
for i,j in yearlyhours:
var_output = {'MAHLDIFF':MAHLDIFF[i][j]}
MAHLDIFFOUTPUT.append(var_output)
dfOptResults = pd.DataFrame.from_records(MAHLDIFFOUTPUT)
dfOptResults.to_excel('file.xls')
This is the output I get so far, just a sample of full array:
MAHLDIFF
0 MAHLDIFF_0_0
This is not really about exporting to Excel, it's just a general question about how to access the values of the variables in PuLP. To do so, use <var_name>.value()
, eg, MAHLDIFF[i][j].value()
.
You can also loop through all variables in the model using, eg:
for v in prob.variables():
print(v.name, "=", v.varValue)
where prob
is the Python variable that holds your PuLP model.
Have you thought about https://solverstudio.org/ . If you want to use Excel to manage your data.
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.