[SCIP] Conversion of CIP.sol to NL.sol

Stefan Vigerske svigerske at gams.com
Mon Feb 10 12:32:28 CET 2020


Hi,

there might be a way to get around step 3 and 4, i.e., let SCIPAMPL 
write out the solution that you just read without going through a solve.
I applied the patch below and ran, from scip/interfaces/ampl:

echo "write prob ex1266.cip q" | ./bin/scipampl 
check/instances/MINLP/ex1266.nl -i
  ../../bin/scip -c "read ex1266.cip opt write sol ex1266.cip.sol q"
echo "read ex1266.cip.sol write amplsol q" | ./bin/scipampl 
check/instances/MINLP/ex1266.nl -i && cat check/instances/MINLP/ex1266.sol

The first line converts an .nl file to .cip.
The second line solves the .cip and saves the .sol.
The third line reads the .nl and the .sol and writes the AMPL solution.

If you do that, does this bring you back the right solution into AMPL or 
Pyomo?

Stefan


--- a/interfaces/ampl/src/reader_nl.c
+++ b/interfaces/ampl/src/reader_nl.c
@@ -1850,6 +1850,13 @@ SCIP_RETCODE SCIPwriteAmplSolReaderNl(

     /* get best primal solution */
     x = NULL;
+   if( SCIPgetStatus(scip) == SCIP_STATUS_UNKNOWN && SCIPgetNSols(scip) 
 > 0 )
+   {
+      SCIP_CALL( SCIPallocBufferArray(scip, &x, probdata->nvars) );
+      SCIP_CALL( SCIPgetSolVals(scip, 
SCIPgetSols(scip)[SCIPgetNSols(scip)-1], probdata->nvars, 
probdata->vars, x) );
+      msg = "lastsol";
+      solve_result_num = 0;
+   }
     if( SCIPgetBestSol(scip) != NULL )
     {
        SCIP_CALL( SCIPallocBufferArray(scip, &x, probdata->nvars) );


On 2/10/20 12:05 AM, Vladimir V. Voloshinov wrote:
> Dear SCIP developers,
> can you recommend some way to convert solution in CIP format to AMPL
> SOL-file (in the presence of corresponding NL-file in AMPL format)?
> 
> I found that the following trick helps, but may be there is another way?
> Suppose we have: problem.nl, appropriate problem.nl.cip and problem.cip.sol
> (returned, e.g. by FiberSCIP, for problem.nl.cip as an input model).
> 1. Start SCIPAMPL console and load problem.nl as model
> $ scipampl problem.nl -i
> 2. Read problem.cip.sol from SCIPAMPL console (outputs presented below)
> SCIP> read problem.cip.sol
> primal solution from solution file <problem.cip.sol> was accepted as
> candidate, will be checked when solving starts
> 3. Load some limits to stop optimization process just after beginning, e.g.
> SCIP> set limits nodes 2
> 4. Start optimization and wait a few seconds
> SCIP> optimize
> 5. Write AMPL SOL-file
> SCIP> write amplsol
> Now we get problem.sol containing the solution in AMPL format.
> The only drawback is the first string with solver status "node limit
> reached" in problem.sol, but it may be "manually" replaced with "optimal
> solution found" to get correct SOL-file with appropriate status.
> 
> See some additional notes below.
> We use Pyomo Python package to prepare optimization model and write it to
> NL-file (AMPL format). Usually we use SCIPAMPL to read NL-file and to get
> solution as SOL-file (AMPL format), which may be loaded "back" to the model
> by Pyomo tools to analyse  results.
> But for hard problems we need to use ParaSCIP or FiberSCIP. For that we use
> SCIPAMPL console to convert NL-file to CIP-file,
> https://scip.zib.de/doc-6.0.2/html/reader__cip_8h.php, because ParaSCIP and
> FiberSCIP does not accept AMPL-formats. So, we get solutions also in
> CIP-format, but Pyomo does not provide tool to load solutions from CIP.sol !
> Up to now,  for special cases, homebred "readers" have been used, but we
> need more universal approach.
> 
> Sincerely yours,
> Vladimir.
> 
> 
> _______________________________________________
> Scip mailing list
> Scip at zib.de
> https://listserv.zib.de/mailman/listinfo/scip
> 



More information about the Scip mailing list