Assume that a company that buys oil, refine it and sell it per month, wants to maximize their profits, by finding how much they consume, buy, produce and store (variables)

my model has constraints, parameters, equations, everything is on point (or so i think) so the question is, can my optimal solution (profits) be negative?

code attached

ModeloOpti.gms (3.15 KB)

In a complete mathematical sense, can a maximum of a variable be negative? Yes. Does it matter if the variable is named profit? No.

In a practical sense, just because you try to maximize profit does not guarantee making profit (may be you are trying to minimize losses and profit is just not possible).

I don’t know how to fix this but all I can say is let’s say you reduce the buying price by a factor of 100 (costo and costoalmacenado), you will get a positive profit. So the negative terms in your objective dominate the positive terms. Assuming this should not happen, this can either be because of parameters or because your variables compra and almacenar are not getting the correct values. Using this sort of logic, you can systematically debug your model.

If you know one you can start with “a” solution that gives positive profit or even zero profit by using fix.

Another quick check that is often handy is to think what happens if the company does “nothing”. Can it have 0 profit or is it infeasible? Just like I did above, you can also test some more things by removing certain terms from the equations, playing around with parameters to see if the model behaves as per your understanding.

Finding a result that contradicts your understanding of the problem is a good sign that something is wrong with the model and not everything is on point.