-
Notifications
You must be signed in to change notification settings - Fork 43
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
doubts on correctness of sol.h:WriteSolFile #135
Comments
@svigerske I have actually never tried calling SHOT from AMPL, only Pyomo. Perhaps Pyomo is more forgiving? |
I could imagine that Pyomo doesn't treat it as error if SHOT says that it specifies only 0 of these mysterious options instead of between 3 and 9. Given the response of the AMPL folks here, it doesn't seem that they intend to explain (or remember) the full specification of that file. But you might want to try running SHOT under the free version of AMPL and see if that works (doesn't this need to accept |
Hi @svigerske, what is the header of your .nl file? The options that need to be written in .sol file originate from the first line of the .nl file. |
I don't know what header AMPL was writing when creating a .nl file.
So I should write But I use |
The options are from the first line of the nl file. In this case "3 0 1 0". These options are used internally by AMPL and are mostly related with the presolver to know some settings that were set during the nl file generation. One of our drivers using the mp interface is ilogcp and and it seems to be passing the options correctly from the nl file to the sol file. Is mp::ReadNLFile() not reading this information correctly? If it is reading this information correctly, then you should only need to write the options again in the sol file ("3\n0\n1\n0\n" in this case). |
I tried to follow |
Looking at an example may be easier to understand the content of a sol file: ampl: model diet.mod;
ampl: data diet.dat;
ampl: write gdiet; # write diet.nl
ampl: solve; # write diet.sol
MINOS 5.51: optimal solution found.
6 iterations, objective 88.2
ampl: display Buy;
Buy [*] :=
BEEF 0
CHK 0
FISH 0
HAM 0
MCH 46.6667
MTL 1.57618e-15
SPG 8.42982e-15
TUR 0
;
ampl: display Diet.dual;
Diet.dual [*] :=
A 0.00181818
B1 0.00818182
B2 0.116
C -8.16933e-18
; The header of diet.nl is "g3 0 1 0 # problem diet;" and the content of diet.sol is:
The first part is related to the header "3 0 1 0":
Then we have the dimensions (number of constraints, number of values for constraints in the solution, number of variables, number of values for variables in the solution):
Dual values for Diet.dual:
Primal values for variable Buy:
After this we have the objective number and status and then some suffixes are included as well. So we have dual values first and primal values after. In https://github.com/ampl/asl/blob/64919f75fa7a438f4b41bce892dcbe2ae38343ee/src/solvers/writesol.c#L434-L443 the same happens with In https://github.com/ampl/asl/blob/64919f75fa7a438f4b41bce892dcbe2ae38343ee/src/solvers/writesol.c, the array z[0] = m = asl->i.n_con0;
if (!y)
m = 0;
z[1] = m;
z[2] = n = asl->i.n_var0;
if (!x)
n = 0;
z[3] = n;
fprintf(f,"%ld\n%ld\n%ld\n%ld\n", (long)z[0],(long)z[1],(long)z[2],(long)z[3]); |
Concerning the Options issue: ilogcp correctly transfers "3 0 1 0" from alan.nl into alan.sol, so if you use standard mp setup it should work. Concerning the order of dual/primal values: the code in sol.h is indeed buggy:
I fixed it on master. mp drivers have never done much with continuous variables (ilogcp's option 'optimizer=cplex' is non-default), so this is just not enough tested (but we are getting there). |
So the issue that remains then in
is wrong if there are no dual values or there are no primal values. Examples are nice, but they cover only one case each. I had hoped you could point to a specification of .sol files. |
…nts at the beginning of the solution file).
I tried to adapt the code
for an AMPL interface I was writing, but had problems to get the solution accepted by AMPL.
I don't have options, so the lines
would only print the line
Options
. For my tiny test problem (2 vars, 2 constraints), I then get this from AMPL:If I change my code to do essentially
thus print
Options\n0\n
, then, as expected, I get this from AMPL:(@andreaslundell does this really work for you?)
What worked from me (and I copied that from a .sol file I had around somewhere) was to print
Options\n3\n2\n1\n0\n
, but I have no idea what the 2, 1, 0, actually mean.Next, there is
file.print("{0}\n{0}\n{1}\n{1}\n", num_dual_values, num_values);
but when I look at writesol.c from ASL, then my impression is that this should actually be
And after this, we have
but it seems that AMPL expects to see the constraint dual values first and the variable primal values afterwards (https://github.com/ampl/asl/blob/64919f75fa7a438f4b41bce892dcbe2ae38343ee/src/solvers/writesol.c#L434-L443).
The text was updated successfully, but these errors were encountered: