User Tools

Site Tools


gams:different_variable_types_within_one_definition

Differences

This shows you the differences between two versions of the page.

Link to this comparison view

Next revision
Previous revision
gams:different_variable_types_within_one_definition [2007/08/10 10:30]
127.0.0.1 external edit
gams:different_variable_types_within_one_definition [2020/05/26 12:19] (current)
Lutz Westermann link to docu; remove reference to very old gams version
Line 16: Line 16:
 // //
  
-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''​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 can be achieved using the [[https://​www.gams.com/​latest/​docs/​UG_Variables.html#​UG_Variables_VariableAttributes|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:+This feature is useful in solving difficult discrete models. The Model Library model "​Linear Recursive Sequence Optimization Model" ([[https://​www.gams.com/​latest/​gamslib_ml/​libhtml/​gamslib_lrs.html|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>​ <​code>​
-set   ​'all variables'​ /a1*a5/, +Set       ​'all variables'​ /a1*a5/ 
-abin(a) '​binary variables'​acont(a)'​continuous variables';​ +    abin(a) '​binary variables'​ 
-abin(a)$(ord(a)<​=(card(a)/​2))=yes ;+    ​acont(a)'​continuous variables';​ 
 +    ​ 
 +abin (a)$(ord(a)<​=(card(a)/​2))=yes ;
 acont(a)$(not abin(a))=yes;​ acont(a)$(not abin(a))=yes;​
 +
 display a, abin, acont; display a, abin, acont;
  
-variables ​z, x; binary variable ​x(a); +Variables ​z, x; 
-equation ​obj;+Binary Variable ​x(a); 
 + 
 +Equation ​obj; 
 obj.. z=e=sum(a, x(a)); obj.. z=e=sum(a, x(a));
 z.up  = card(a)-0.5;​ z.up  = card(a)-0.5;​
-model foo /all/;+ 
 +Model foo /all/;
 solve foo maximizing z using mip; solve foo maximizing z using mip;
 display z.l, x.l; display z.l, x.l;
 +
 x.prior(a) =inf; x.prior(abin) = 1; x.prior(a) =inf; x.prior(abin) = 1;
 solve foo maximizing z using mip; solve foo maximizing z using mip;
 display z.l, x.l; display z.l, x.l;
 +display x.lo, x.up;
 </​code>​ </​code>​
 The first solve statement will return: The first solve statement will return:
 <​code>​ <​code>​
-----     13 VARIABLE z.L                   ​= ​       4.000   +----     20 VARIABLE z.L                   ​= ​       4.000  ​ 
-----     13 VARIABLE x.L  ​+ 
 +----     20 VARIABLE x.L  ​ 
 a1 1.000, ​   a2 1.000, ​   a3 1.000, ​   a4 1.000 a1 1.000, ​   a2 1.000, ​   a3 1.000, ​   a4 1.000
 </​code>​ </​code>​
 and the second: and the second:
 <​code>​ <​code>​
-----     16 VARIABLE z.L                   ​= ​       4.500   +----     24 VARIABLE z.L                   ​= ​       4.500  ​ 
-----     16 VARIABLE x.L  ​+ 
 +----     24 VARIABLE x.L  ​ 
 a1 1.000, ​   a2 1.000, ​   a3 1.000, ​   a4 1.000, ​   a5 0.500 a1 1.000, ​   a2 1.000, ​   a3 1.000, ​   a4 1.000, ​   a5 0.500
 </​code>​ </​code>​
 Please note that this only changes the priorities, not the bounds of the variables! These will remain zero and one for all x: Please note that this only changes the priorities, not the bounds of the variables! These will remain zero and one for all x:
 <​code>​ <​code>​
-----     16 VARIABLE x.Lo  ​+----     25 VARIABLE x.Lo  ​ 
                       ( ALL       0.000 )                       ( ALL       0.000 )
-----     16 VARIABLE x.Up  + 
 + 
 +----     25 VARIABLE x.Up (1)  
                       ( ALL       1.000 )                       ( ALL       1.000 )
 </​code>​ </​code>​
IMPRESSUM / LEGAL NOTICEPRIVACY POLICY gams/different_variable_types_within_one_definition.1186734602.txt.gz · Last modified: 2007/08/10 10:30 by 127.0.0.1