[SCIP] SCIP deleting constraints during solving process

Pierre Montalbano pierre.montalbano at univ-tours.fr
Fri Nov 14 18:26:04 CET 2025


Dear SCIP users,

I am trying to design a new mechanism in SCIP, and for this I need to modify the objective function at each node of the search tree.
I disabled heuristics, separation, propagation and presolve. I also do a DFS. 

As far as I know, it is not possible to change the objective function during the solving process. Therefore, I model the objective as a constraint (i.e., myobj <= z with z minimized). I would like to replace this “objective constraint” at each node before the LP is solved. Currently, I attempt to do this inside a node-focused callback.

Adding a constraint with SCIPaddConsNode works. However, SCIPdelConsLocal removes the constraint only from the transformed problem (it no longer appears in SCIPwriteTransProblem), but not from the LP rows. Thus, the LP solution is incorrect. 
I also tested adding a row directly via SCIPaddRow, but it seems the row is inserted only after the LP is solved.

I suspect that modifying the objective-constraint during an LP-solved event (instead of node-focused) will not behave correctly when backtracking. 

Is there a more appropriate or efficient way to modify a constraint or emulate objective changes during solving in SCIP?

Here is part of my code where I delete/add objective constraint. 


// ----NODEFOCUSED event handler ----
static
SCIP_DECL_EVENTEXEC(eventExecNodeFocused)
{
...

	SCIP_CALL( SCIPdelConsLocal(scip, oldobjcons));

        SCIP_Real* coefs = nullptr;
        SCIP_VAR** consvars = nullptr;
        SCIP_CONS* newobj = nullptr;
        
        SCIP_CALL( SCIPallocBufferArray(scip, &coefs, nvars) );
        SCIP_CALL( SCIPallocBufferArray(scip, &consvars, nvars) );
        for (int k = 0; k < nvars; ++k)
        {
            consvars[k] = vars[k];
            coefs[k] = redcosts[k];
        }

        char sname[256];
        
        snprintf(sname, sizeof(sname), "obj_%d", nodeNumber);
        SCIP_CALL( SCIPcreateConsBasicLinear(scip, &newobj,
            sname,    
            nvars,               
            consvars,          
            coefs,             
            -SCIPinfinity(scip),               
            0) );           
        
        
        SCIP_CALL( SCIPaddConsNode(scip,node, newobj,nullptr) );

        SCIP_CALL( SCIPreleaseCons(scip, &newobj) );

…
}


Thank you very much for your help, and I wish you a nice weekend.

Best regards,

Montalbano Pierre



More information about the Scip mailing list