I'm trying to solve a problem of minimizing energy costs for the next time period. I have a vector of energy bought from the grid, and the idea is to find moments with cheaper energy prices and store energy for the future. The grid has a physical peak power constraint and the "recommended" peak. If the power exceeds that recommended level, there is a fine for the peak, but the fine is paid only once. After that moment, it is allowed to achieve a new maximum value for free. The objective function includes all costs for energy from the grid plus the fine multiplied by (grid_max - limit).
Here is a code snippet of how I tried to achieve that:
model.grid_buy = Var(model.time_step, bounds=(0, max_value), initialize=0)
model.exceeded_peaks = Var(model.time_step)
model.fined_peak = Var()
PW_PTS = {}
for i in model.time_step:
PW_PTS[i] = [0, limit, max_value]
def f(model, i, x):
return 0 if x <= limit else x - limit
model.constraints = Piecewise(model.time_step, model.exceeded_peaks, model.grid_buy,
pw_pts=PW_PTS, pw_constr_type='EQ', pw_repn='DCC',
f_rule=f)
def peak_definition(model, i):
return model.fined_peak >= model.exceeded_peak[i]
model.peak_definition = Constraint(model.time_step, rule=peak_definition)
model.obj_1 = Objective(expr=model.grid_buy * prices, sense=minimize)
model.obj_2 = Objective(expr=model.grid_buy * prices + model.fined_peak * fine, sense=minimize)
obj_1 - objective function that considers only costs
obj_2 considers fine for peak power
The result of the optimization with the objective function 2 is worse if I consider the objective function 1 + max_value which is set to the recommended limit. In this solution the part grid_buy * prices is a little bit more expencive but because there is no fine in total it is much more cheaper.
It seems to me that in the optimization with obj_2, the fine is being considered incorrectly, but I'm unsure why. I'm using the solver 'scip'.
Do you have any ideas or suggestions? Thank you for any help.