gams:different_variable_types_within_one_definition

*Q: 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)?
*

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?
*

Starting with Distribution 22.1 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`

r 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:

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;

The first solve statement will return:

---- 13 VARIABLE z.L = 4.000 ---- 13 VARIABLE x.L a1 1.000, a2 1.000, a3 1.000, a4 1.000

and the second:

---- 16 VARIABLE z.L = 4.500 ---- 16 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:

---- 16 VARIABLE x.Lo ( ALL 0.000 ) ---- 16 VARIABLE x.Up ( ALL 1.000 )

IMPRESSUM / LEGAL NOTICE
PRIVACY POLICY
gams/different_variable_types_within_one_definition.txt · Last modified: 2007/08/10 08:30 (external edit)