<div dir="ltr"><div dir="ltr"><div>Hello, Stefan.</div><div>My colleague, Sergey Smirnov, had applied your patch to the latest SCIP release 6.0.2 and we tested some problems to check it.</div><div>In a few words - patched SCIPAMPL does not return right solution as SOL-file.</div><div><br></div><div>After a number of tests I can suggest the following: <br></div>if NL-file contains initial values of the problem's variables then the SOL-file returned contains these initial values, rather than optimal solution;<br><div>else - values of all variables in SOL-file are equal to zero.</div><div><br></div><div>It seems that it is so even for the test problem you mentioned [scipoptsuite-6.0.2/scip/interfaces/ampl/check/instances/MINLP/<a href="http://ex1266.nl">ex1266.nl</a>]. <br></div><div>See in attachment:</div><div>[<a href="http://ex1266.nl">ex1266.nl</a>] the NL-file we have;<br></div><div>[ex1266.cip.sol] CIP-solution returned by SCIP from ex1266.cip <a class="gmail_plusreply" id="plusReplyChip-1">"created</a> from"  <a href="http://ex1266.nl">ex1266.nl</a> (it has initial values, see line #317 and below ;</div><div>[ex1266.sol] SOL-file returned by patched SCIPAMPL after "normal" optimization;</div><div>[ex1266.cip.2.sol] SOL-file returned by patched SCIPAMPL as a result of the "trick" you suggested (it .</div><div><br></div><div>When we took a look at your patch a suggestion arose: may be it is something wrong with the array index of SCIPgetSols(scip)[SCIPgetNSols(scip)-1] ?</div><div>The implementation of the function <a class="gmail-code" href="https://scip.zib.de/doc-6.0.2/html/scip__sol_8c_source.php#l02254">SCIPgetBestSol</a> returns scip->primal->sols[0] (line #2337), i.e. THE FIRST element of "sols" array, not THE LAST!<br> </div></div><div><br></div><div>Best regards,</div><div>Vladimir.<br></div><div><br></div><div class="gmail_quote"><div dir="ltr" class="gmail_attr">On Mon, Feb 10, 2020 at 3:01 PM Stefan Vigerske <<a href="mailto:svigerske@gams.com" target="_blank">svigerske@gams.com</a>> wrote:<br></div><blockquote class="gmail_quote" style="margin:0px 0px 0px 0.8ex;border-left:1px solid rgb(204,204,204);padding-left:1ex">Hi,<br>
<br>
there might be a way to get around step 3 and 4, i.e., let SCIPAMPL <br>
write out the solution that you just read without going through a solve.<br>
I applied the patch below and ran, from scip/interfaces/ampl:<br>
<br>
echo "write prob ex1266.cip q" | ./bin/scipampl <br>
check/instances/MINLP/<a href="http://ex1266.nl" rel="noreferrer" target="_blank">ex1266.nl</a> -i<br>
  ../../bin/scip -c "read ex1266.cip opt write sol ex1266.cip.sol q"<br>
