From: Joachim Schimpf <joachim.schimpf_at_...44...>

Date: Fri, 12 Feb 2010 15:36:14 +1100

Date: Fri, 12 Feb 2010 15:36:14 +1100

Andreas Berger wrote: > Thank you! The constraint prototype for integer is exactly what I was > looking for. I was afraid you would say that. The reason I offered this as the last of 3 alternatives is that this is not a constraint that is very suited to the way the ic solver represents integer variables. If you have just a few of these constraints, and the majority of constraints are the usual arithmetic or global constraints over integer variables, this is probably ok. But if your problem consists mostly of this kind of constraint, you should seriously consider the other possibilities. -- Joachim > > Andreas > > > Am 11.02.2010 02:44, schrieb Joachim Schimpf: >> Andreas Berger wrote: >> ... >> >>> I want to express a Constraint of the Form: >>> >>> "Give me a Number X, which is bitwise connected (C++ '&' ) with a second >>> Number A is 0. >>> >>> Something like: A /\ X = 0, give me a possible X when A = 9. >>> >>> I can't find an appropiate predicate for such kind of problem. I tried >>> the following construct: >>> 9 /\ X #= 0, but of course it does not work. >>> >>> Can someone give me a hint to solve this problem please. >>> >> First, you should consider whether it is not better to use boolean (0/1) >> variables for the individual bits. Your constraints may then be easier >> to express. For example, if you represent your numbers as lists of >> boolean digits, you can define >> >> bool_bitand(X, Y, Z) :- >> ( foreach(Xi,X), foreach(Yi,Y), foreach(Zi,Z) do >> [Xi,Yi,Zi]::0..1, >> Zi #= (Xi and Yi) >> ). >> >> and express your example as >> >> ?- bool_bitand(X, [1, 0, 0, 1], [0, 0, 0, 0]). >> X = [0, _368{[0, 1]}, _457{[0, 1]}, 0] >> Yes (0.00s cpu) >> >> >> Second, if your bit vectors represent sets, you could also consider >> using the ic_set solver's set-variables to represent them. >> >> >> Third, with your original representation, you could prototype such >> a constraint as follows: >> >> :- lib(propia). >> >> int_bitand(X, Y, Z) :- ( labeling([X,Y,Z]), X/\Y =:= Z ) infers ic. >> >> which solves your example in this way: >> >> ?- X :: 0 .. 9, int_bitand(X, 9, 0). >> X = X{[0, 2, 4, 6]} >> Yes (0.00s cpu) >> >> >> -- Joachim >> >Received on Fri Feb 12 2010 - 04:35:19 CET

*
This archive was generated by hypermail 2.2.0
: Mon Jul 09 2018 - 02:05:29 CEST
*