I have been tasked with transforming a GRG nonlinear problem used in Solver to python. Since I have no experience with NLP, I'm trying to convert it to a LP problem.
We have twelve variables that represent the solar power generated monthly for a year and twelve constants that represent the monthly grid consumption. The objective is to maximize the sum of the twelve variables. In PuLP, we represent these variables the following way:
problem = LpProblem("Test_Problem", LpMaximize)
grid_consumption = [190, 409, 273, 424, 351, 412, 360, 509, 280, 241, 263, 175]
total_grid_consumption = sum(consumo_odf)
fv_productions = LpVariable.dicts('fv', list(range(12)))
There are five constraint, some depend explicitly of the variables and some depend implicitly.
For example, one of the constraints says that the production of solar power can't be greater than grid consumption, which is a constant. In PuLP, we represent this constraint this way:
for i in range(12):
fv_i - grid_consumption[i] <= 0
One of the constraints that is giving us a headache is one that says 1/3 of the self-consumption must be greater than the compensated energy. Monthly self consumption is equal to the grid consumption if the latter is lower than the solar production (fv_i), and will be equal to solar production if not:
for i in range(12):
if(fv_i>grid_consumption[i]):
self_consumption[i] = grid_consumption[i]
else:
self_consumption[i] = fv_i
Excel Solver has no problem with this constraint but we have no idea how can we translate it to a PuLP constraint. Any help would be welcomed. This is my first question, so if I can provide some more info please let me know. Thanks.
x=max(a,b)depends on the details. - Erwin Kalvelagen