Skip to content

addConsCumulative and AddConsCumulativeOpt? #1222

Closed

Description

@tias

I just learned at CPAIOR that SCIP has a cumulative (and disjunctive/no-overlap?) constraint.

Indeed, I can find 'cons_cumulative.c' on: https://www.scipopt.org/doc/html/group__DEFPLUGINS__CONS.php
and I can even find a 'cons_optcumulative.c' on: https://www.scipopt.org/doc/html/group__CONSHDLRS.php
(the difference between the two doc files escapes me)

I do not immediately see a Disjunctive/NoOverlap constraint (but I am well aware we can use Cumulative for that).

We would love to interface to these constraint handlers from our CPMpy library. Would it be possible to add them to PySCIPOpt? Or is there a reason not to?

We could help out if you think its a good idea to add it, and you have some pointers of where to start.

Kind regards,
Tias

Activity

  1. Joao-Dionisio commented on May 27, 2026

    @Joao-Dionisio
    Member

    Hey @tias , thank for the issue! Always happy when SCIP/PySCIPOpt comes up in the wild 😁

    PySCIPOpt's initial focus was more on modeling (and some plugin work as well), but we've seen people interested in more advanced use cases. SCIP internally upgrades constraints into more specialized constraints (like cumulative constraints), but advanced users still want more control (for example #941 with knapsack constraints).

    For this reason, in #977 I'm tracking the constraints that have/have not yet been ported into PySCIPOpt, and indeed cumulative constraints are there, there hasn't been much progress. But the process of adding a new constraint handler is simple, once it's done the first time, it's very mechanical. So, here are the steps:

    1 - Edit scip.pxd with the SCIP methods you want PySCIPOpt to call. For example, SCIPcreateConsCumulative():

    cdef extern from "scip/cons_cumulative.h":
        SCIP_RETCODE SCIPcreateConsCumulative(SCIP* scip,
                                             SCIP_CONS** cons,
                                             etc etc)

    2 - Edit scip.pxi with the interface to these methods. Something like (simplified):

    def addConsCumulative(args):
        cdef SCIP_CONS* scip_cons
        ...
        PY_SCIP_CALL(SCIPcreateConsCumulative(self.scip, &scip_cons, args))
        PY_SCIP_CALL(SCIPaddCons(self._scip, scip_cons))
        pyCons = self._getOrCreateCons(scip_cons)
        return pyCons

    3 - Add and interface any other related methods you think are sensible (maybe SCIPgetVarsCumulative(), I don't know)
    4 - Add the stubs to scip.pyi for type hints. For now, something like:

        def addConsCumulative(
            self,
            vars: Incomplete,
            resvar: Incomplete,
            name: Incomplete = ...,
            initial: Incomplete = ...,
            separate: Incomplete = ...,
            enforce: Incomplete = ...,
            check: Incomplete = ...,
            propagate: Incomplete = ...,
            local: Incomplete = ...,
            modifiable: Incomplete = ...,
            dynamic: Incomplete = ...,
            removable: Incomplete = ...,
            stickingatnode: Incomplete = ...,
        ) -> Incomplete: ...

    5 - Add a test that calls the added PySCIPOpt methods to the appropriate test file (or create a new one, if you think it makes sense).
    6 - Add a CHANGELOG entry.
    7 - Create an MR

    And that's it! A couple details are ommited from steps 2 and 3, but it's just about copying addConsAnd(), I believe. What do you think?

  2. Joao-Dionisio commented on Jun 5, 2026

    @Joao-Dionisio
    Member

    Solved via #1223

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions