[SCIP] SCIP deleting constraints during solving process
Marc Pfetsch
pfetsch at mathematik.tu-darmstadt.de
Mon Nov 17 16:55:51 CET 2025
Dear Pierre,
I do not think that there is a direct way of changing the objective,
since this removes the power of the bounding step of branch-and-bound
(one cannot cut off nodes by objective value anymore).
The row is indeed still in the LP, because it would invalidate all basis
information, if you remove it without being redundant. I think it would
require major effort to change this within SCIP.
Some things that you might think about:
Is it possible to formulate your setting as a constraint for which you
can implement propagation or separation? Maybe the change of the
objective is only one way of achieving what you want to do?
Best
Marc
On 14/11/2025 18:26, Pierre Montalbano wrote:
> 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
>
> _______________________________________________
> Scip mailing list
> Scip at zib.de
> https://listserv.zib.de/mailman/listinfo/scip
More information about the Scip
mailing list