amplneos-server

Print only nonzero results using AMPL + Neos server


I'm doing a optimization model of a relatively big model. I will use 15 timesteps in this model, but now when I'm testing it I am only using 4. However, even with 11 time steps less than desired the model still prints 22 000 rows of variables, where perhaps merely a hundred differs from 0.

Does anyone see a way past this? I.e. a way using NEOS server to only print the variable name and corresponding value if it is higher than 0.

What I've tested is:

 solve; 
 option omit_zero_rows 0; (also tried 1;)
 display _varname, _var;

Using both omit_zero_rows 0; or omit_zero_rows 1; still prints every result, and not those higher than 0.

I've also tried:

solve;
if _var > 0 then {
      display _varname, _var;
}

but it gave me syntax error. Both (or really, the three) variants were tested in the .run file I use for NEOS server.


Solution

  • I'm posting a solution to this issue, as I believe that this is an issue more people will stumble upon. Basically, in order to print only non-zero values using NEOS Server write your command file (.run file) as:

    solve;
    display {j in 1.._nvars: _var[j] > 0} (_varname[j], _var[j]);