Incorrect solution in code running

Problems with modeling
Post Reply
Sandrina
User
User
Posts: 5
Joined: 2 years ago

Incorrect solution in code running

Post by Sandrina »

Hello everyone,

I have implemented a mathematical model in GAMS whose code runs without errors. However, only the binary variables have the correct solution. All the rest are zero, which is not supposed to be. I think the problem is in the code and not in the mathematical formulation, but I can't figure out what the problem is because given the data I entered I should have values for the positive variables. Does anyone have any idea what the problem could be?

Thanks in advance!
GFA
User
User
Posts: 50
Joined: 5 years ago

Re: Incorrect solution in code running

Post by GFA »

Hi Sandrina,

It is hard to give any advice since the information you provided is quite limited.
One thing you could try is to make your model as small as possible, or make a simple toy example. This usually makes it easier to analyse the model's behaviour.

Regards,
GFA
Sandrina
User
User
Posts: 5
Joined: 2 years ago

Re: Incorrect solution in code running

Post by Sandrina »

Hi!
Since I am not very experienced in using GAMS, I can not understand what the problem is. I leave the code attached because maybe someone can help me. The data entered are validation data and not the real data.
Untitled_5.gms
(21.24 KiB) Downloaded 158 times
Thank you very much!
GFA
User
User
Posts: 50
Joined: 5 years ago

Re: Incorrect solution in code running

Post by GFA »

Hi sandrina,

Try using starting values for your variables, this usually helps the solve. See: https://www.gams.com/latest/docs/UG_Variables.html
Hope this helps.

GFA
User avatar
bussieck
Moderator
Moderator
Posts: 1033
Joined: 7 years ago

Re: Incorrect solution in code running

Post by bussieck »

Hi,

If the a model does not return a "good" solution you need to debug the model. Always work with a small data set (if possible) for this. Bruce McCarl has some good advice on model debugging, see https://www.gams.com/latest/docs/UG_Exe ... allToLarge.

When I have a situation like yours I set the variable levels before the solve to an optimal solution. This can be done for a small problem by hand or by setting some key variables and then code to set the other variables. The latter might require to duplicate some of the equation code. Looking at these calculated values already might give you some idea where things go wrong. If your "optimal" solution you calculated looks good you can now have GAMS generate the model. For this turn the equation list on in full (modelname.limrow=1e9) and check the listing file for this "Equation Listing" section afterwards. If GAMS accepts the "solution" then the equation listing will have no "INFES" (infeasibility) markers for the input point. If it does, and that will the in your case, then your "solution" is not a solution for your model and the INFES marker tells you the exact equation that does not work. You can then work on this, but adjusting your "solution" or adjusting the model equation logic.

You probably won't receive much concrete/detailed help for your model in this forum because you as the developer are the only one that (with reasonable effort) can debug your model. You know what it is supposed to do, others don't. So we can only help you with advice how to debug, the debugging itself has to be done by you or you convince someone to invest heavily in your model (logic) which often goes together with some sort of payment.

Good luck,
-Michael
Post Reply