Thread View: comp.programming
3 messages
3 total messages
Started by Julio Di Egidio
Sat, 24 Oct 2026 11:50
Stronger CLP/FD sum consistency? (SWI-Prolog)
Author: Julio Di Egidio
Date: Sat, 24 Oct 2026 11:50
Date: Sat, 24 Oct 2026 11:50
60 lines
2954 bytes
2954 bytes
In SWI-Prolog: Here is a simple scenario where I wish the consistency of CLP/FD sum constraints would propagate more strongly. We have boolean variables A,B,C,D and sum constraints on two subsets of those. It is not difficult to figure out that that is enough to fix variable A, but CLP/FD doesn't see it: ```prolog ?- use_module(library(clpfd)). ?- Vs = [A,B,C,D], Vs ins 0..1, sum([A,C,D], #=, 2), sum([B,C,D], #=, 1). Vs = [A,B,C,D], A in 0..1, A+C+D#=2, B in 0..1, B+C+D#=1, C in 0..1, D in 0..1. ``` On the other hand, I can force it by considering the intersection of the two subsets, and putting a constraint on that intersection that is "mutually consistent" with the other two constraints: ```prolog ?- Vs = [A,B,C,D], Vs ins 0..1, sum([C,D], #=, N), sum([A,N], #=, 2), sum([B,N], #=, 1). Vs = [1,0,C,D], A = N, N = 1, B = 0, C in 0..1, C+D#=1, D in 0..1. ``` But of course a solver's code becomes quite more complicated since, for any new sum constraint on some subset of variables, we'd have to actually constraint all intersections of that subset with any other subset of variables that has already been constrained... or something like that, I am not at the details yet. QUESTION: Is all that work really needed? And, am I just reinventing some wheel, i.e. that can be done easily with the tools already provided? BTW, CLP/B does offer that stronger consistency, i.e. it does solve A in the example, but then CLP/B does not offer a sum constraint proper, card/2 wants a ground cardinality: and I have not figured out how to implement a cardinality constraint for CLP/B myself, though I guess it wouldn't be simpler than the above. Anyway to go beyond just booleans, I am more interested in extending on CLP/FD. -Julio
Re: Stronger CLP/FD sum consistency? (SWI-Prolog)
Author: Julio Di Egidio
Date: Sat, 24 Oct 2026 11:57
Date: Sat, 24 Oct 2026 11:57
13 lines
1665 bytes
1665 bytes
On 24/10/2026 13:50, Julio Di Egidio wrote: > We have boolean variables A,B,C,D and sum constraints on > two subsets of those. It is not difficult to figure out > that that is enough to fix variable A, but CLP/FD doesn't > see it: Sorry, of course I have extracted a minimal example, which actually can fix variables A and B. I hope that doesn't make the post confusing: the problem is the same. -Julio
Re: Stronger CLP/FD sum consistency? (SWI-Prolog)
Author: Julio Di Egidio
Date: Sat, 24 Oct 2026 13:10
Date: Sat, 24 Oct 2026 13:10
13 lines
1629 bytes
1629 bytes
On 24/10/2026 13:50, Julio Di Egidio wrote: [amended] > BTW, CLP/B does offer that stronger consistency, i.e. it > does solve A and B in the example, but then CLP/B does not > offer (that I can see) a sum constraint proper, card/2 is > an expression that wants ground cardinalities: So that e.g. we cannot generically say that two sets have the same cardinality. -Julio
Thread Navigation
This is a paginated view of messages in the thread with full content displayed inline.
Messages are displayed in chronological order, with the original post highlighted in green.
Use pagination controls to navigate through all messages in large threads.
Back to All Threads