Skip to content

plus constraint over unbounded variables panic with message attempt to subtract with overflow #369

Description

@pellico

Pumpkin version 0.3.0

use std::{i32, result, vec};

use pumpkin_solver::conflict_resolvers::resolvers::ResolutionResolver;
use pumpkin_solver::core::results::{ProblemSolution, SatisfactionResult};
use pumpkin_solver::core::termination::Indefinite;
use pumpkin_solver::*;
fn main() {
    let mut solver = Solver::default();

    // We create 3 variables
    let x = solver.new_bounded_integer(i32::MIN, i32::MAX);
    let y = solver.new_bounded_integer(i32::MIN, i32::MAX);
    let z = solver.new_bounded_integer(i32::MIN, i32::MAX);
    let c1 = solver.new_constraint_tag();
    solver.add_constraint(plus(x, y, z, c1)).post().unwrap();

    let mut termination = Indefinite;
    let mut resolver = ResolutionResolver::default();
    let mut brancher = solver.default_brancher();
    let result = solver.satisfy(&mut brancher, &mut termination, &mut resolver);
}

This panic with message:

attempt to subtract with overflow

Activity

  1. EmirDe commented on Mar 17, 2026

    @EmirDe
    Contributor

    Thank you for reporting the issues. We discussed this internally, but I realise now that we have not replied to you.

    At the core of this issue (and the others you posted) is the assumption that the variables will have relatively small domains, so overflows will not occur. This is true for (almost) all MiniZinc Challenge benchmarks. In the past, we did some experiments with other CP solvers, and we also noted that other solvers have this issue as well. Essentially, solvers hope that overflows do not occur, and if they do, that they do not affect the end result. Most silently fail, which is not great. In your case, you seem to have a specific application where having (arbitrarily?) large domains may be relevant.

    We discussed handling this in Pumpkin in a principled way, but we are not sure when we would make this change, since it does require a bit of work to ensure it does not degrade performance for instances that do not need large domains. One of the main issues for us is that we do not have good use cases for such functionality. If we could get some benchmarks/instances where this is needed, that would be much appreciated!

    (See for example this issue: #330)

    Edit: add "when" in the first sentence of the last paragraph.

  2. added theissue type on Mar 17, 2026
  3. added
    bug
    on Mar 17, 2026
  4. pellico commented on Mar 17, 2026

    @pellico
    Author

    Here my use cases:

    • memory allocator -> generate linker script based on constraint of section
      • we need to represent u32 pointer but we can use i32 by adding an offset
    • constraint over register values that control connection between signal in microcontroller.
      • Presently we have solver implement EclipseCLP in this tool and we are evaluating to reimplement using faster framework
    • microcontroller clock configurator
      • due to the lack of floating point the idea is to use i32 fixed point math and we can have quite large number.

    I am interested to know which other solver have evaluate. Does Choco solver have the same ?

  5. AndrewJBrown-MMSD commented on Mar 17, 2026

    @AndrewJBrown-MMSD

    Chiming in with a use case for a larger domain than i32; I'm using the constraint solver to minimize the number of partitioned queries in a larger overall set based on a total number of anticipated rows. The database can easily crack 2.1B rows for queries, but the number to optimize for would not surpass 1T; the constraints are to partition the queries to return chunks no more than CHUNK_LIMIT in size based on 2 dimensions (varname and datetime cutpoint). This is a case where expanding the bounds would be useful because it could handle the larger number while working on a solution, even though CHUNK_LIMIT is decidedly within-bounds (~100,000).

    Obviously an open question whether you want to support the use/intent or if there's some better way to handle the problem but this would certainly make the library accommodate more flexible/general-purpose use with different domains.

  6. EmirDe commented on Mar 24, 2026

    @EmirDe
    Contributor

    Thank you both for your input! It is interesting to hear about these use cases, since we did not have such applications in mind. If you could provide some small benchmarks, we can try out the solver once we implement unbounded integers, which would be helpful. No rush from our side.

    Obviously an open question whether you want to support the use/intent or if there's some better way to handle the problem but this would certainly make the library accommodate more flexible/general-purpose use with different domains.

    Agreed! It seems relevant since it would make the solver more reliable, which is our prime concern. That said, I am not sure when we would do this, but it is relevant. We will think about it in the next period, but we cannot give any estimates at the moment. We would need to see how to incorporate this without slowing down the solver for cases when this is not needed.

    I am interested to know which other solver have evaluate. Does Choco solver have the same ?

    We tried ortools, gecode, and chuffed. We are not sure if Choco supports large integers.

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

    bug

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions