简体   繁体   中英

SCIP: How to set an initial guess when solving a MILP problem

Due to poor documentation of the SCIP library, I do not understand the sequence of SCIP methods which allows to set an initial guess.

I have a problem of n variables (integer and continuous) and constraints. I would like to do the following. At first, to solve the problem and obtain its solution. Then an additional variable and some related constraints are introduced into the problem. The obtained solution is used as the initial guess (a partial one) of the new problem of n+1 variables and constraints.

According to my ideas, it is implemented as follows:

SCIPsolve(scipeEnv); // solving the problem of n variables
SCIP_Sol *sol = SCIPgetBestSol(scipEnv); // obtaining the solution
SCIP_Sol *copiedSol = nullptr; // a copy of the obtained solution
SCIPcreateSolCopy(scipEnv, copiedSol, sol); // copying the obtained solution

// [1] Does the copied solution has a link with the problem and has to be unlink
// when the problem is transformed to the original state?
// [2] Whether the copying is required?

SCIPfreeTransform(scip); // transforming the problem to the original state

// *** add a new variable and related constraints into the problem ***

SCIPcreatePartialSol(scip, &copiedSol, nullptr);

// [3] Is it true that creating an initial guess works in terms of solution objects,
// that is: obtaining the optimal solution -> coping it -> creating a partial one on the basis
// of the copied solution?
// Or one should extract the solution values from the optimal solution to temporal double variables
// and then create a partial solution and transfer the obtained values? 

SCIP_Bool stored;
SCIPaddSolFree(scipEnv, &copiedSol, &stored);

Thank you for your answers.

You have some things wrong in your code. You need to retransform to the original space (as I wrote in the other thread), you need to pass a SCIP_SOL** to SCIPcreateSolCopy (surprised if your code is even compiling) and calling SCIPcreatePartialSol will overwrite your copiedSol (and create memory corruption).

It should be more like this

SCIPsolve(scipeEnv); // solving the problem of n variables
SCIP_SOL *sol = SCIPgetBestSol(scipEnv); // obtaining the solution
SCIP_SOL *copiedSol = nullptr; // a copy of the obtained solution
SCIP_CALL( SCIPcreateSolCopy(scipEnv, &copiedSol, sol) ); // copying the obtained solution

SCIP_CALL( SCIPretransformSol(scip, copiedSol) );

// [1] Does the copied solution has a link with the problem and has to be unlink -> no happens when you retransform
// [2] Whether the copying is required? -> yes

SCIPfreeTransform(scip); // transforming the problem to the original state

// *** add a new variable and related constraints into the problem ***

SCIP_SOL* newsol;

SCIPcreatePartialSol(scip, &newsol, nullptr);

// Or one should extract the solution values from the optimal solution to temporal double variables -> yes, this is the way 

/// missing: iterate through variables, get their solution values from copiedSol and set them for newsol

SCIP_Bool stored;
SCIPaddSolFree(scipEnv, &copiedSol, &stored);

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM