# GAMS Support Wiki

### Site Tools

gams:should_i_use_bounds_or_singleton_equations

# Differences

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

 gams:should_i_use_bounds_or_singleton_equations [2020/05/28 15:16]Michael Bussieck gams:should_i_use_bounds_or_singleton_equations [2020/05/28 15:29] (current)Michael Bussieck Both sides previous revision Previous revision 2020/05/28 15:29 Michael Bussieck 2020/05/28 15:16 Michael Bussieck 2020/05/27 16:17 Lutz Westermann format and link to documentation2007/10/20 07:44 Franz Nelissen 2007/09/28 13:30 external edit 2020/05/28 15:29 Michael Bussieck 2020/05/28 15:16 Michael Bussieck 2020/05/27 16:17 Lutz Westermann format and link to documentation2007/10/20 07:44 Franz Nelissen 2007/09/28 13:30 external edit Line 25: Line 25: Nonlinear solvers usually do not violate bounds, because bounds describe the region where function and derivative calculations are possible, e.g. ''​log(x)''​ with ''​x.lo=1e-6;''​. A constraint ''​xlo.. x =g= 1e-6;''​ can in principle be violated by the solvers feasibility tolerance. If this tolerance is larger than 1e-6 then the 0 (and negative numbers) becomes part of the region where the solver can evaluate points and hence might triggers evaluation errors. Nonlinear solvers usually do not violate bounds, because bounds describe the region where function and derivative calculations are possible, e.g. ''​log(x)''​ with ''​x.lo=1e-6;''​. A constraint ''​xlo.. x =g= 1e-6;''​ can in principle be violated by the solvers feasibility tolerance. If this tolerance is larger than 1e-6 then the 0 (and negative numbers) becomes part of the region where the solver can evaluate points and hence might triggers evaluation errors. + + In general, so bounds are prefered over single equations. The following example illustrates different ways of fixing variables: + + <​code>​ + Set j / 1*10 /; + Parameter a(j); + a(j) = uniform(1,​10);​ + Variables x(j), z; + Equations f(j), obj; + obj..  z =e= sum{j, power(x(j)-4,​2)};​ + f(j).. x(j) =e= a(j); + model foo / obj / + bar / obj, f /; + ​ + * This model has many constraints,​ many free variables + * The solver has freedom in presolving/​removing them (if it can) or not + * In the listing, the nonzero marginals are on the equation f(j) + solve bar using nlp minimizing z; + + * This model has one constraint, many variables + * The solver has freedom in presolving/​removing them (if it can) or not + * In the listing, the nonzero marginals are on the variables x(j) + x.fx(j) = a(j); + solve foo using nlp minimizing z; + + * With holdfixed on, the solver sees only one constraint, one variable + * It doesn’t even know the variable x exists + * In the listing, you won’t see any marginals for x, since the solver never saw x + x.m(j) = 0; + foo.holdfixed = 1; + solve foo using nlp minimizing z; + 