Constraint Handling Rules is a declarative constraint logic programming language.
Questions tagged [constraint-handling-rules]
19 questions
5
votes
1 answer
Defining CHR constraints at runtime
I'm trying to write a program that generates new constraints at runtime in SWI-Prolog. is_true([A,means,B]) is intended to generate another constraint at runtime:
:- use_module(library(chr)).
:- chr_constraint is_true/1.
is_true([A,means,B]) ==>…

Anderson Green
- 30,230
- 67
- 195
- 328
4
votes
1 answer
How can you count, the amount of backtracks in Prolog SWI or CHR Prolog SWI
I'm creating several puzzle solvers in Prolog SWI with CHR (Constraint Handling Rules)
Everything works great but, I like to test which solver is best one.
Therefore I like to find out, which solver uses the least amount of backtracks.
Is there a…

Dieter
- 2,499
- 1
- 23
- 41
3
votes
3 answers
Solving chain reactions in prolog
One of the recent Advent of code challenges tasks me with solving for the smallest amount of input material that I can use to apply a given set of reactions and get 1 unit of output material.
For example, given
10 ORE => 10 A
1 ORE => 1 B
7 A, 1 B…

D. Ben Knoble
- 4,273
- 1
- 20
- 38
3
votes
2 answers
Constraint Handling Rules in SWI Prolog: Does the "constraint store" exists only for the duration of the toplevel goal processing?
I am taking a closer look at Constraint Handling Rules (CHR) to see if I can understand them (in the sense what's being computed here and how does classical logic and even linear logic fit into this) and possibly apply them.
Thom Frühwirth's book…

David Tonhofer
- 14,559
- 5
- 55
- 51
2
votes
1 answer
Generate decomposition constraints for constraints
Consider the following setup:
:- use_module(library(chr)).
:- chr_constraint
a/1,
b/1.
% really there will be many of these, possibly 100s
% some rules about how to replace as with bs, e.g.,
a(1),a(1) <=> b(2).
% a way to decompose,…

D. Ben Knoble
- 4,273
- 1
- 20
- 38
2
votes
1 answer
Reducing constraints in Prolog
One of the recent Advent of code challenges tasks me with solving for the smallest amount of input material that I can use to apply a given set of reactions and get 1 unit of output material.
For example, given
10 ORE => 10 A
1 ORE => 1 B
7 A, 1 B…

D. Ben Knoble
- 4,273
- 1
- 20
- 38
2
votes
1 answer
CHR solution output in Prolog
I'm running a textbook CHR program in SWI-Prolog.
:- use_module(library(chr)).
:- chr_constraint fib/2.
f0 @ fib(0,M) ==> M=1.
f1 @ fib(1,M) ==> M=1.
fn @ fib(N,M) ==> N>=2 | N1 is N-1, fib(N1,M1), N2 is N-2, fib(N2,M2), M is M1+M2.
All goes fine,…

jack malkovick
- 503
- 2
- 14
2
votes
1 answer
using constraint_handlers in C++
I have a code in C# that uses _set_invalid_parameter_handler function. It's Windows specific and i am trying to rewrite this code in standard C++ so it runs on Linux.
I am not sure how to translate this functionality. I was advised to use maybe…

darkThoughts
- 403
- 6
- 18
1
vote
2 answers
Constraint Handling Rules in SWI Prolog: The `neq` constraint doesn't work
I am learning Constraint Handling Rules (CHR) in swi-prolog.
I started with the tutorial from Tom Schrijvers' Constraint Handling Rules A Tutorial for (Prolog) Programmers.
In p.286, the author gave an example to implement Inequality constraint.
:-…

chansey
- 1,266
- 9
- 20
1
vote
1 answer
Constraint Handling Rules in SWI Prolog: What's the order of puting a constraint to the store?
I am learning Constraint Handling Rules (CHR) in swi-prolog.
I started with the tutorial from Tom Schrijvers' Constraint Handling RulesA Tutorial for (Prolog) Programmers.
The confusion part is that what's the order of putting a constraint to the…

chansey
- 1,266
- 9
- 20
1
vote
1 answer
tau-prolog won't run a prolog code that I use CHR library in although it works on SWI-Prolog
I'm trying to use Tau Prolog to run a CHR code and it gives this error:
throw(error(existence_error(procedure, '/'(color, 1)), '/'(top_level, 0)))
although it works fine on SWI Prolog.
This is the Prolog code:
:- use_module(library(chr)).
:-…

MahmoudLamei
- 11
- 1
- 2
1
vote
0 answers
Is there a way to reorder CHR rules at runtime in prolog?
I am writing a program for an artistic purpose in Prolog with heavy reliance on a large set of CHR rules. I would like to be able to run many times, but produce a different output each time. The easiest way to do this would be to…

lightning
- 389
- 1
- 9
1
vote
0 answers
A General Method To Transpile A Code in Eclipse CLP to CHR
My question is a little general but the answer to my specific question could be very helpful. The general question is "Is there any general method to transfer code in Eclipse CLP prolog to a Constraint Handling Rules (CHR) code?". I know that the…

OmG
- 18,337
- 10
- 57
- 90
1
vote
1 answer
Avoiding infinite recursion with Constraint Handling Rules
I have written a simple set of constraints in SWI-Prolog using Constraint Handling Rules. It uses two relatively simple rules of inference:
%If A means B, then B means A.
means(A,B) ==> means(B,A).
%If A means B and A means C, then B means…

Anderson Green
- 30,230
- 67
- 195
- 328
0
votes
0 answers
Observer in Constraint Handling Rules (Petri Nets example)
I'm learning Constraint Handling Rules (in SWI-Prolog) and trying to (faithfully) program the "Example 5 (Petri Nets - Barber Shop)" from https://www.informatik.uni-ulm.de/pm/fileadmin/pm/home/fruehwirth/rule-based-summer-2013.pdf (page…

hakank
- 6,629
- 1
- 17
- 27