[Scip] How can I read the values of fixed variables in the collected feasible solutions

michael.winkler@zib.de michael.winkler at zib.de
Tue Aug 21 15:15:51 MEST 2012


Hi,

> I am collecting the feasible solutions of a problem using the method
> SCIPgetCountedSparseSolutions(). In this method, the collected feasible
> solutions are stored in SPARSESOLUTION** structure array. However, the
> input arguments for SCIPgetSolVals()contain the solution in the form of
> structure SCIP_Sol*.
>

as you already have noticed using SCIPgetSolVals() needs a SCIP_SOL* as
input argument, but when counting solutions in the end you only have an
array of SPARSESOLUTION*.
These data structures are different and "cannot" be converted into each
other.

The SPARSESOLUTION data structure consist of two SCIP_Real arrays with the
lower bound values and the upper bound values of all the variables which
you get when calling SCIPgetCountedSparseSolutions().

In your case, you wanted to know the values of variables, which were
already fixed(, aggregated, multi-aggregated) in presolving and therefore
not in the variables array returned when calling
SCIPgetCountedSparseSolutions().

Let's assume that you do not have any (multi-)aggregated variables (,
which you could also force by calling

SCIPsetBoolParam(scip, "presolving/donotmultaggr", 1) and
SCIPsetBoolParam(scip, "presolving/donotaggr", 1) before calling

SCIPcount()).

In the above case you can easily run over the fixed variables

>>>> SCIP_VAR** fixedvars;
>>>> fixnum  = SCIPgetNFixedVars(scip);
>>>> fixedvars = SCIPgetFixedVars(scip);

and ask for:

>>> SCIPvarGetLbGlobal(fixedvars[*]) or
>>> SCIPvarGetUbGlobal(fixedvars[*])

because the lower and upper bound should be the same (in feasibility
tolerance) for fixed variables.

For the more general way, if you have aggregated and even multi-aggregated
variables you need to call SCIPgetProbvarLinearSum() (see
http://scip.zib.de/doc/html/scip_8h.shtml#a0509a5028381b92e3e40cde775db7ac9)
for each variable in your 'fixedvars' array.

For all the returned (active) variables you need to check the values in
the SPARSESOLUTION and calculate the values of the (multi-)aggregated
variables yourself.

E.g. You have one fixed variable x1. (Code is not tested)

SCIP_CALL( SCIPallocBufferArray(scip, &repvars, SCIPgetNVars(scip)) );
SCIP_CALL( SCIPallocBufferArray(scip, &scalars, SCIPgetNVars(scip)) );

repvars[0] = x1;
scalars[0] = 1.0;
constant = 0;
nrepvars = 1;

SCIP_CALL( SCIPgetProbvarLinearSum(scip, repvars, scalars, &nrepvars,
SCIPgetNVars(scip), &constant, &requiredsize, TRUE) );

solval = constant;

for( v = 0; v < nrepvars; ++v )
{
   solval += scalars[v] * getSolValSparsesolution(sparsesol,
sparsesolvars, repvars[v]);
}

You need to implement getSolValSparsesolution(). ('sparsesol' is you
SPARSESOLUTION*, and 'sparsesolvars' the corresponding variables.)

The solution value of the fixed variable 'x1' is then 'solval'.


Best, Michael




More information about the Scip mailing list