[Scip] Collecting feasible solutions in SCIP
Stefan Heinz
heinz at zib.de
Sat May 26 10:39:16 MEST 2012
Hi,
first check the following page:
http://scip.zib.de/doc/html/COUNTER.html
On 05/25/2012 06:24 PM, sheetal murkute wrote:
> Hello,
>
> I want to collect all the feasible solutions for MIP in SCIP. I want to
> store these solution values (for the original
> variables) either in file or in some class so that I can access these later.
In case of the counting feature the solutions are stored w.r.t. the
transformed problem only. That means, you have to use SCIP functions to
convert these solutions into the original space. This functionality is
implemented by the "write/allsolutions" dialog
http://scip.zib.de/doc/html_devel/cons__countsols_8c.html#a1c3b0e8f05febeac36ad6f77ce45bf66
you can copy the corresponding code or use in the interactive shell that
dialog.
> I have written the code as follows. However, I do not know how to store all
> these solutions to a file or
> in my own array/class. Also when I display *nsols ( total number of counted
> solutions), it displays "0".
>
> ************************************************************************************************************************
> SCIP_CALL_EXC(SCIPsolve(scip));
>
> SCIP_Bool valid;
> int a, b;
> SPARSESOLUTION ** feassols;
> SCIP_VAR** curvars;
> int* nsols;
> int* nvars;
>
> assert( scip != NULL );
> a = SCIPgetNVars(scip);
> nvars =&a;
> curvars = SCIPgetVars(scip);
> valid = FALSE;
> b = SCIPgetNCountedSols(scip,&valid);
> nsols =&b;
>
> //SCIP_CALL( SCIPsetLongintParam( scip, "constraints/countsols/sollimit",
> 1000) );
> SCIP_CALL( SCIPsetBoolParam( scip, "constraints/countsols/collect", TRUE) );
>
> SCIPgetCountedSparseSolutions(scip,&curvars, nvars,&feassols,nsols);
> cout<< "total nuber of feasible solutions :"<< *nsols<< endl;
First you set up your problem as usual and set the parameter:
SCIP_CALL( SCIPsetBoolParam( scip, "constraints/countsols/collect", TRUE) );
Second you call SCIPcount() instead of SCIPsolve().
http://scip.zib.de/doc/html/cons__countsols_8h.html#aef183d6883f1917bffb15159f7b856fd
After that you use the method SCIPgetCountedSparseSolutions() the get
all sparse solution
http://scip.zib.de/doc/html/cons__countsols_8h.html#acbf587cc73efb9556f2ea7deba3dad37
Having these you can use the code of the "write/allsolutions" dialog
http://scip.zib.de/doc/html_devel/cons__countsols_8c.html#a1c3b0e8f05febeac36ad6f77ce45bf66
the get the sparse solutions unrolled and transformed into the original
space.
> *****************************************************************************************************************************************
>
> Are the feasible solutions stored in SPARSESOLUTION ** feassols ?
> I tried to display solutions as
> SPARSESOLUTION * feas;
> feas = *feassols;
>
> for(i=0; i<= nvars; ++i)
> cout<< feas[i];
> However, this gives segmentation fault.
>
> ************************************************************************************************************************************
Note that SPARSESOUTION is a struct with two SCIP_Longint arrays which
you can access directly (which is actually not the way it should).
http://scip.zib.de/doc/html/cons__countsols_8h_source.html#l00043
Best Stefan
>
> Could you please help me with this?
>
>
>
>
> _______________________________________________
> Scip mailing list
> Scip at zib.de
> http://listserv.zib.de/mailman/listinfo/scip
More information about the Scip
mailing list