echo "read ex1266.cip.sol write amplsol q" | ./bin/scipampl <br>
check/instances/MINLP/<a href="http://ex1266.nl" rel="noreferrer" target="_blank">ex1266.nl</a> -i && cat check/instances/MINLP/ex1266.sol<br>
<br>
The first line converts an .nl file to .cip.<br>
The second line solves the .cip and saves the .sol.<br>
The third line reads the .nl and the .sol and writes the AMPL solution.<br>
<br>
If you do that, does this bring you back the right solution into AMPL or <br>
Pyomo?<br>
<br>
Stefan<br>
<br>
<br>
--- a/interfaces/ampl/src/reader_nl.c<br>
+++ b/interfaces/ampl/src/reader_nl.c<br>
@@ -1850,6 +1850,13 @@ SCIP_RETCODE SCIPwriteAmplSolReaderNl(<br>
<br>
     /* get best primal solution */<br>
     x = NULL;<br>
+   if( SCIPgetStatus(scip) == SCIP_STATUS_UNKNOWN && SCIPgetNSols(scip) <br>
 > 0 )<br>
+   {<br>
+      SCIP_CALL( SCIPallocBufferArray(scip, &x, probdata->nvars) );<br>
+      SCIP_CALL( SCIPgetSolVals(scip, <br>
SCIPgetSols(scip)[SCIPgetNSols(scip)-1], probdata->nvars, <br>
probdata->vars, x) );<br>
+      msg = "lastsol";<br>
+      solve_result_num = 0;<br>
+   }<br>
     if( SCIPgetBestSol(scip) != NULL )<br>
     {<br>
        SCIP_CALL( SCIPallocBufferArray(scip, &x, probdata->nvars) );<br>
<br>
<br>
On 2/10/20 12:05 AM, Vladimir V. Voloshinov wrote:<br>
> Dear SCIP developers,<br>
> can you recommend some way to convert solution in CIP format to AMPL<br>
> SOL-file (in the presence of corresponding NL-file in AMPL format)?<br>
> <br>
> I found that the following trick helps, but may be there is another way?<br>
> Suppose we have: <a href="http://problem.nl" rel="noreferrer" target="_blank">problem.nl</a>, appropriate problem.nl.cip and problem.cip.sol<br>
> (returned, e.g. by FiberSCIP, for problem.nl.cip as an input model).<br>
> 1. Start SCIPAMPL console and load <a href="http://problem.nl" rel="noreferrer" target="_blank">problem.nl</a> as model<br>
> $ scipampl <a href="http://problem.nl" rel="noreferrer" target="_blank">problem.nl</a> -i<br>
> 2. Read problem.cip.sol from SCIPAMPL console (outputs presented below)<br>
> SCIP> read problem.cip.sol<br>
> primal solution from solution file <problem.cip.sol> was accepted as<br>
> candidate, will be checked when solving starts<br>
> 3. Load some limits to stop optimization process just after beginning, e.g.<br>
> SCIP> set limits nodes 2<br>
> 4. Start optimization and wait a few seconds<br>
> SCIP> optimize<br>
> 5. Write AMPL SOL-file<br>
> SCIP> write amplsol<br>
> Now we get problem.sol containing the solution in AMPL format.<br>
> The only drawback is the first string with solver status "node limit<br>
> reached" in problem.sol, but it may be "manually" replaced with "optimal<br>
> solution found" to get correct SOL-file with appropriate status.<br>
> <br>
> See some additional notes below.<br>
> We use Pyomo Python package to prepare optimization model and write it to<br>
> NL-file (AMPL format). Usually we use SCIPAMPL to read NL-file and to get<br>
> solution as SOL-file (AMPL format), which may be loaded "back" to the model<br>
> by Pyomo tools to analyse  results.<br>
> But for hard problems we need to use ParaSCIP or FiberSCIP. For that we use<br>
> SCIPAMPL console to convert NL-file to CIP-file,<br>
> <a href="https://scip.zib.de/doc-6.0.2/html/reader__cip_8h.php" rel="noreferrer" target="_blank">https://scip.zib.de/doc-6.0.2/html/reader__cip_8h.php</a>, because ParaSCIP and<br>
> FiberSCIP does not accept AMPL-formats. So, we get solutions also in<br>
> CIP-format, but Pyomo does not provide tool to load solutions from CIP.sol !<br>
> Up to now,  for special cases, homebred "readers" have been used, but we<br>
> need more universal approach.<br>
> <br>
> Sincerely yours,<br>
> Vladimir.<br>
> <br>
> <br>
> _______________________________________________<br>
> Scip mailing list<br>
> <a href="mailto:Scip@zib.de" target="_blank">Scip@zib.de</a><br>
> <a href="https://listserv.zib.de/mailman/listinfo/scip" rel="noreferrer" target="_blank">https://listserv.zib.de/mailman/listinfo/scip</a><br>
> <br>
<br>
_______________________________________________<br>
Scip mailing list<br>
<a href="mailto:Scip@zib.de" target="_blank">Scip@zib.de</a><br>
<a href="https://listserv.zib.de/mailman/listinfo/scip" rel="noreferrer" target="_blank">https://listserv.zib.de/mailman/listinfo/scip</a><br>
</blockquote></div><br></div>