Interpreting presolve output

How should I interpret the output of show_stats with respect to the original model (the one prior to the presolve step)? I’m trying to understand the meaning behind the number of eliminated variables and constraints reported through presolve and substitution. An example output is shown below.

If I want to compute the total number of variables prior to presolve being called, I believe I can display _ncons and _nvars. I figured it would also be possible to arrive at the same number by adding the information in show_stats. For example, _ncons = eliminated presolve constraints + adjusted model constraints. This wasn’t correct, but after adding the number of variables that substitution eliminated I was able to get the original number of constraints. However, I noticed I need to add the eliminated substitution variables to the constraints and variables to get to their original model numbers. Is this correct? Why are the substituted variables being double counted? Are defined variables generated twice, once as a constraint and the other as a variable?

Below is a sample session that shows the output of show_stats and my calculations of _ncons and _nvars from the show_stats data.


Presolve eliminates 5269 constraints and 5226 variables.
Substitution eliminates 3421 variables.
“option presolve 10;” used, but “option presolve 11;” might work better.
Adjusted problem:
132 variables:
128 nonlinear variables
4 linear variables
134 constraints; 572 nonzeros
36 nonlinear constraints
98 linear constraints
116 equality constraints
18 range constraints
1 nonlinear objective; 20 nonzeros.

ampl: display _ncons, 5269+134+3421, _nvars, 5226+132+3421;
_ncons = 8824
5269 + 134 + 3421 = 8824
_nvars = 8779
5226 + 132 + 3421 = 8779
1 Like

Hi @_nr ,

While _nvars, _ncons are the number of variables/constraints before presolve, you can also get the “after presolve” (so the variables that actually go to the solver interface) with _snvars and _sncons.

There are similar sets you can display:

ampl.display("_var, _varname") # variables before presolve
ampl.display("_con, _conname") # constraints before presolve
ampl.display("_svar, _svarname") # variables after presolve
ampl.display("_scon, _sconname") # constraints after presolve

Yes, thank you for taking the time to respond! I am aware of _sncons and _snvars. These parameters equal the number of variables and constraints reported in the adjusted problem summary. I was just curious about the relationship between the numbers in the show_stats report. If my math is right, are substituted variables being double counted in the report?

1 Like

Are you creating “defined variables” by using an = operator in a var statement? AMPL counts each defined variable as also defining a constraint, thus adding 1 to both _nvars and _ncons. Then when AMPL’s presolve eliminates defined variables, both those variables and the associated constraints are removed, reducing _nvars and _ncons equally.

1 Like

That makes sense. Yes, I use defined variables in my model for a variety of reasons from keeping my subject to statements short to keeping track of intermediate values.

Thank you for the response.

1 Like