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?

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:

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;