Gams Results not Consistent with Constraints I defined

Problems with modeling
Post Reply
Moana
User
User
Posts: 2
Joined: 1 year ago

Gams Results not Consistent with Constraints I defined

Post by Moana »

Hi experts!

I have written a code in GAMS and hopefully it works well.
But I find that the results are not consistent with the constraints I defined in EQUATIONS .

In the Equation D_b(i), I define that each D_b should be equal or larger than 0, like this:

Code: Select all

D_b(i)   ..      p5+p11*b(i)+p12*c(i)+p13*l(i)+*p14*y(i) =g= 0;  
And in the .lst file, it shows that each D_b(i) be solved on just zero(represented by ".").
But when displaying them, I find that each D_b(i) is still negative (about -1.4584E-26 and so on)

Code: Select all

parameter
         db(i);
db(i)= p5.l+p11.l*b(i)+p12.l*c(i)+p13.l*l(i)+p14.l*y(i);
display db,dy,sprice;

Code: Select all

----    746 PARAMETER db  

1   -1.4584E-26,    2   -3.5000E-26,    3   -4.4283E-27,    4   -9.2929E-28
5   -1.2404E-27,    6   -9.2131E-28,    7   -4.0874E-27,    8   -2.3711E-27
9   -4.2175E-27,    10  -2.3077E-27,    11  -4.7505E-28,    12  -8.5157E-28
13  -2.4389E-27,    14  -1.1383E-26,    15  -3.6343E-26,    16  -3.6976E-27
17  -7.8643E-28,    18  -1.0797E-27,    19  -7.7971E-28,    20  -3.6147E-27
21  -2.2054E-27,    22  -3.2541E-27,    23  -2.1021E-27,    24  -4.1078E-28
25  -7.2960E-28,    26  -2.1892E-27,    27  -1.3065E-26,    28  -3.7490E-26
29  -3.8722E-27,    30  -8.5505E-28,    31  -1.1503E-27,    32  -7.9799E-28
33  -3.7073E-27,    34  -2.2435E-27,    35  -3.4572E-27,    36  -2.1607E-27
37  -4.5059E-28,    38  -7.7830E-28,    39  -2.2740E-27,    40  -1.4065E-26
41  -4.1160E-26,    42  -6.3776E-27,    43  -1.7800E-27,    44  -2.1074E-27
45  -1.6047E-27,    46  -6.2262E-27,    47  -3.8592E-27,    48  -5.8157E-27
49  -3.7423E-27,    50  -1.0368E-27,    51  -1.5545E-27,    52  -3.9654E-27
53  -1.6316E-26,    54  -4.7145E-26,    55  -6.6722E-27,    56  -2.0295E-27
57  -2.2796E-27,    58  -1.7494E-27,    59  -6.5698E-27,    60  -4.0855E-27
61  -6.2166E-27,    62  -3.9907E-27,    63  -1.1232E-27,    64  -1.6744E-27
65  -4.2464E-27,    66  -1.8589E-26,    67  -4.6225E-26,    68  -6.7911E-27
69  -2.0289E-27,    70  -2.1684E-27,    71  -1.7633E-27,    72  -6.3813E-27
73  -3.9653E-27,    74  -5.9819E-27,    75  -3.9666E-27,    76  -1.1421E-27
77  -1.6868E-27,    78  -4.2258E-27,    79  -2.0254E-26,    80  -4.1478E-26
81  -4.6228E-27,    82  -1.3284E-27,    83  -1.2926E-27,    84  -1.5244E-27
85  -5.9429E-27,    86  -3.6154E-27,    87  -4.7947E-27,    88  -1.8111E-27
89  -1.0305E-27,    90  -1.5217E-27,    91  -3.7405E-27,    92  -2.1457E-26
93  -4.2138E-26,    94  -4.8327E-27,    95  -1.3290E-27,    96  -8.3098E-28
97  -1.0631E-27,    98  -6.0460E-27,    99  -4.3302E-27,    100 -4.8767E-27
101 -1.8568E-27,    102 -1.0454E-27,    103 -1.3239E-27,    104 -2.9145E-27
Why GAMS didn't make it positive?

I heard that every solver had its feasibility tolerance from here "viewtopic.php?f=9&t=12659".
Is my problem resulted from GAMS treated E-27 as zero?

How to solve that? I want positive D_b(i).
Here is the code and I used MINOS 5 , GAMS 24.8.2
Thanks very much! :D

MOANA
Untitled_1.gms
(14.26 KiB) Downloaded 42 times
User avatar
bussieck
Moderator
Moderator
Posts: 1033
Joined: 7 years ago

Re: Gams Results not Consistent with Constraints I defined

Post by bussieck »

The reason is that the NLP solver gives you values very close to 0 (within tolerance) and these lead to slightly negative values of the left hand side of your <= 0 constraint. There is nothing wrong with what the solver does. It provides a solution within tolerances. If you solve with an simplex LP solver (the model is actually linear), e.g. Cplex, they turn internally the free variable x into two positive variables p and n and represent x = p - n. The simplex algorithm keeps many of these variables in the non-basis (hence at bound) and so you don't get these small values with a simplex based LP solver and hence no violation in D_b:

Code: Select all

