1
votes

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.

1
You should give more background info about your problem. What is your input data? What is the expected result? What have you tried so far? Please, check this stackoverflow.com/help/how-to-ask and especially this stackoverflow.com/help/minimal-reproducible-example and edit your question accordingly. - alec_djinn
PuLP is for linear models only, so I doubt this is the right tool. - Erwin Kalvelagen
The correct formulation of x=max(a,b) depends on the details. - Erwin Kalvelagen
@alec_djinn I have added more info. I don't know much about LP so I don't know if it enough - theMan

1 Answers

0
votes

Ok so I managed to solve it. Turns out I had to add two more constraints:

for i in range(12):
    self_consumption[i] <= grid_consumption[i]
    self_consumption[i] <= fv_i

Since it is a maximize type of problem, the value of each variable will be lower than the lowest value between the grid consumption and the solar power production.