Skip to content

Custom brancher cannot be implemented because type Assignments is not public. #309

Closed

Description

@pellico

Pumpkin-solver version 0.2.1
I would like to implement my own brancher therefore I need to implement function fn synchronise(&mut self, _assignments: &Assignments) but Assignments is not public.

Activity

  1. maartenflippo commented on Oct 30, 2025

    @maartenflippo
    Contributor

    That seems to be an oversight on our part. I will have a look at this next week with a resolution.

    The reason we keep the Assignments private is that we are continually changing its interface. That would mean breaking compatibility regularly. However, there is a stable core that we could make public. Could you tell us what you would need from Assignments to implement your brancher?

    @ImkoMarijnissen what do you think of this?

  2. pellico commented on Nov 1, 2025

    @pellico
    Author

    I discovered this issue while implementing Brancher trait but actually I don't need to re-implement the sync method and I can rely on the default implementation.
    I just wanted to contribute to the project by notifying this inconsistency.

    However maybe you interested in my use case and why I am implementing Brancher trait.

    Presently I am evaluating the usage of Pumpkin solver for an application at my company:

    • This application has a GUI where the user can decide to fix a parameter and let the other to be decided by the solver.
    • Parameters not fixed by user could have a drop down list with available choices or the possible range is shown.
    • When user change value or remove a fixed value, the GUI need to be updated.

    To solve I use the method satisfy_under_assumptions and I would like to get the ranges of not fixed variables after the assumption instantiation but the before the solution.
    Therefore I encapsulate brancher in a type to intercept the range on first invocation of next_decision

    struct  PropagateBrancher<B:Brancher> {inner:B,limits:Option<HashMap<u32,(i32,i32)>>}
    
    impl <B:Brancher> Brancher for PropagateBrancher<B> {
        delegate! {
            to self.inner {
                 fn subscribe_to_events(&self) -> Vec<BrancherEvent>;
            }
        }
        fn next_decision(&mut self, context: &mut SelectionContext) -> Option<Predicate> {
            if self.limits.is_none() {
                let mut limits:HashMap<u32,(i32,i32)> = HashMap::new();
                for d_id in context.get_domains() {
                    let upper= context.upper_bound(d_id);
                    let lower = context.lower_bound(d_id);
                    limits.insert(d_id.id(), (lower,upper));
                }
                self.limits=Some(limits);
            }
            self.inner.next_decision(context)
        }
    }
    
    impl <B:Brancher> PropagateBrancher<B> {
        pub fn new(brancher:B)-> Self {
            Self{inner:brancher,limits:None}
        }
    } 

    In my experience this use case is quite common and maybe you are interested to support in easier way.

    I would suggest to support also more generic constraint as assumption.
    Other solver as ECLiPSe or Choco4 has the capability to post temporary a constraint and then remove it.

  3. maartenflippo commented on Nov 3, 2025

    @maartenflippo
    Contributor

    I discovered this issue while implementing Brancher trait but actually I don't need to re-implement the sync method and I can rely on the default implementation.
    I just wanted to contribute to the project by notifying this inconsistency.

    Alright, that is good to know. Thank you for the notification. I hope to push a fix this week.

    To solve I use the method satisfy_under_assumptions and I would like to get the ranges of not fixed variables after the assumption instantiation but the before the solution.

    That is an interesting use case, and indeed, there is no convenient way to get that information. It is interesting for us to figure out what a good API for this would be.

    I would suggest to support also more generic constraint as assumption.

    That is a good suggestion, which we may look into in the future. Although we currently do not have a direct use-case for it, so I am not sure when we will find the time to implement that feature.

  4. added a commit that references this issue on Nov 10, 2025
    9548114
  5. maartenflippo commented on Nov 11, 2025

    @maartenflippo
    Contributor

    This is fixed in the latest release of pumpkin

  6. EmirDe commented on Nov 11, 2025

    @EmirDe
    Contributor

    Question about the use case @pellico. You have a set of assumptions A, and you would like to get information about the domains of all/some variables after assumptions A have been posted by the solver (including propagation), just before the solver would start solving the problem? Did I understand this correctly?

    About posting constraints temporarily. We can simulate this by creating a new Boolean B and posting a half-reified constraint "B -> constraint", and then one can solve under assumptions to enable/disable constraints. But we have not used this extensively so far.

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