I have modeled the variables, objective, and constraints as follows:
wgen <- Variable(t) #wind power sold in the day-ahead market
wbal <- Variable(t) #wind power sold in the balancing market (up-regulation)
el <- Variable(t) #power used to perform electrolysis
inst <- Variable(t) #hydrogen that goes to the storage
fc <- Variable(t) #power generated using the fuel cell for the day-ahead market
fcbal <- Variable(t) #power generated using the fuel cell for the balancing market (up-regulation)
sth <- Variable(t) #hydrogen sold to industry from the storage
h <- Variable(t) #hydrogen sold immediately after electrolysis
st <- Variable(t+1) #the storage level
wdown <- Variable(t) #negative amount of wind power sold in the balancing market (down-regulation)
fcdown <- Variable(t) #negative amount of fuel cell power sold in the balancing market (down-regulation)
#objective
objective <- Maximize(sum((wgen+fc)*p[1:(t)]+(wbal+fcbal)*pbal_up+(wdown+fcdown)*pbal_down+(h+sth)*h2p))
#contraints
constraints <- list(st[1]==0, wgen>=0, wbal>=0, wdown <= 0, el>=0, fc>=0, fcdown <=0, fcbal>=0,
h>=0, st>=0, inst>=0, sth>=0,
wgen + wbal + wdown+ el <= wind[1:(t)],
0 <= wbal + fcbal, wbal + fcbal <= max_up,
wdown + fcdown >= max_down, wdown + fcdown <= max_up,
abs(wdown) <= solution_a$getValue(wgen), abs(fcdown) <= solution_a$getValue(fc), #problematic constraint
h + sth <= heat[1:(t)],
el*eel==inst+h,
inst <= sendin,
el<= elmax, fc+fcbal+fcdown<= fcmax,
(fc+fcbal+fcdown)/efc+sth<= st[1:t],
(fc+fcbal+fcdown)/efc+sth<= sendout,
st[1:t+1] <= maxst,
diff(st)==inst-(fc+fcbal+fcdown)/efc-sth #diff is the increase from the last hour
)
CvX fits the requirements of my model, except for this one issue.
In the code above I have used output from a version of the model that only includes the first scheduling moment to constrain the desired variables, in the line with “problematic constraint”.
The result is not yet quite satisfactory, since it might still be that during the first moment extra power is sold, because it can be sold as down-regulation of power (negative supply of power because there is too much electricity supply compared to demand and this needs to balance) during the second scheduling moment. The two scheduling moments represents different submarkets in the electricity market. It might indeed be a good idea to separate them in two stages, but I don’t know if or how this can be done.
As I am already pretty invested in the use of CvXR, I am trying to figure out a way to solve my problem within CvXR. Perhaps this is too much to ask, but if you could see if, or even better, how CvXR can facilitate what I need this would be a great help.