Should I use bounds or "singleton equations"?

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

Should I use bounds or "singleton equations"?

Post by aileen »

What is the difference with respect to model size between

Code: Select all

x.lo(i) = 1000;
and

Code: Select all

Equation xmin(i);
xmin(i) .. x(i) =g= 1000;
and between

Code: Select all

x.fx('i0') = 777;
and

Code: Select all

Equation xinit;
xinit .. x('i0') =e= 777;
aileen
User
User
Posts: 136
Joined: 3 years ago

Re: Should I use bounds or 'singleton equations'?

Post by aileen »

In general bounds (i.e. x.lo, and x.up) are more efficient than equations: a bound does not make the model bigger while an equation does. For solvers with good presolvers this advantage is less pronounced, as the presolver will convert "singleton equations" like x(i) =g= 1000; into bounds automatically.

Similarly preferably you should not generate many .fx fixed variables. In many cases you can use dollar conditions in the model so that GAMS will not generate them. You can also use the .holdfixed model suffix; this will cause GAMS to consider fixed variables as constants. Again, for a solver with a good presolver many fixed variables are not an issue; they will be removed from the model automatically.

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 trigger evaluation errors.

In general, bounds are preferred over single equations. The following example illustrates different ways of fixing variables:

Code: Select all

Set j / j1*j10 /;
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;
Locked