1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 332 333 334 335 336 337 338 339
|
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0 Transitional//EN"
"http://www.w3.org/TR/REC-html40/loose.dtd">
<HTML>
<HEAD>
<META http-equiv="Content-Type" content="text/html; charset=ISO-8859-1">
<META name="GENERATOR" content="hevea 1.08">
<LINK rel="stylesheet" type="text/css" href="gprolog.css">
<TITLE>
Boolean and reified constraints
</TITLE>
</HEAD>
<BODY TEXT=black BGCOLOR=white>
<A HREF="gprolog060.html"><IMG SRC ="previous_motif.gif" ALT="Previous"></A>
<A HREF="gprolog054.html"><IMG SRC ="contents_motif.gif" ALT="Up"></A>
<A HREF="gprolog062.html"><IMG SRC ="next_motif.gif" ALT="Next"></A>
<HR>
<H3 CLASS="subsection"><A NAME="htoc326">8.7</A> Boolean and reified constraints</H3><UL>
<LI><A HREF="gprolog061.html#toc267">Boolean FD expressions</A>
<LI><A HREF="gprolog061.html#toc268"><TT>(#\)/1</TT> - constraint NOT,
<TT>(#<=>)/2</TT> - constraint equivalent,<BR>
<TT>(#\<=>)/2</TT> - constraint different,
<TT>(##)/2</TT> - constraint XOR,<BR>
<TT>(#==>)/2</TT> - constraint imply,
<TT>(#\==>)/2</TT> - constraint not imply,<BR>
<TT>(#/\)/2</TT> - constraint AND,
<TT>(#\/\)/2</TT> - constraint NAND,<BR>
<TT>(#\/)/2</TT> - constraint OR,
<TT>(#\\/)/2</TT> - constraint NOR</A>
<LI><A HREF="gprolog061.html#toc269"><TT>fd_cardinality/2</TT>,
<TT>fd_cardinality/3</TT>,
<TT>fd_at_least_one/1</TT>,
<TT>fd_at_most_one/1</TT>,<BR>
<TT>fd_only_one/1</TT></A>
</UL>
<A NAME="Boolean-and-reified-constraints"></A>
<A NAME="toc267"></A>
<H4 CLASS="subsubsection"><A NAME="htoc327">8.7.1</A> Boolean FD expressions</H4>
<A NAME="Boolean-FD-expressions"></A>
An boolean FD expression is a Prolog term built from integers (0 for false,
1 for true), variables (Prolog or FD variables), partial AC arithmetic
constraints (section <A HREF="gprolog060.html#Partial-AC:-(:=)/2">8.6.2</A>), full AC arithmetic constraints
(section <A HREF="gprolog060.html#Full-AC:-(:=:)/2">8.6.3</A>) and functors (or operators) that represent
boolean functions. When a sub-expression of a boolean expression is an
arithmetic constraint <I><TT>c</TT></I>, it is reified. Namely, as soon as the
solver detects that <I><TT>c</TT></I> is true (i.e. <EM>entailed</EM>) the
sub-expression has the value <TT>1</TT>. Similarly when the solver detects
that <I><TT>c</TT></I> is false (i.e. <EM>disentailed</EM>) the sub-expression
evaluates as <TT>0</TT>. While neither the entailment nor the disentailment
can be detected the sub-expression is evaluated as a domain <TT>0..1</TT>.
The following table details the components of an FD boolean expression:<BR>
<TABLE BORDER=1 CELLSPACING=0 CELLPADDING=1>
<TR><TD ALIGN=left NOWRAP>FD Expression</TD>
<TD ALIGN=left NOWRAP>Result</TD>
</TR>
<TR><TD ALIGN=left NOWRAP>Prolog variable</TD>
<TD ALIGN=left NOWRAP>domain <TT>0..1</TT></TD>
</TR>
<TR><TD ALIGN=left NOWRAP>FD variable <TT>X</TT></TD>
<TD ALIGN=left NOWRAP>domain of <TT>X</TT>, <TT>X</TT> is constrained to
be in <TT>0..1</TT></TD>
</TR>
<TR><TD ALIGN=left NOWRAP><TT>0</TT> (integer)</TD>
<TD ALIGN=left NOWRAP><TT>0</TT> (false)</TD>
</TR>
<TR><TD ALIGN=left NOWRAP><TT>1</TT> (integer)</TD>
<TD ALIGN=left NOWRAP><TT>1</TT> (true)</TD>
</TR>
<TR><TD ALIGN=left NOWRAP><TT>#\ E</TT></TD>
<TD ALIGN=left NOWRAP>not <TT>E</TT></TD>
</TR>
<TR><TD ALIGN=left NOWRAP><TT>E1 #<=> E2</TT></TD>
<TD ALIGN=left NOWRAP><TT>E1</TT> equivalent to <TT>E2</TT></TD>
</TR>
<TR><TD ALIGN=left NOWRAP><TT>E1 #\<=> E2</TT></TD>
<TD ALIGN=left NOWRAP><TT>E1</TT> not equivalent to
<TT>E2</TT> (i.e. <TT>E1</TT> different from <TT>E2)</TT></TD>
</TR>
<TR><TD ALIGN=left NOWRAP><TT>E1 ## E2</TT></TD>
<TD ALIGN=left NOWRAP><TT>E1</TT> exclusive OR <TT>E2</TT> (i.e. <TT>E1</TT>
not equivalent to <TT>E2)</TT></TD>
</TR>
<TR><TD ALIGN=left NOWRAP><TT>E1 #==> E2</TT></TD>
<TD ALIGN=left NOWRAP><TT>E1</TT> implies <TT>E2</TT></TD>
</TR>
<TR><TD ALIGN=left NOWRAP><TT>E1 #\==> E2</TT></TD>
<TD ALIGN=left NOWRAP><TT>E1</TT> does not imply <TT>E2</TT></TD>
</TR>
<TR><TD ALIGN=left NOWRAP><TT>E1 #/\ E2</TT></TD>
<TD ALIGN=left NOWRAP><TT>E1</TT> AND <TT>E2</TT></TD>
</TR>
<TR><TD ALIGN=left NOWRAP><TT>E1 #\/\ E2</TT></TD>
<TD ALIGN=left NOWRAP><TT>E1</TT> NAND <TT>E2</TT></TD>
</TR>
<TR><TD ALIGN=left NOWRAP><TT>E1 #\/ E2</TT></TD>
<TD ALIGN=left NOWRAP><TT>E1</TT> OR <TT>E2</TT></TD>
</TR>
<TR><TD ALIGN=left NOWRAP><TT>E1 #\\/ E2</TT></TD>
<TD ALIGN=left NOWRAP><TT>E1</TT> NOR <TT>E2</TT></TD>
</TR></TABLE><BR>
<TT>#<=></TT>, <TT>#\<=></TT>, <TT>##</TT>,
<TT>#==></TT>, <TT>#\==></TT>, <TT>#/\</TT>,
<TT>#\/\</TT>, <TT>#\/</TT> and <TT>#\\/</TT> are
predefined infix operators. <TT>#\</TT> is a predefined prefix operator
(section <A HREF="gprolog037.html#op/3:(Term-input/output)">7.14.10</A>).<BR>
<BR>
<B>Errors</B><BR>
<TABLE CELLSPACING=2 CELLPADDING=0>
<TR><TD BGCOLOR=black COLSPAN=3><TABLE BORDER=0 WIDTH="100%" CELLSPACING=0 CELLPADDING=1><TR><TD></TD></TR></TABLE></TD>
</TR>
<TR><TD VALIGN=top ALIGN=left>a sub-expression <TT>E</TT> is neither a variable nor an integer (0
or 1) nor an FD boolean functor nor reified constraint</TD>
<TD VALIGN=top ALIGN=center NOWRAP> </TD>
<TD VALIGN=top ALIGN=left><TT>type_error(fd_bool_evaluable, E)</TT></TD>
</TR>
<TR><TD BGCOLOR=black COLSPAN=3><TABLE BORDER=0 WIDTH="100%" CELLSPACING=0 CELLPADDING=1><TR><TD></TD></TR></TABLE></TD>
</TR>
<TR><TD VALIGN=top ALIGN=left>an expression is too complex</TD>
<TD VALIGN=top ALIGN=center NOWRAP> </TD>
<TD VALIGN=top ALIGN=left><TT>resource_error(too_big_fd_constraint)</TT></TD>
</TR>
<TR><TD BGCOLOR=black COLSPAN=3><TABLE BORDER=0 WIDTH="100%" CELLSPACING=0 CELLPADDING=1><TR><TD></TD></TR></TABLE></TD>
</TR>
<TR><TD VALIGN=top ALIGN=left>a sub-expression is an invalid reified constraint</TD>
<TD VALIGN=top ALIGN=center NOWRAP> </TD>
<TD VALIGN=top ALIGN=left>an arithmetic constraint error (section <A HREF="gprolog060.html#FD-arithmetic-expressions">8.6.1</A>)</TD>
</TR>
<TR><TD BGCOLOR=black COLSPAN=3><TABLE BORDER=0 WIDTH="100%" CELLSPACING=0 CELLPADDING=1><TR><TD></TD></TR></TABLE></TD>
</TR></TABLE><BR>
<A NAME="toc268"></A>
<H4 CLASS="subsubsection"><A NAME="htoc328">8.7.2</A> <TT>(#\)/1</TT> - constraint NOT,
<TT>(#<=>)/2</TT> - constraint equivalent,<BR>
<TT>(#\<=>)/2</TT> - constraint different,
<TT>(##)/2</TT> - constraint XOR,<BR>
<TT>(#==>)/2</TT> - constraint imply,
<TT>(#\==>)/2</TT> - constraint not imply,<BR>
<TT>(#/\)/2</TT> - constraint AND,
<TT>(#\/\)/2</TT> - constraint NAND,<BR>
<TT>(#\/)/2</TT> - constraint OR,
<TT>(#\\/)/2</TT> - constraint NOR</H4>
<B>Templates</B>
<DL CLASS="list" COMPACT="compact"><DT CLASS="dt-list"><DD CLASS="dd-list"><TT>
#\(?fd_bool_evaluable)<BR>
#<=>(?fd_bool_evaluable, ?fd_bool_evaluable)<BR>
#\<=>(?fd_bool_evaluable, ?fd_bool_evaluable)<BR>
##(?fd_bool_evaluable, ?fd_bool_evaluable)<BR>
#==>(?fd_bool_evaluable, ?fd_bool_evaluable)<BR>
#\==>(?fd_bool_evaluable, ?fd_bool_evaluable)<BR>
#/\(?fd_bool_evaluable, ?fd_bool_evaluable)<BR>
#\/\(?fd_bool_evaluable, ?fd_bool_evaluable)<BR>
#\/(?fd_bool_evaluable, ?fd_bool_evaluable)<BR>
#\\/(?fd_bool_evaluable, ?fd_bool_evaluable)</TT></DL>
<B>Description</B><BR>
<BR>
<TT>#\= FdBoolExpr1</TT> constraints <TT>FdBoolExpr1</TT> to be
false.<BR>
<BR>
<TT>FdBoolExpr1 #<=> FdBoolExpr2</TT> constrains
<TT>FdBoolExpr1</TT> to be equivalent to <TT>FdBoolExpr2</TT>.<BR>
<BR>
<TT>FdBoolExpr1 #\<=> FdBoolExpr2</TT> constrains
<TT>FdBoolExpr1</TT> to be equivalent to not <TT>FdBoolExpr2</TT>.<BR>
<BR>
<TT>FdBoolExpr1 ## FdBoolExpr2</TT> constrains <TT>FdBoolExpr1</TT> XOR
<TT>FdBoolExpr2</TT> to be true<BR>
<BR>
<TT>FdBoolExpr1 #==> FdBoolExpr2</TT> constrains
<TT>FdBoolExpr1</TT> to imply <TT>FdBoolExpr2</TT>.<BR>
<BR>
<TT>FdBoolExpr1 #\==> FdBoolExpr2</TT> constrains
<TT>FdBoolExpr1</TT> to not imply <TT>FdBoolExpr2</TT>.<BR>
<BR>
<TT>FdBoolExpr1 #/\ FdBoolExpr2</TT> constrains <TT>FdBoolExpr1</TT>
AND <TT>FdBoolExpr2</TT> to be true.<BR>
<BR>
<TT>FdBoolExpr1 #\/\ FdBoolExpr2</TT> constrains
<TT>FdBoolExpr1</TT> AND <TT>FdBoolExpr2</TT> to be false.<BR>
<BR>
<TT>FdBoolExpr1 #\/ FdBoolExpr2</TT> constrains <TT>FdBoolExpr1</TT>
OR <TT>FdBoolExpr2</TT> to be true.<BR>
<BR>
<TT>FdBoolExpr1 #\\/ FdBoolExpr2</TT> constrains
<TT>FdBoolExpr1</TT> OR <TT>FdBoolExpr2</TT> to be false.<BR>
<BR>
<TT>FdBoolExpr1</TT> and <TT>FdBoolExpr2</TT> are boolean FD expressions
(section <A HREF="#Boolean-FD-expressions">8.7.1</A>).<BR>
<BR>
Note that <TT>#\<=></TT> (not equivalent) and <TT>##</TT>
(exclusive or) are synonymous.<BR>
<BR>
These predicates post boolean constraints that are managed by the FD solver
using a partial arc-consistency algorithm to reduce the domain of involved
variables. The (dis)entailment of reified constraints is detected using
either the bounds (for partial AC arithmetic constraints) or the full domain
(for full AC arithmetic constraints).<BR>
<BR>
<TT>#<=></TT>, <TT>#\<=></TT>, <TT>##</TT>,
<TT>#==></TT>, <TT>#\==></TT>, <TT>#/\</TT>,
<TT>#\/\</TT>, <TT>#\/</TT> and <TT>#\\/</TT> are
predefined infix operators. <TT>#\</TT> is a predefined prefix operator
(section <A HREF="gprolog037.html#op/3:(Term-input/output)">7.14.10</A>).<BR>
<BR>
<B>Errors</B><BR>
<BR>
Refer to the syntax of boolean FD expressions for possible errors
(section <A HREF="#Boolean-FD-expressions">8.7.1</A>).<BR>
<BR>
<B>Portability</B><BR>
<BR>
GNU Prolog predicates.<BR>
<BR>
<A NAME="toc269"></A>
<H4 CLASS="subsubsection"><A NAME="htoc329">8.7.3</A> <TT>fd_cardinality/2</TT>,
<TT>fd_cardinality/3</TT>,
<TT>fd_at_least_one/1</TT>,
<TT>fd_at_most_one/1</TT>,<BR>
<TT>fd_only_one/1</TT></H4>
<A NAME="fd-cardinality/2"></A>
<B>Templates</B>
<DL CLASS="list" COMPACT="compact"><DT CLASS="dt-list"><DD CLASS="dd-list"><TT>
fd_cardinality(+fd_bool_evaluable_list, ?fd_variable)<BR>
fd_cardinality(+integer, ?fd_variable, +integer)<BR>
fd_at_least_one(+fd_bool_evaluable_list)<BR>
fd_at_most_one(+fd_bool_evaluable_list)<BR>
fd_only_one(+fd_bool_evaluable_list)</TT></DL>
<B>Description</B><BR>
<BR>
<TT>fd_cardinality(List, Count)</TT> unifies <TT>Count</TT> with the number
of constraints that are true in <TT>List</TT>. This is equivalent to post
the constraint <TT>B<SUB>1</SUB> + B<SUB>2</SUB> + ...+ B<SUB><I>n</I></SUB> #= Count</TT>
where each variable <TT>Bi</TT> is a new variable defined by the constraint
<TT>B<SUB><I>i</I></SUB> #<=> C<SUB><I>i</I></SUB></TT> where <TT>C<SUB><I>i</I></SUB></TT> is the
<TT>i</TT><EM>th</EM> constraint of <TT>List</TT>. Each <TT>C<SUB><I>i</I></SUB></TT>
must be a boolean FD expression (section <A HREF="#Boolean-FD-expressions">8.7.1</A>).<BR>
<BR>
<TT>fd_cardinality(Lower, List, Upper)</TT> is equivalent to
<TT>fd_cardinality(List, Count), Lower #=< Count, Count #=<
Upper</TT><BR>
<BR>
<TT>fd_at_least_one(List)</TT> is equivalent to
<TT>fd_cardinality(List, Count), Count #>= 1</TT>.<BR>
<BR>
<TT>fd_at_most_one(List)</TT> is equivalent to
<TT>fd_cardinality(List, Count), Count #=< 1</TT>.<BR>
<BR>
<TT>fd_only_one(List)</TT> is equivalent to <TT>fd_cardinality(List,
1)</TT>.<BR>
<BR>
<B>Errors</B><BR>
<TABLE CELLSPACING=2 CELLPADDING=0>
<TR><TD BGCOLOR=black COLSPAN=3><TABLE BORDER=0 WIDTH="100%" CELLSPACING=0 CELLPADDING=1><TR><TD></TD></TR></TABLE></TD>
</TR>
<TR><TD VALIGN=top ALIGN=left><TT>List</TT> is a partial list</TD>
<TD VALIGN=top ALIGN=center NOWRAP> </TD>
<TD VALIGN=top ALIGN=left><TT>instantiation_error</TT></TD>
</TR>
<TR><TD BGCOLOR=black COLSPAN=3><TABLE BORDER=0 WIDTH="100%" CELLSPACING=0 CELLPADDING=1><TR><TD></TD></TR></TABLE></TD>
</TR>
<TR><TD VALIGN=top ALIGN=left><TT>List</TT> is neither a partial list nor a list</TD>
<TD VALIGN=top ALIGN=center NOWRAP> </TD>
<TD VALIGN=top ALIGN=left><TT>type_error(list, List)</TT></TD>
</TR>
<TR><TD BGCOLOR=black COLSPAN=3><TABLE BORDER=0 WIDTH="100%" CELLSPACING=0 CELLPADDING=1><TR><TD></TD></TR></TABLE></TD>
</TR>
<TR><TD VALIGN=top ALIGN=left><TT>Count</TT> is neither an FD variable nor an integer</TD>
<TD VALIGN=top ALIGN=center NOWRAP> </TD>
<TD VALIGN=top ALIGN=left><TT>type_error(fd_variable, Count)</TT></TD>
</TR>
<TR><TD BGCOLOR=black COLSPAN=3><TABLE BORDER=0 WIDTH="100%" CELLSPACING=0 CELLPADDING=1><TR><TD></TD></TR></TABLE></TD>
</TR>
<TR><TD VALIGN=top ALIGN=left><TT>Lower</TT> is a variable</TD>
<TD VALIGN=top ALIGN=center NOWRAP> </TD>
<TD VALIGN=top ALIGN=left><TT>instantiation_error</TT></TD>
</TR>
<TR><TD BGCOLOR=black COLSPAN=3><TABLE BORDER=0 WIDTH="100%" CELLSPACING=0 CELLPADDING=1><TR><TD></TD></TR></TABLE></TD>
</TR>
<TR><TD VALIGN=top ALIGN=left><TT>Lower</TT> is neither a variable nor an integer</TD>
<TD VALIGN=top ALIGN=center NOWRAP> </TD>
<TD VALIGN=top ALIGN=left><TT>type_error(integer, Lower)</TT></TD>
</TR>
<TR><TD BGCOLOR=black COLSPAN=3><TABLE BORDER=0 WIDTH="100%" CELLSPACING=0 CELLPADDING=1><TR><TD></TD></TR></TABLE></TD>
</TR>
<TR><TD VALIGN=top ALIGN=left><TT>Upper</TT> is a variable</TD>
<TD VALIGN=top ALIGN=center NOWRAP> </TD>
<TD VALIGN=top ALIGN=left><TT>instantiation_error</TT></TD>
</TR>
<TR><TD BGCOLOR=black COLSPAN=3><TABLE BORDER=0 WIDTH="100%" CELLSPACING=0 CELLPADDING=1><TR><TD></TD></TR></TABLE></TD>
</TR>
<TR><TD VALIGN=top ALIGN=left><TT>Upper</TT> is neither a variable nor an integer</TD>
<TD VALIGN=top ALIGN=center NOWRAP> </TD>
<TD VALIGN=top ALIGN=left><TT>type_error(integer, Upper)</TT></TD>
</TR>
<TR><TD BGCOLOR=black COLSPAN=3><TABLE BORDER=0 WIDTH="100%" CELLSPACING=0 CELLPADDING=1><TR><TD></TD></TR></TABLE></TD>
</TR>
<TR><TD VALIGN=top ALIGN=left>an element <TT>E</TT> of the <TT>List</TT> list is an invalid
boolean expression</TD>
<TD VALIGN=top ALIGN=center NOWRAP> </TD>
<TD VALIGN=top ALIGN=left>an FD boolean constraint (section <A HREF="#Boolean-FD-expressions">8.7.1</A>)</TD>
</TR>
<TR><TD BGCOLOR=black COLSPAN=3><TABLE BORDER=0 WIDTH="100%" CELLSPACING=0 CELLPADDING=1><TR><TD></TD></TR></TABLE></TD>
</TR></TABLE><BR>
<B>Portability</B><BR>
<BR>
GNU Prolog predicates.<BR>
<BR>
<HR SIZE=2>
Copyright (C) 1999-2007 Daniel Diaz
<BR>
<BR>
Verbatim copying and distribution of this entire article is permitted in any
medium, provided this notice is preserved. <BR>
<BR>
<A HREF="index.html#copyright">More about the copyright</A>
<HR>
<A HREF="gprolog060.html"><IMG SRC ="previous_motif.gif" ALT="Previous"></A>
<A HREF="gprolog054.html"><IMG SRC ="contents_motif.gif" ALT="Up"></A>
<A HREF="gprolog062.html"><IMG SRC ="next_motif.gif" ALT="Next"></A>
</BODY>
</HTML>
|