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

Stefan Vigerske svigerske at gams.com
Tue Mar 24 19:01:13 CET 2020


Hi,

can you also change the line
   if( SCIPgetBestSol(scip) != NULL )
in SCIPwriteAmplSolReaderNl() to
   else if( SCIPgetBestSol(scip) != NULL )

First the .nl file check/instances/MINLP/ex1266.nl is read, which puts 
the initial solution to position 0 in the solutions array.
Then "read ex1266.cip.sol" reads another solution and adds this to 
position 1 in the array.
So the following "write amplsol" should look at the last position in the 
sols array.
But it shouldn't overwrite x with SCIPgetBestSol(scip) afterwards, due 
to the missing else.

Stefan



On 3/22/20 12:00 AM, Vladimir V. Voloshinov wrote:
> Hello, Stefan.
> My colleague, Sergey Smirnov, had applied your patch to the latest SCIP
> release 6.0.2 and we tested some problems to check it.
> In a few words - patched SCIPAMPL does not return right solution as
> SOL-file.
> 
> After a number of tests I can suggest the following:
> if NL-file contains initial values of the problem's variables then the
> SOL-file returned contains these initial values, rather than optimal
> solution;
> else - values of all variables in SOL-file are equal to zero.
> 
> It seems that it is so even for the test problem you mentioned
> [scipoptsuite-6.0.2/scip/interfaces/ampl/check/instances/MINLP/ex1266.nl].
> See in attachment:
> [ex1266.nl] the NL-file we have;
> [ex1266.cip.sol] CIP-solution returned by SCIP from ex1266.cip "created
> from"  ex1266.nl (it has initial values, see line #317 and below ;
> [ex1266.sol] SOL-file returned by patched SCIPAMPL after "normal"
> optimization;
> [ex1266.cip.2.sol] SOL-file returned by patched SCIPAMPL as a result of the
> "trick" you suggested (it .
> 
> 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] ?
> The implementation of the function SCIPgetBestSol
> <https://scip.zib.de/doc-6.0.2/html/scip__sol_8c_source.php#l02254> returns
> scip->primal->sols[0] (line #2337), i.e. THE FIRST element of "sols" array,
> not THE LAST!
> 
> Best regards,
> Vladimir.
> 
> On Mon, Feb 10, 2020 at 3:01 PM Stefan Vigerske <svigerske at gams.com> wrote:
> 
>> 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
>>>
>>
>> _______________________________________________
>> Scip mailing list
>> Scip at zib.de
>> https://listserv.zib.de/mailman/listinfo/scip
>>
> 



More information about the Scip mailing list