Different variable types within one definition

Frequently asked questions about GAMS

Moderator: aileen

Forum rules
Please ask questions in the other sub-forums
Locked
aileen
User
User
Posts: 136
Joined: 3 years ago

Different variable types within one definition

Post by aileen »

Is there a concise way to declare some of the decision variables within a class, say, binary and the rest of the class continuous? For example, can we achieve the following notional declarations and how (that are illegal in the form shown below)?

Code: Select all

BINARY VARIABLES
VARCLASS(A)$(ORD(A) LT CARD(A)/2) the first half are binary;
POSITIVE VARIABLES
VARCLASS(A)$(ORD(A) GE CARD(A)/2) the rest are continuous;
Can we declare a class of variables to be continuous at some point in the code and redeclare them to be binary later?
aileen
User
User
Posts: 136
Joined: 3 years ago

Re: Different variable types within one definition

Post by aileen »

This can be achieved using the priority attribute. The priority attribute of a discrete variable can be used to relax a specific variable instance. The priority attribute .prior establishes in what order variables are to be fixed to integral values while searching for a solution. Variables with a specific .prior value will remain relaxed until all variables with a lower .prio values have been fixed. Setting the .prior value to +inf will relax this variable permanently. This relaxation is done independent of the model attribute .prioropt.

This feature is useful in solving difficult discrete models. The Model Library model "Linear Recursive Sequence Optimization Model" (lrs.gms) illustrates the use of this feature that specifies that only the first n variables of k are binary, whereas the remaining ones are fractional. Find below a simple example:

Code: Select all

Set a       'all variables' /a1*a5/
    abin(a) 'binary variables'
    acont(a)'continuous variables';
    
abin (a)$(ord(a)<=(card(a)/2))=yes ;
acont(a)$(not abin(a))=yes;

display a, abin, acont;

Variables z, x;
Binary Variable x(a);

Equation obj;

obj.. z=e=sum(a, x(a));
z.up  = card(a)-0.5;

Model foo /all/;
solve foo maximizing z using mip;
display z.l, x.l;

x.prior(a) =inf; x.prior(abin) = 1;
solve foo maximizing z using mip;
display z.l, x.l;
display x.lo, x.up;
The first solve statement will return:

Code: Select all

----     20 VARIABLE z.L                   =        4.000  

----     20 VARIABLE x.L  

a1 1.000,    a2 1.000,    a3 1.000,    a4 1.000
and the second:

Code: Select all

----     24 VARIABLE z.L                   =        4.500  

----     24 VARIABLE x.L  

a1 1.000,    a2 1.000,    a3 1.000,    a4 1.000,    a5 0.500
Please note that this only changes the priorities, not the bounds of the variables! These will remain zero and one for all x:

Code: Select all

----     25 VARIABLE x.Lo  

                      ( ALL       0.000 )


----     25 VARIABLE x.Up (1) 

                      ( ALL       1.000 )
Locked