ampl / mp

An open-source library for mathematical programming
https://mp.ampl.com
Other
227 stars 43 forks source link

Spaces required between solver options? #199

Open 4er4er4er opened 1 year ago

4er4er4er commented 1 year ago

Using ASL solvers, it was possible to specify an option string that had no space between option specifications. A user has provided this minimal example:

var x;

minimize Obj: x;
subject to Bound: x>=0;

option solver gurobiasl;
option gurobi_options 'outlev 0';
option gurobi_options $gurobi_options 'presolve 0';

solve;
option gurobi_options;

which gives a succesful Gurobi 10.0 run, even though it reports the option string to be 'outlev 0presolve 0'. When run with the MP-based Gurobi version, however, this example rejects the option string:

option gurobi_options;
Gurobi 10.0.0: Invalid value "0presolve" for option "tech:outlev"
Unknown option or invalid key "0"
tech:outlev=0
exit value 1
<BREAK>

The user was concerned because his old scripts were breaking when he tried to use them with the MP version, and he had to change to, for example,

option gurobi_options 'outlev 0';
option gurobi_options $gurobi_options ' presolve 0';

Should we try to reproduce ASL's option processing (without spaces) in MP, or should we declare that it was an undocumented feature of ASL that we have chosen not to perpetuate?

fdabrandao commented 1 year ago

I think we should declare that it was an undocumented featured of ASL since the space should ideally be included every time. Otherwise we also get situations like the following:

option gurobi_options 'outlev=1 writeprob=model.lp';
option gurobi_options $gurobi_options 'presolve 0';

This does not work with both gurobi and gurobiasl since it becomes "outlev=1 writeprob=model.lppresolve 0".

glebbelov commented 1 year ago

Would it be clean to always insert a space when appending to AMPL option value?

4er4er4er commented 1 year ago

I think this could work for solver options, with very low probability of breaking any existing scripts. However, a potential problem is that AMPL's option command does not know the difference between setting a solver option string and setting any other option, and thus it would also add spaces in other contexts, like this:

ampl: option directory "/usr/4er";
ampl: option filename1 "diet.mod";
ampl: option file $directory "/" $filename1;

ampl: option file;
option file '/usr/4er/diet.mod';

We could try to arrange to only add spaces when the option name ends in _options, but that would be kludgy.