----    715 the activity level of p1
            VARIABLE p1.L                  =       -0.239  
            the activity level of p2
            VARIABLE p2.L                  =        0.395  
            the activity level of p3
            VARIABLE p3.L                  =        0.000  
            the activity level of p4
            VARIABLE p4.L                  =       -1.000  
            the activity level of p5
            VARIABLE p5.L                  =        0.000  
            the activity level of p6
            VARIABLE p6.L                  =       -0.003  
            the activity level of p7
            VARIABLE p7.L                  =        0.000  
            the activity level of p8
            VARIABLE p8.L                  =        0.000  
            the activity level of p9
            VARIABLE p9.L                  =        0.000  
            the activity level of p10
            VARIABLE p10.L                 =        0.000  
            the activity level of p11
            VARIABLE p11.L                 =        0.000  
            the activity level of p12
            VARIABLE p12.L                 =        0.000  
            the activity level of p13
            VARIABLE p13.L                 =        0.000  
            the activity level of p14
            VARIABLE p14.L                 =        0.000  
            the activity level of p15
            VARIABLE p15.L                 =        0.000  
            the activity level of p16
            VARIABLE p16.L                 =        0.000  
            the activity level of p17
            VARIABLE p17.L                 =        0.001  
            the activity level of p18
            VARIABLE p18.L                 =        0.216  

----    746 PARAMETER db  

                      ( ALL  0.00000000 )


----    746 PARAMETER dy  

1   -1.00000000,    2   -1.00000000,    3   -1.00000000,    4   -1.00000000,    5   -1.00000000,    6   -1.00000000,    7   -1.00000000,    8   -1.00000000,    9   -1.00000000,    10  -1.00000000,    11  -1.00000000,    12  -1.00000000,    13  -1.00000000,    14  -1.00000000,    15  -1.00000000,    16  -1.00000000,    17  -1.00000000,    18  -1.00000000,    19  -1.00000000,    20  -1.00000000,    21  -1.00000000,    22  -1.00000000,    23  -1.00000000,    24  -1.00000000,    25  -1.00000000,    26  -1.00000000,    27  -1.00000000,    28  -1.00000000,    29  -1.00000000,    30  -1.00000000,    31  -1.00000000,    32  -1.00000000,    33  -1.00000000,    34  -1.00000000,    35  -1.00000000,    36  -1.00000000,    37  -1.00000000,    38  -1.00000000,    39  -1.00000000,    40  -1.00000000,    41  -1.00000000,    42  -1.00000000,    43  -1.00000000,    44  -1.00000000,    45  -1.00000000,    46  -1.00000000,    47  -1.00000000,    48  -1.00000000,    49  -1.00000000,    50  -1.00000000,    51  -1.00000000,    52  -1.00000000,    53  -1.00000000,    54  -1.00000000,    55  -1.00000000,    56  -1.00000000,    57  -1.00000000,    58  -1.00000000,    59  -1.00000000,    60  -1.00000000,    61  -1.00000000,    62  -1.00000000,    63  -1.00000000,    64  -1.00000000,    65  -1.00000000,    66  -1.00000000,    67  -1.00000000,    68  -1.00000000,    69  -1.00000000,    70  -1.00000000,    71  -1.00000000,    72  -1.00000000,    73  -1.00000000,    74  -1.00000000,    75  -1.00000000,    76  -1.00000000,    77  -1.00000000,    78  -1.00000000,    79  -1.00000000,    80  -1.00000000,    81  -1.00000000,    82  -1.00000000,    83  -1.00000000,    84  -1.00000000,    85  -1.00000000,    86  -1.00000000,    87  -1.00000000,    88  -1.00000000,    89  -1.00000000,    90  -1.00000000,    91  -1.00000000,    92  -1.00000000,    93  -1.00000000,    94  -1.00000000,    95  -1.00000000,    96  -1.00000000,    97  -1.00000000,    98  -1.00000000,    99  -1.00000000,    100 -1.00000000,    101 -1.00000000,    102 -1.00000000,    103 -1.00000000,    104 -1.00000000


----    746 PARAMETER sprice  

                      ( ALL  0.00000000 )
24.8 still has the free simplex based LP solver BDMLP (dropped in more recent versions of GAMS) and SOPLEX.

You could also play around with rounding your variables after 16 digits or something like this after the solve.

-Michael
Moana
User
User
Posts: 2
Joined: 1 year ago

Re: Gams Results not Consistent with Constraints I defined

Post by Moana »

It really works! After changing decimal places, I got positive D_b. Thank you!

But I don't understand what "non-basis" mean, could you please explain it to me ?

In addition, Cplex, BDMLP and SOPLEX all show that " algorithm not suitable for the process", which is confusing.

Thank you again!

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

Re: Gams Results not Consistent with Constraints I defined

Post by bussieck »

The LP solvers only solve LPs, so you need to change your solve statement from "solve direct_function using nlp minimizing obj;" to "solve direct_function using lp minimizing obj;". It helps to understand how the solver algorithms work (but is not necessary for casual modeling), you can study the simplex algorithm and the meaning of basis and non-basis in any text book on optimization. Consult e.g. Wikipedia as a starting point: https://en.wikipedia.org/wiki/Simplex_algorithm

-Michael
Post Reply