'How to get the results for each 24 rows
My question is that:
My data consists of 768 rows to have values for 24 hours per day, with 32 days (24*32 = 768) . I am applying optimization using gurobi library. I want to get the values for a specific decision variable DA with the code:
DA = [x[t].X for t in T]
Now I am getting the results in an excel sheet for one column and 24 rows , which means for only the first day (24 hours). Can you please assist in getting the values for all of the 32 days, and each day has 24 values (we can present each day in one column in the results sheet). Below is the code I put.
from gurobipy import *
import gurobipy as gp
from gurobipy import GRB
import pandas as pd
import numpy as np
m = gp.Model()
df = pd.read_excel ('All Data.xlsx')
RT_array = df['Real-time price ($/MWh)'].to_numpy()
DA_array= df['Day-ahead price ($/MWh)'].to_numpy()
SP_array= df['Solar power generation (kWh)'].to_numpy()
t = 24
T = [i for i in range(1,t+1)]
S= SP_array
RT = RT_array
DP = DA_array
x = m.addVars(T,vtype=GRB.CONTINUOUS)
#y = m.addVars(A,vtype=GRB.CONTINUOUS)
y1 = m.addVars(T,vtype=GRB.CONTINUOUS)
m.setObjective(quicksum(DP[t]*x[t] for t in T if t < 24) + quicksum(RT[t]*y1[t] for t in T if t < 24) , GRB.MAXIMIZE)
const2 = m.addConstrs(S[t] == y1[t] + x[t] for t in T if t <24)
const4 = m.addConstrs(y1[t] <= S[t] for t in T if t <24)
const10 = m.addConstrs(x[t] >= 0 for t in T)
const11 = m.addConstrs(y1[t] >= 0 for t in T )
DA = [x[t].X for t in T]
writer2 = pd.ExcelWriter('DA.xlsx')
df_1 = pd.DataFrame(DA)
df_1.to_excel(writer2, sheet_name = 'DA', index = False)
writer2.save()
The data has three columns that are called:
Real-time price ($/MWh)
Day-ahead price ($/MWh)
Solar power generation (kWh)
Sources
This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.
Source: Stack Overflow
| Solution | Source |
|---|
