Closed 4er4er4er closed 1 year ago
The reason is the slow writing of the SOL file in text format. MP does not implement binary SOL writing yet, see #142. As the script only waits for the SOL file to appear, it proceeds to the solution mpsi.sol;
command, which tries to read the incomplete file. ASL driver, when asked to use text SOL format, causes the same failure.
Note that this could also happen with the binary format for large enough files.
Workaround: wait 20 s after detecting the SOL file by adding shell 'timeout /t 20';
after the loop (some wait could also happen before the continue
). This still does not guarantee success, as a busy system can take longer to complete the file.
Solution: perform the initial solve by the solve;
command, similar to the subsequent solve. Its output can be redirected: solve >solve1.txt;
. I assume the reason for putting the initial solve into a subprocess is due to a port from another modeling/solving tool; I don't see any reason to do this with AMPL.
The whole setup could become more transparent with in-memory solver interfaces.
A web search turned up this hack, which seems to work: Replace the shell
statement inside the loop by
shell ('ren mpsi.sol mpsi.sol 1>nul 2>nul');
But I agree there doesn't seem to be any reason to invoke AMPL in this complicated way, instead of using a solve
.
The two Windows scripts in MDXoptimalmarkets.zip are the same except that one uses
xpressasl
where the other usesxpress
. Executinginclude mdx_asl.run
leads to a successful conclusion:But
include mdx_new1.run
(using MP) fails with an "early end of file" error:It might be that the old ASL option names have not been converted properly to the new MP option names, or that some new option works differently than before -- but I'm not seeing where the difference is.
Note that the first solve in the script is carried out by
or
so it directs output to its own command window. The user who provided this minimal example might be doing this because it's required somehow by the complete application.