1% BEGIN LICENSE BLOCK 2% Version: CMPL 1.1 3% 4% The contents of this file are subject to the Cisco-style Mozilla Public 5% License Version 1.1 (the "License"); you may not use this file except 6% in compliance with the License. You may obtain a copy of the License 7% at www.eclipse-clp.org/license. 8% 9% Software distributed under the License is distributed on an "AS IS" 10% basis, WITHOUT WARRANTY OF ANY KIND, either express or implied. See 11% the License for the specific language governing rights and limitations 12% under the License. 13% 14% The Original Code is The ECLiPSe Constraint Logic Programming System. 15% The Initial Developer of the Original Code is Cisco Systems, Inc. 16% Portions created by the Initial Developer are 17% Copyright (C) 2012 Cisco Systems, Inc. All Rights Reserved. 18% 19% Contributor(s): Kish Shen 20% 21% END LICENSE BLOCK 22 23%HEVEA\cutdef[1]{section} 24 25\section{Introduction} 26 27 The GFD library is an interface for {\eclipse} to Gecode's finite domain constraint 28 solver. Gecode ({\tt www.gecode.org}) is an open-source toolkit for 29 developing 30 constraint-based systems in C++, and includes an integer 31 finite domain constraint solver. 32 33 This interface provides a high degree of code compatibility with the finite 34 domain portion of the IC library, and to a lesser extent, with the FD 35 library as well. This means that programs originally written for the 36 IC library should run with GFD with little modifications, beyond 37 renaming any explicit reference to the ic family of modules. For example, 38 here is a GFD program for N-Queens: 39 40\begin{quote} 41\begin{verbatim} 42:- lib(gfd). 43 44queens_list(N, Board) :- 45 length(Board, N), 46 Board :: 1..N, 47 (fromto(Board, [Q1|Cols], Cols, []) do 48 ( foreach(Q2, Cols), param(Q1), count(Dist,1,_) do 49 Q2 #\= Q1, 50 Q2 - Q1 #\= Dist, 51 Q1 - Q2 #\= Dist 52 ) 53 ), 54 labeling(Board). 55\end{verbatim} 56\end{quote} 57 58This version of the program is from an example IC version of N-Queens, 59with just \verb':- lib(ic)' replaced by \verb':- lib(gfd)'. The 60search is done in \eclipse, using GFD's \verb'labeling/1', which essentially 61employs no heuristics in selecting the variable (input order) and choice of 62value to label the selected variable to (from minimum). 63 64 65 66\section{Problem Modelling} 67 68GFD provides facilities to model and solve problems over the 69finite integer domain, with Gecode as the solver. It supports the constraints 70provided by Gecode -- and Gecode supports a large set of constraints. The 71search to solve the problem can be done at the 72{\eclipse} level (with support from Gecode for variable and value selections), 73or the whole search can be performed by Gecode itself using one of its 74search engines. 75 76Implementation-level differences (like Gecode's 77{\it re-computation based\/} model vs. \eclipse's {\it backtracking\/} 78model) are largely invisible to the user, 79as GFD automatically maintains the Gecode computational state 80to match \eclipse's. 81 82\subsection{Usage} 83 84To load the GFD library into your program, simply add the following directive 85at an appropriate point in your code. 86 87\begin{quote} 88\begin{verbatim} 89:- lib(gfd). 90\end{verbatim} 91\end{quote} 92 93\subsection{Integer domain variables} 94 95An (integer) domain variable is a variable which can be instantiated only to a 96value from a given finite set of integer values. 97 98A variable becomes a domain variable when it first appears in a (GFD) 99constraint. If the constraint is a domain constraint, then the variable will 100be given the domain specified by the constraint. Otherwise, the variable will 101be given a default domain, which should be large enough for 102most problem instances. 103 104The default domain is an interval, and the maximum and minimum values of this 105interval can be changed using \bipref{gfd_set_default/2}{../bips/lib/gfd/gfd_set_default-2.html} (with the options 106{\tt interval_max} and {\tt interval_min} for the maximum and minimum values, 107respectively). You can also obtain the current values 108of interval_max and interval_min using \bipref{gfd_get_default/2}{../bips/lib/gfd/gfd_get_default-2.html}. 109 110The Gecode documentation suggests that domain variables should be given as 111small a domain as possible, and requires the user to explicitly specify a domain for 112all domain variables. While this is not required by GFD, following Gecode's 113convention is still a good idea, since overly large domains can negatively 114affect performance. It is therefore recommended to make use of domain 115constraints, and specify the domain for variables before using them in other 116constraints. 117 118A domain variable is mapped into a Gecode \verb'IntVar'. 119 120In GFD, as in IC, booleans (such as the boolean in reified constraints) are 121normal domain variables with the domain \verb'[0,1]'. However, in Gecode, 122boolean domain variables are a separate class \verb'BoolVar'. Boolean 123domain variables are implemented in GFD by linking the integer 124domain variable representing the boolean to an internal 125\verb'BoolVar' in the Gecode solver state, and the user always access the 126boolean via the integer domain variable. 127 128 129\subsection{Constraints} 130GFD supports the (integer finite domain) constraints implemented by Gecode. 131Some of these constraints correspond to those in \eclipse's native finite 132domain solvers (IC and FD), but many do not. For those that are 133implemented in IC and/or FD, the same name and syntax is used by GFD 134(although details may differ, such as the types allowed for arguments). 135See 136\begin{htmlonly} 137\ahref{../bips/finite-domain_constraints.html}{Table of Finite domain Constraints} 138\end{htmlonly} 139\begin{latexonly} 140the Table of Finite domain Constraints (included with the documentation 141in \verb|<ECLiPSeDir>/doc/bips/finite-domain_constraints.html|) 142\end{latexonly} 143for the constraints supported by \eclipse's finite domain solvers. 144%One difference is that all these constraints are defined in the GFD 145%library itself, and can thus be called without module qualification or 146%loading additional libraries. 147 148\label{conlev} 149In addition to propagating constraints at a unspecified or default level, 150Gecode also support three propagaion consistency levels. GFD map 151these consistency levels to four modules: 152\begin{description} 153\item[{\tt gfd_gac}] Domain consistent (Generalised Arc-Consistent), maps to {\tt ICL_DOM} in Gecode. 154\item[{\tt gfd_bc}] Bound consistent, maps to {\tt ICL_BND} in Gecode. 155\item[{\tt gfd_vc}] Value consistent, maps to {\tt ICL_VAL} in Gecode. 156\item[{\tt gfd}] Default consistency level, maps to {\tt ICL_DEF} in Gecode. 157\end{description} 158Constraints can be posted unqalified for the default consistency level, or 159explicitly qualified with the module name for the desired 160consistency level, e.g. 161\begin{quote} 162\begin{verbatim} 163gfd_gac:alldifferent(Xs) 164\end{verbatim} 165\end{quote} 166Alternatively, constraints can also be imported from one of the modules and 167then posted unqualified at the imported consistency level. 168 169The default consistency level is supported for all constraints, but 170posting a constraint at the other three consistency levels is supported only 171if that consistency level is implemented for that constraint 172in Gecode -- see the individual documentation for the constraints for details. 173Note that the three consistency modules are implicitly created when GFD 174is loaded, and do not need to be loaded explicitly. 175 176Even constraints that involve expressions may be posted at specific 177consistency levels. In fact, a consistency level can be specified for 178any sub-expression within the expression. However, it is possible that some of 179the sub-constraints and sub-expressions inside the expressions are not 180supported at the given consistency level. In such cases, these sub-expressions 181will be posted at the default consistency level. Note that any 182sub-expressions with its own specified consistency level will also be 183factored out and posted separately. 184 185For example, the N-Queens example 186can post domain consistent versions of the \verb'#\=/2' constraints: 187\begin{quote} 188\begin{verbatim} 189:- lib(gfd). 190 191queens_list(N, Board) :- 192 length(Board, N), 193 Board :: 1..N, 194 (fromto(Board, [Q1|Cols], Cols, []) do 195 ( foreach(Q2, Cols), param(Q1), count(Dist,1,_) do 196 gfd_gac: (Q2 #\= Q1), 197 gfd_gac: (Q2 - Q1 #\= Dist), 198 gfd_gac: (Q1 - Q2 #\= Dist) 199 ) 200 ), 201 labeling(Board). 202\end{verbatim} 203\end{quote} 204In this particular example, using the stronger propagation actually results in 205a reduction in performance, as there is no reduction in search space from the 206stronger propagation, but an increase in the cost of doing the propagation, 207 208Gecode maintains a solver state representing the problem, with the constraints 209and problem variables, and performs constraint propagation within this solver 210state. GFD adds the constraints and problem variables to this state 211as they are posted in the user program. Unlike 212the problem variables, there are no \eclipse level representation of the 213constraints. One consequence is that floundering -- active constraints 214remaining at the end of computation -- can only be determined from the solver 215state. GFD provides \bipref{solver_constraints_number/1} 216{../bips/lib/gfd/solver_constraints_number-1.html}, 217and \bipref{solver_vars_number/1} 218{../bips/lib/gfd/solver_vars_number-1.html} to obtain the current number of 219active constraints and problem variables, respectiviely, in the current solver 220state. 221 222Unlike \eclipse's native solvers, constraint propagation in Gecode must be 223triggered explicitly. In GFD, triggering propagation in the Gecode solver state 224is implemented as a demon goal {\tt gfd_do_propagate/1} at scheduling 225priority 9. 226When a constraint is posted, it is added to the solver state, 227and the propagate demon goal is 228scheduled for execution. It is thus possible to post multiple 229 constraints without propagation by posting the constraints at a more 230urgent (i.e. numerically smaller) priority than 9 (see 231\bipref{call_priority/2}{../bips/kernel/suspensions/call_priority-2.html}). 232This could reduce the cost of performing the propagation. 233 234\paragraph{Constraint argument conventions} 235 236GFD's constraints (and other predicates) follows several conventions 237for the format of its arguments. These are outlined in this section. 238 239For arguments in constraints that are domain variables, the argument 240can be supplied as an 241array element using array notion (e.g. \verb|Array[1]|). 242Non-domain variables will be turned into domain variables with the default 243interval, and an integer can be given in place of a domain variable, 244representing a domain variable with a singleton domain. 245 246For arguments that are a group of variables or values, these are supplied 247as a collection 248(as used in \bipref{collection_to_list/2}{../bips/lib/lists/collection_to_list-2.html}). In some cases, the elements in the collection are required to be 249ordered, and for such cases, the ordering is 250with respect to the flattened form of the collection, with indexing starting 251at 1 for the first element. Array notation can again be used to supply a 252part of the array as a collection. 253 254Indexing always start at 1 for \eclipse, 255which is different from Gecode, where index starts from 0. 256GFD maps between the two index conventions in various ways, 257depending on the constraint, with the aim of 258minimising the overhead. GFD also supports versions of these constraints that 259uses Gecode's native indices, i.e. starting from 0, and these have an 260additional {\tt _g} in their name (e.g. {\bf bin_packing_g/3} is the Gecode native 261index version of {\bf bin_packing/3}). These versions of the constraint do not 262have the overhead of converting the index value, but may be 263incompatible with the rest of \eclipse. 264 265In general, any collection argument can be supplied as a nested collection 266(e.g. nested listed or multi-dimensional arrays). In some 267cases, nested collections are required and supply information required 268by the constraint, e.g.\ 269the dimension in multi-dimensional bin-packing predicates. Also, 270some predicates' argument expect a two dimensional matrix, in which 271case the argument must be supplied as a two dimensional collection 272(list of lists, two dimensional array). A two dimensional collection is 273organised in the standard \eclipse way, i.e.\ row-major order, as a 274collection of rows, where each row having the same number of elements, and 275each of these 276element representing the column elements in that row. In array notation, 277the row is addressed first, followed by the column, i.e.\ 278\verb'[Row,Column]'. 279 280\subsubsection{Domain constraints} 281 282The following domain constraints are supported by GFD: 283 284\begin{description} 285\item[\biptxtrefni{?Vars \#:: ++Domain}{\#::/2!gfd}{../bips/lib/gfd/HNN-2.html}] 286Constrains Vars to have the domain Domain. A \biptxtrefni{reified}{\#::/3!gfd}{../bips/lib/gfd/HNN-3.html} version is also available. 287\verb'::/2,3' are also supported as aliases. 288 289\end{description} 290 291 292\subsubsection{Arithmetic and logical expressions} 293 294GFD supports expressions as arguments for relational and logical connective 295constraints. Expressions can either evaluate to an integer (integer 296expression) or a truth value (constraint expression). Integer and 297constraint expressions maps to Gecode's {\it LinIntExpr\/} and {\it BoolExpr}, 298respectively. Unlike IC's expressions, user-defined constraints are not 299allowed, but unrecognised ground terms in integer expressions are treated as 300arithmetic functions and evaluated. 301 302\begin{description} 303\item[Relational Constraints] 304These specify an arithmetic relationship between two integer expressions. 305Constraint expressions are allowed as arguments of relational constraints, 306with the truth value of the expression treated as the integer value 1 (true) 307or 0 (false). 308 309All relational constraints have their reified counterparts, which has an extra 310boolean argument that specify if the constraint is entailed or not. Expressions 311in refied constraints are restricted to inlined (i.e.\ Gecode native) integer 312expressions. 313 314The relational constraints are: 315\biptxtrefni{\#</2,3 }{\#</2!gfd}{../bips/lib/gfd/HL-2.html} (less than), 316\biptxtrefni{\#=/2,3}{\#=/2!gfd}{../bips/lib/gfd/HE-2.html} (equal), 317\biptxtrefni{\#=</2,3}{\#=</2!gfd}{../bips/lib/gfd/HEL-2.html} (less than or equal to), 318\biptxtrefni{\#>/2,3}{\#>/2!gfd}{../bips/lib/gfd/HG-2.html} (greater than), 319\biptxtrefni{\#>=/2,3}{\#>=/2!gfd}{../bips/lib/gfd/HGE-2.html} (greater than or equal to), 320\biptxtrefni{\#\bsl=/2,3}{\#\\=/2!gfd}{../bips/lib/gfd/HRE-2.html} (not equal to). 321 322\item[Logical Connective constraints] 323Specifies a logical connection between constraint expression(s). 324. 325All logical connectives have their reified counterparts. 326 327The available connectives are: 328 329\biptxtrefni{<=>/2,3}{<=>/2!gfd}{../bips/lib/gfd/LEG-2.html} (equivalent), 330\biptxtrefni{=>/2,3}{=>/2!gfd}{../bips/lib/gfd/EG-2.html} (implies), 331\biptxtrefni{and/2,3}{and/2!gfd}{../bips/lib/gfd/and-2.html} (and), 332\biptxtrefni{or/2,3}{or/2!gfd}{../bips/lib/gfd/or-2.html} (or), 333\biptxtrefni{xor/2,3}{xor/2!gfd}{../bips/lib/gfd/xor-2.html} (exclusive or), 334\biptxtrefni{neg/1,2}{neg/1!gfd}{../bips/lib/gfd/neg-1.html} (negation). 335 336Boolean domain variables with domain \texttt{[0,1]} and constraints 337which can be reified can occur as an argument of a logical connective, i.e. 338as a constraint expression, evaluating to the reified truth value. 339 340For compatibility with IC, \texttt{\#=/2} can be used 341instead of \texttt{<=>/2} and \texttt{\#\bsl=/2} can be used instead of 342\texttt{xor}. 343 344Gecode also supports {\em half reification\/} as well as the normal 345{\em full reification} for reified constraints. Half verification 346is when the propagation is in one direction only across the logical 347connective (i.e. \verb'=>'), rather than bi-directional (\verb'<=>'). 348In GFD, constraints can be half reified as follows: 349\begin{verbatim} 350Boolean => Constraint 351Constraint => Boolean 352\end{verbatim} 353where Constraint is the half reified constraint, written without its boolean 354argument \texttt{Boolean}. The two alternatives are for the two different 355direction of propagation. 356 357\end{description} 358 359The syntax for the expressions closely follows that in IC. The 360following can be used inside integer expressions: 361 362\begin{description} 363\item[\texttt{X}] 364 \emph{Variables}. If \verb'X' is not yet a domain variable, it is turned 365 into one. 366 367\item[\texttt{123}] 368 Integer constants. 369 370\item[\texttt{-Expr}] 371 Sign change. 372 373\item[\texttt{abs(Expr)}] 374 The absolute value of Expr. 375 376\item[\texttt{E1+E2}] 377 Addition. 378 379\item[\texttt{E1-E2}] 380 Subtraction. 381 382\item[\texttt{E1*E2}] 383 Multiplication. 384 385\item[\texttt{E1//E2}] 386 Integer division, truncating towards zero. 387 388\item[\texttt{E1/E2}] 389 Division, defined only if E2 evenly divides E1 (non-inlined). 390 391\item[\texttt{E1 rem E2}] 392 Integer remainder, same sign as E1. 393 394\item[\texttt{Expr}\textasciicircum{}{\texttt N}] 395 N$^{th}$ power. N is a positive integer. . 396 397\item[\texttt{min(E1,E2)}] 398 Minimum. 399 400\item[\texttt{max(E1,E2)}] 401 Maximum. 402 403\item[\texttt{sqr(Expr)}] 404 Square. Logically equivalent to \verb|Expr*Expr|. 405 406\item[\texttt{rsqr(Expr)}] 407 Reverse of the \texttt{sqr} function. Differ from \texttt{sqrt} in that 408 negative root is not excluded (non-inlined). 409 410\item[\texttt{isqrt(Expr)}] 411 Integer square root (always positive). Truncated towards zero. 412 413\item[\texttt{sqrt(Expr)}] 414 Square root, defined only if Expr is the square of an integer 415 (non-inlined). 416 417\item[\texttt{inroot(Expr,N)}] 418 Integer N$^{th}$ root, N is a positive integer. Truncated to nearest smaller 419 integer. For even N, result is the non-negative root. 420 421\item[\texttt{rpow(Expr,N)}] 422 Reverse of exponentiation, i.e.\ find \texttt{X} in \verb'E1 = X^N'.. 423 \texttt{N} is a positive integer. Differ from \texttt{inroot} in that 424 the result is only defined for integral root, and negative root not 425 excluded (non-inlined). 426 427\item[\texttt{sum(ExprCol)}] 428 Sum of a collection of expressions (ExprCol non-inlined). 429 430\item[\texttt{sum(IntCol*ExprCol)}] 431 Scalar product of a collection of integers and expressions. 432 \verb'IntCol' and \verb'ExprCol' must be the same size 433 (ExprCol non-inlined). 434 435\item[\texttt{min(ExprCol)}] 436 Minimum of a collection of expressions (ExprCol non-inlined). 437 438\item[\texttt{max(ExprCol)}] 439 Maximum of a collection of expressions (ExprCol non-inlined). 440 441\item[\texttt{element(ExprIdx, Col)}] 442 Element constraint, Evaluate to the ExprIdx'th element of Col. 443 ExprIdx can be an integer expression. 444 445\item[ 446 \texttt{\#>}, \texttt{\#>=}, \texttt{\#=}, \texttt{\#=<}, 447 \texttt{\#<}, 448 \texttt{\#\bsl=}] 449 450 Posted as a constraint, both the left- and right- hand arguments are 451 inlined expressions (non-inlined). 452 453 Within the expression context, the constraint evaluates to its 454 reified truth value. If the constraint is entailed by the 455 state of the constraint store then the (sub-)expression 456 evaluates to \verb|1|. If it is dis-entailed by the state of 457 the constraint store then it evaluates to \verb|0|. If its 458 reified status is unknown then it evaluates to a boolean domain 459 variable \verb|0..1|. 460 461\begin{sloppypar} 462 Note: The simple cases (e.g.\ \verb|Bool #= (X #> 5)|) are 463 equivalent to directly calling the reified forms of the basic 464 constraints (e.g.\ \verb|#>(X, 5, Bool)|). 465\end{sloppypar} 466 467\item[\texttt{ConLev:Expr}] 468 Post \texttt{Expr} at consistency level \texttt{ConLev}. Consistency 469 levels are described in section~\ref{conlev}. 470 471\item[\texttt{eval(Expr)}] 472 Logically equivalent to \verb'Expr'. Provided for compatiblity 473 with IC 474 475\item[\texttt{Functional/reified constraints}] 476 Reified constraints (whose last argument is a 0/1 variable) 477 and functional constraints (whose last argument is an integer 478 variable) can be written without their last argument within 479 an expression context. The expression then effectively 480 evaluates to the value of the missing (unwritten) argument. 481 (non-inlined) 482 483\end{description} 484and for constraint expressions: 485 486\begin{description} 487\item[\texttt{X}] 488 \emph{Boolean Variables}. Domain variables with domain 0/1. If cariable 489 is not yet a domain variable, it is turned into one. 490 491\item[\texttt{1}] 492 truth value (0 for false, 1 for true). 493 494 495\item[\texttt{E1 and E2}] 496 Reified constraint conjunction. e.g. \verb'X #> 3 and Y #< 8'. 497 E1 and E2 are constraint expressions. 498 499\item[\texttt{E1 or E2}] 500 Reified constraint disjunction. e.g. \verb'X #> 3 or Y #< 8'. 501 E1 and E2 are constraint expressions. 502 503\item[\texttt{E1 xor E2}] 504 Reified constraint exclusive disjunction/non-equivalence. e.g. \verb'X #> 3 xor Y #< 8'. 505 E1 and E2 are constraint expressions. 506 507\item[\texttt{E1 => E2}] 508 Reified constraint implication. e.g. \verb'X #> 3 => Y #< 8'. 509 E1 and E2 are constraint expressions. 510 511\item[\texttt{neg E}] 512 Reified constraint negation. e.g. \verb'neg X #> 3' 513 E is a constraint expressions. 514 515\item[\texttt{E1 <=> E2}] 516 Reified constraint equivalence. e.g. \verb'X #> 3 <=> Y #< 8'. 517 This is similar to {\texttt \#=} used in an expression context. 518 E1 and E2 are constraint expressions. 519 520\item[\texttt{element(ExprIdx, BoolCol)}] 521 Element constraint, Evaluate to the ExprIdx'th element of BoolCol. 522 ExprIdx can be an inlined integer expression. BoolCol is a 523 collection of boolean values or domain variable. 524 525\item[ 526 \texttt{\#>}, \texttt{\#>=}, \texttt{\#=}, \texttt{\#=<}, 527 \texttt{\#<}, 528 \texttt{\#\bsl=}] 529 530 Reified relational constraint, both the left- and right- hand arguments are 531 inlined integer expressions. 532 533\item[\texttt{ConLev:Expr}] 534 Post \texttt{Expr} at consistency level \texttt{ConLev}. Consistency 535 levels are described in section~\ref{conlev}. 536 537\item[\texttt{eval(Expr)}] 538 Logically equivalent to \verb'Expr'. Provided for compatibility 539 with IC. 540 541\item[\texttt{Reified constraints}] 542 Reified constraints (whose last argument is a 0/1 variable) 543 can be written without their last argument within 544 an expression context. The expression then effectively 545 evaluates to the value of the missing (unwritten) argument. 546 (non-inlined) 547 548\end{description} 549 550The expressions allowed by GFD are a super-set of the expressions supported by 551Gecode. The components not supported by Gecode are indicated by `non-inlined' 552in the above description. When an expression is posted, it is parsed and 553broken down into expressions and/or logical connectives supported by Gecode, 554along 555with any constraints). This is done to 556allow the user greater freedom in the code they write, and also to provide 557better compatibility with IC. 558 559Note that posting of complex expressions is relatively expensive: they are 560first parsed at the {\eclipse} level by GFD to extract the sub-expressions and 561any new domain variables, and these sub-expressions (in the form of 562{\eclipse} structures) are then parsed again at the GFD C++ level to convert 563them to the appropriate Gecode data structures, which are then passed to 564Gecode. Gecode itself will then convert these data structures 565to the basic constraints that it supports. 566 567Unlike IC, GFD domain variables must have finite upper and lower 568bounds, and any arithmetic expression that evaluate to values outside 569these bounds will fail. In particular, auxillary variables created by GFD 570used to represent factored out subexpressions are given the default bounds, 571and this may lead to unexpected failures, e.g.\ assuming the default bounds 572was not changed, the following will fail: 573\begin{verbatim} 574 A :: 0..10^9, A #= 10^8/1. 575\end{verbatim} 576\noindent 577because division (\texttt{/}) is non-inlined and is factored our, and 578\verb|10^8| is outside the default bounds. 579 580%%% Not sure which point we are trying to make here: 581%As mentioned above, one of the reason for parsing the expressions is to 582%extract new domain variables. This is another difference between GFD and 583%Gecode: Gecode requires the user to explicitly initialise domain variables 584%(IntVar) with a domain before using them, while GFD will give any new 585%domain variables a default domain, so variables do not need to be 586%initialised with a domain before use. This GFD behaviour is compatible with 587%IC (except the default domain is a finite integer domain like FD). 588 589 590 591\subsubsection{Arithmetic constraints} 592 593These constraints impose some form of arithmetic relation between their 594arguments. Some of these constraints can occur inside expressions, while 595others are ``primitive'' versions of the constraint where the arguments 596are domain variables (or integers). 597 598%%% Not sure which point we are trying to make here: 599%Many of the constraints listed here are only available in IC inside 600%expressions, i.e. they are not available as independent constraints. 601%In GFD, all ``operators'' allowed in expressions have a constraint 602%counterpart that can be posted outside of expressions, partly because 603%Gecode does provide these constraints. 604 605 606\begin{description} 607%%% Commented out until we sort out the name 608%\item[\biptxtrefni{divmod(?X,?Y,?Q,?M)}{divmod/4!gfd}{../bips/lib/gfd/divmod-4.html}] 609%Constrains Q to X // Y, and M to X rem Y. 610 611\item[\biptxtrefni{all_eq(?Collection,?Y)}{all_eq/2!gfd}{../bips/lib/gfd/all_eq-2.html}] 612Constrains each element of Collection to be equal to Y. Similar constraints 613for the other relations: 614\biptxtrefni{all_ge/2)}{all_ge/2!gfd}{../bips/lib/gfd/all_ge-2.html} (greater than or equal to), 615\biptxtrefni{all_gt/2}{all_gt/2!gfd}{../bips/lib/gfd/all_gt-2.html} (greater than), 616\biptxtrefni{all_le/2}{all_le/2!gfd}{../bips/lib/gfd/all_le-2.html} (less than or equal to), 617\biptxtrefni{all_lt/2}{all_lt/2!gfd}{../bips/lib/gfd/all_lt-2.html} (less than), and 618\biptxtrefni{all_ne/2}{all_ne/2!gfd}{../bips/lib/gfd/all_ne-2.html} (not equal). 619 620 621\item[\biptxtrefni{max(+Collection,?Max)}{max/2!gfd}{../bips/lib/gfd/max-2.html}] 622Constrains Max to be the maximum of the values in Collection. Similarly, 623\biptxtrefni{min(+Collection,?Min)}{min/2!gfd}{../bips/lib/gfd/min-2.html} 624for minimum. 625 626\item[\biptxtrefni{max_index(+Collection,?Index)}{max_index/2!gfd}{../bips/lib/gfd/max_index-2.html}] 627Constrains Index to be the the index(es) of the variable(s) with the maximum of the values in Collection. Similarly, 628\biptxtrefni{min_index(+Collection,?Index)}{min_index/2!gfd}{../bips/lib/gfd/min_index-2.html}\item[\biptxtrefni{max_index(+Collection,?Index)}{max_index/2!gfd}{../bips/lib/gfd/max_index-2.html}] 629Constrains Index to be the the index(es) of the variable(s) with the maximum of the values in Collection. Similarly, 630\biptxtrefni{min_index(+Collection,?Index)}{min_index/2!gfd}{../bips/lib/gfd/min_index-2.html} 631for minimum. 632 633\item[\biptxtrefni{max_first_index(+Collection,?Index)}{max_first_index/2!gfd}{../bips/lib/gfd/max_first_index-2.html}] 634Constrains Index to be the the index of the first variable with the maximum of the values in Collection. Similarly, 635\biptxtrefni{min_first_index(+Collection,?Index)}{min_first_index/2!gfd}{../bips/lib/gfd/min_first_index-2.html} 636for minimum. 637 638%%% does not exist (would clash with arithmetic builtin) 639%\item[\biptxtrefni{max(?X,?Y,?Max)}{max/3!gfd}{../bips/lib/gfd/max-3.html}] 640%Constrains Max to be the maximum of X and Y. Similarly, 641%\biptxtrefni{min(?X,?Y,?Min)}{min/3!gfd}{../bips/lib/gfd/min-3.html} for 642% minimum. 643 644\item[\biptxtrefni{mem(+Vars,?Member [,?Bool])}{mem/2!gfd}{../bips/lib/gfd/mem-2.html}] 645Constrains Member to be the a member element in Vars. The 646\biptxtrefni{reified}{mem/3!gfd}{../bips/lib/gfd/mem-3.html} version has the 647\verb'Bool' argument. 648 649\begin{sloppypar} 650\item[\biptxtrefni{scalar_product(++Coeffs,+Collection,+Rel,?Sum [,?Bool])}{scalar_product/4!gfd}{../bips/lib/gfd/scalar_product-4.html}] 651Constrains the scalar product of the elements of Coeffs 652 and Collection to satisfy the relation {\em sum(Coeffs*Collection) Rel P}. 653\biptxtrefni{Reified}{scalar_product/5!gfd}{../bips/lib/gfd/scalar_product-5.html} 654with \verb'Bool' argument. 655\end{sloppypar} 656 657 658\item[\biptxtrefni{sum(+Collection,?Sum)}{sum/2!gfd}{../bips/lib/gfd/sum-2.html}] 659Constrains Sum to be the sum of the elements in Collection, or if the 660argument is of the form IntCollection*Collection, the scalar product of the 661connections. 662 663\item[\biptxtrefni{sum(+Collection,+Rel,?Sum [,?Bool]}{sum/3!gfd}{../bips/lib/gfd/sum-3.html}] 664Constrains the sum of the elements of Collection to satisfy the relation {\em sum(Collection) Rel Sum}. 665\biptxtrefni{Reified}{sum/4!gfd}{../bips/lib/gfd/sum-4.html} 666with \verb'Bool' argument. 667 668 669\end{description} 670 671\subsubsection{Ordering constraints} 672 673These constraints impose some form of ordering relation on their arguments. 674 675\begin{description} 676\item[\biptxtrefni{lex_eq(+Collection1,+Collection2)}{lex_eq/2!gfd}{../bips/lib/gfd/lex_eq-2.html}] 677Constrains Collection1 to be lexicographically equal to Collection2. 678Constraints for the other lexicographic relations: 679\biptxtrefni{lex_ge/2}{lex_ge/2!gfd}{../bips/lib/gfd/lex_ge-2.html} (lexicographically greater or equal to), 680\biptxtrefni{lex_gt/2}{lex_gt/2!gfd}{../bips/lib/gfd/lex_gt-2.html} (lexicographically greater than), 681\biptxtrefni{lex_le/2}{lex_le/2!gfd}{../bips/lib/gfd/lex_le-2.html} 682(lexicographically less or equal to), 683\biptxtrefni{lex_lt/2}{lex_lt/2!gfd}{../bips/lib/gfd/lex_lt-2.html}, 684(lexicographically less than), 685\biptxtrefni{lex_neq/2}{lex_neq/2!gfd}{../bips/lib/gfd/lex_neq-2.html} 686(lexicographically not equal to). 687 688\item[\biptxtrefni{ordered(+Relation,+Collection)}{ordered/2!gfd}{../bips/lib/gfd/ordered-2.html}] 689Constrains Collection to be ordered according to Relation. 690 691\item[\biptxtrefni{precede(++Values,+Collection)}{precede/2!gfd}{../bips/lib/gfd/precede-2.html}] 692Constrains each value in Values to precede its succeeding 693value in Collection. 694 695\item[\biptxtrefni{precede(+S,+T,+Collection)}{precede/3!gfd}{../bips/lib/gfd/precede-3.html}] 696Constrains S to precede T in Collection. 697 698\item[\biptxtrefni{sorted(?Unsorted, ?Sorted)}{sorted/2!gfd}{../bips/lib/gfd/sorted-2.html}] 699Sorted is a sorted permutation of Unsorted. 700 701\item[\biptxtrefni{sorted(?Unsorted, ?Sorted, ?Positions)}{sorted/3!gfd}{../bips/lib/gfd/sorted-3.html}] 702Sorted is a sorted permutation (described by Positions) of Unsorted. 703 704\end{description} 705 706\subsubsection{Counting and data constraints} 707 708These constraints impose restrictions either on the number of 709 values that can be taken in one or more collections of domain 710 variables, and/or on the positions of values in the collection. 711\begin{description} 712\item[\biptxtrefni{alldifferent(+Vars)}{alldifferent/1!gfd}{../bips/lib/gfd/alldifferent-1.html}] 713Constrains all elements of Vars are different. 714 715\item[\biptxtrefni{alldifferent_cst(+Vars,++Offsets)}{alldifferent_cst/2!gfd}{../bips/lib/gfd/alldifferent_cst-2.html}] 716Constrains the values of each element plus corresponding offset to be pairwise different. 717 718\item[\biptxtrefni{among(+Values, ?Vars, +Rel, ?N)}{among/4!gfd}{../bips/lib/gfd/among-4.html}] 719The number of occurrences ({\em Occ}) in Vars of values taken from the set of 720values specified in Values satisfies the relation {\em Occ Rel N}. 721 722\item[\biptxtrefni{atleast(?N, +Vars, +V)}{atleast/3!gfd}{../bips/lib/gfd/atleast-3.html}] 723At least N elements of Vars have the value V. Similarly 724\biptxtrefni{atmost(?N, +Vars, +V)}{atmost/3!gfd}{../bips/lib/gfd/atmost-3.html}. 725 726\item[\biptxtrefni{count(+Value, ?Vars, +Rel, ?N)}{count/4!gfd}{../bips/lib/gfd/count-4.html}] 727Constrains the number of occurrences of Value in Vars ({\em Occ}) to satisfy 728the relation {\em Occ Rel N}. 729 730\item[\biptxtrefni{count_matches(+Values, ?Vars, +Rel, ?N)}{count_matches/4!gfd}{../bips/lib/gfd/count_matches-4.html}] 731The number of the elements in Vars that 732 match their corresponding value in Values, {\em Matches}, satisfies the 733 relation {\em Matches Rel N}. 734 735\item[\biptxtrefni{element(?Index, +Collection, ?Value)}{element/3!gfd}{../bips/lib/gfd/element-3.html}] 736Constrains Value to be the Index$^{th}$ element of the integer collection Collection. 737 738\item[\biptxtrefni{gcc(+Bounds,+Vars)}{gcc/2!gfd}{../bips/lib/gfd/gcc-2.html}] 739Constrains the number of occurrences of each Value in Vars according to the specification 740in Bounds (global cardinality constraint). 741 742\item[\biptxtrefni{nvalues(+Collection, +Rel, ?Limit)}{nvalues/3!gfd}{../bips/lib/gfd/nvalues-3.html}] 743Constrains {\em N}, the number of distinct values occurring in 744Collection to satisfy the relation {\em N Rel Limit}. 745 746\item[\biptxtrefni{occurrences(+Value,+Vars,?N)}{occurrences/3!gfd}{../bips/lib/gfd/occurrences-3.html}] 747Constrains the value Value to occur N times in Vars. 748 749\item[\biptxtrefni{sequence(+Low,+High,+K,+Vars,++Values)}{sequence/5!gfd}{../bips/lib/gfd/sequence-5.html}] 750The number of values taken from Values is between Low and 751High for all sequences of K variables in Vars. There is also a version for 752binary (0/1) variables: 753\biptxtrefni{sequence(+Low,+High,+K,+ZeroOnes)}{sequence/4!gfd}{../bips/lib/gfd/sequence-4.html}. 754\end{description} 755 756\subsubsection{Resource and scheduling constraints} 757These constraints deal with scheduling and/or allocation of resources. 758 759\begin{description} 760\item[\biptxtrefni{bin_packing(+Items,++ItemSizes,+BinLoads)}{bin_packing/3!gfd}{../bips/lib/gfd/bin_packing-3.html}] 761The one-dimensional bin packing constraint with loads: packing 762M items into N bins, each bin having a load specified in BinLoads. 763 764\item[\biptxtrefni{bin_packing(+Items,++ItemSizes,+N,+BinSize)}{bin_packing/4!gfd}{../bips/lib/gfd/bin_packing-4.html}] 765The one-dimensional bin packing constraint: packing M items 766into N bins of size BinSize. 767 768\item[\biptxtrefni{bin_packing_md(+Items,++ItemMDSizes,+BinMDLoads)}{bin_packing_md/3!gfd}{../bips/lib/gfd/bin_packing_md-3.html}] 769The multi-dimensional bin packing constraint with loads: packing 770M L-Dimensional items into N L-Dimensional bins, each bin having a load in 771each dimension. The dimension L is implicitly specified in ItemMDSizes and 772BinMDLoads. 773 774\begin{sloppypar} 775\item[\biptxtrefni{bin_packing_md(+Items,++ItemMDSizes,+N,+BinMDSize)}{bin_packing/4!gfd}{../bips/lib/gfd/bin_packing-4.html}] 776The multi-dimensional bin packing constraint loads: packing M L-Dimensional 777items into N L-Dimensional bins, each bin having a size in each dimension. 778The dimension L is implicitly specified in ItemMDSizes and BinMDSize. 779\end{sloppypar} 780 781\item[\biptxtrefni{cumulative(+Starts,+Durations,+Usages,+ResourceLimit)}{cumulative/4!gfd}{../bips/lib/gfd/cumulative-4.html}] 782Single-resource cumulative task scheduling constraint. A version with 783optional tasks is also available: 784\biptxtrefni{cumulative_optional(+StartTimes, +Durations, +Usages, +ResourceLimit, +Scheduled)}{cumulative_optional/5!gfd}{../bips/lib/gfd/cumulative_optional-5.html}. 785 786\item[\biptxtrefni{cumulatives(+Starts,+Durations,+Heights,+Assigned,+Capacities)}{cumulatives/5!gfd}{../bips/lib/gfd/cumulatives-5.html}] 787Multi-resource cumulatives constraint on specified tasks. 788 789\item[\biptxtrefni{cumulatives_min(+Starts,+Durs,+Heights,+Assgn,+Mins)}{cumulatives_min/5!gfd}{../bips/lib/gfd/cumulatives_min-5.html}] 790Multi-resource cumulatives constraint on specified tasks with 791required minimum resource consumptions. 792 793\item[\biptxtrefni{disjoint2(+Rectangles)}{disjoint2/1!gfd}{../bips/lib/gfd/disjoint2-1.html}] 794Constrains the position (and possibly size) of the rectangles in 795Rectangles so that none overlap. A version where placement of rectangles is 796optional is 797\biptxtrefni{disjoint2_optional(+Rectangles)}{disjoint2_optional/1!gfd}{../bips/lib/gfd/disjoint2_optional-1.html}. 798 799\item[\biptxtrefni{disjunctive(+StartTimes, +Durations)}{disjunctive/2!gfd}{../bips/lib/gfd/disjunctive-2.html}] 800Constrains the tasks with specified start times and durations to not overlap in time. A version with optional tasks is also available: 801\biptxtrefni{disjunctive_optional(+StartTimes, +Durations, +Scheduled)}{disjunctive_optional/3!gfd}{../bips/lib/gfd/disjunctive_optional-3.html}. 802 803\end{description} 804 805\subsubsection{Graph constraints} 806 807In these constraints, the arguments represent a graph, and the 808 constraint imposes some form of relation on the graph. 809 810\begin{description} 811\item[\biptxtrefni{circuit(+Succ)}{circuit/1!gfd}{../bips/lib/gfd/circuit-1.html}] 812Constrains elements in Succ to form a Hamiltonian circuit. 813A version allowing constant offsets is 814\biptxtrefni{circuit_offset(+Succ,+Offset)}{circuit_offset/2!gfd}{../bips/lib/gfd/circuit_offset-2.html}. 815 816\item[\biptxtrefni{circuit(+Succ,++CostMatrix,?Cost)}{circuit/3!gfd}{../bips/lib/gfd/circuit-3.html}] 817Constrains elements in Succ to form a Hamiltonian circuit, with Cost 818being the cost of the circuit, based on the edge cost matrix CostMatrix. 819A version allowing constant offsets is 820\biptxtrefni{circuit_offset(+Succ,+Offset,++CostMatrix,?Cost)}{circuit_offset/4!gfd}{../bips/lib/gfd/circuit_offset-4.html}. 821 822\item[\biptxtrefni{circuit(+Succ,++CostMatrix,+ArcCosts,?Cost)}{circuit/4!gfd}{../bips/lib/gfd/circuit-4.html}] 823Constrains elements in Succ to form a Hamiltonian circuit. ArcCosts 824are the costs of the individual hops, and Cost their sum, 825based on the edge cost matrix CostMatrix. 826A version with constant offsets is available as 827\biptxtrefni{circuit_offset(+Succ,+Offset,++CostMatrix,+ArcCosts,?Cost)}{circuit_offset/5!gfd}{../bips/lib/gfd/circuit_offset-5.html}, 828 829\item[\biptxtrefni{ham_path(?Start,?End,+Succ)}{ham_path/3!gfd}{../bips/lib/gfd/ham_path-3.html}] 830Constrains elements in Succ to form a Hamiltonian path from Start to End. 831A version with constant offsets is available as 832\biptxtrefni{ham_path_offset(?Start,?End,+Succ,+Offset)}{ham_path_offset/4!gfd}{../bips/lib/gfd/ham_path_offset-4.html}. 833 834\begin{sloppypar} 835\item[\biptxtrefni{ham_path(?Start,?End,+Succ,++CostMatrix,?Cost)}{ham_path/5!gfd}{../bips/lib/gfd/ham_path-5.html}] 836Constrains elements in Succ to form a Hamiltonian path from Start to End, 837with Cost being the cost of the path, based on the edge cost matrix CostMatrix. 838A version with constant offsets is available as 839\biptxtrefni{ham_path_offset(?Start, ?End, +Succ, +Offset, ++CostMatrix, ?Cost)}{ham_path_offset/6!gfd}{../bips/lib/gfd/ham_path_offset-6.html}. 840 841\item[\biptxtrefni{ham_path(?Start,?End,+Succ,++CostMatrix,+ArcCosts,?Cost)}{ham_path/6!gfd}{../bips/lib/gfd/ham_path-6.html}] 842Constrains elements in Succ to form a Hamiltonian path from Start to End. 843ArcCosts are the costs of the individual hops, and Cost their sum, 844based on the edge cost matrix CostMatrix. 845A version with constant offsets is available as 846\biptxtrefni{ham_path_offset(?Start, ?End, +Succ, +Offset, ++CostMatrix, +ArcCosts, ?Cost)}{ham_path_offset/7!gfd}{../bips/lib/gfd/ham_path_offset-7.html}. 847 848\item[\biptxtrefni{inverse(+Succ,+Pred)}{inverse/2!gfd}{../bips/lib/gfd/inverse-2.html}] 849Constrains elements of Succ to be the successors and 850Pred to be the predecessors of nodes in a digraph. A version with offsets 851is also available: 852\biptxtrefni{inverse(+Succ,+SuccOffset,+Pred,+PredOffset)}{inverse/4!gfd}{../bips/lib/gfd/inverse-4.html}. 853\end{sloppypar} 854 855\end{description} 856 857\subsubsection{Extensional constraints} 858These are ``user defined constraints'' (also known as ad-hoc 859 constraints), i.e. the allowable tuples of values for a 860collection of domain variables is defined as part of the constraint. These 861predicate differs in the way the allowable values are specified. 862 863\begin{description} 864\item[\biptxtrefni{regular(+Vars, ++RegExp)}{regular/2!gfd}{../bips/lib/gfd/regular-2.html}] 865Constrains Vars' solutions to conform to that defined in the regular expression RegExp. 866 867\item[\biptxtrefni{table(+Vars, ++Table)}{table/2!gfd}{../bips/lib/gfd/table-2.html}] 868Constrain Vars' solutions to be those defined by the tuples in Table. 869The variant 870\biptxtrefni{table(+Vars, ++Table, +Option)}{table/3!gfd}{../bips/lib/gfd/table-3.html} 871allows the specification of the algorithm used. 872 873\item[\biptxtrefni{extensional(+Vars, ++Transitions, +Start, +Finals)}{extensional/4!gfd}{../bips/lib/gfd/extensional-4.html}] 874Constrain Vars' solutions to conform to the finite-state 875automaton specified by Transitions with start state Start and final states Finals. 876 877\end{description} 878 879\subsubsection{Other constraints} 880 881Constraints that don't fit into the other categories. 882 883\begin{description} 884 885\item[\biptxtrefni{bool_channeling(?Var, +DomainBools, +Min)}{bool_channeling/3!gfd}{../bips/lib/gfd/bool_channeling-3.html}] 886Channel the domain values of Vars to the 0/1 boolean variables in DomainBools. 887 888\item[\biptxtrefni{integers(+Vars)}{integers/1!gfd}{../bips/lib/gfd/integers-1.html}] 889Pseudo constraint (i.e. no constraint will be posted in Gecode): 890Vars' domain is the integer numbers (within default bounds). 891 892\end{description} 893 894%---------------------------------------------------------------------- 895\section{Search Support} 896%---------------------------------------------------------------------- 897 898GFD allows search to be performed in two ways: 899completely encapsulated in the external Gecode solver, or 900in {\eclipse}, supported by GFD's variable selection 901and value choice predicates. 902 903Additionally, GFD support various search facilities of Gecode that is 904not directly supported by IC. These are described in section~\ref{addsearch}. 905 906\subsection{Performing search completely inside Gecode} 907\label{searcheng} 908Search can be performed in Gecode using one of its search engines. 909In this 910case, the search to produce a solution appears as an atomic step at 911the {\eclipse} level, and backtracking into the search will produce the next 912solution (or fail if there are none), again as an atomic step. 913 914This direct interface to Gecode's search engines is provided by 915\biptxtrefni{gfd:search/6}{search/6!gfd}{../bips/lib/gfd/search-6.html}, 916and uses a syntax similar to that of the generic search/6 predicates 917(in {\tt lib(gfd_search)} (see below), {\tt lib(ic)} and {\tt lib(fd_search)}). 918 919As the search is performed in Gecode, it should be more efficient than doing 920the search in \eclipse, where the system has to repeatedly switch between 921Gecode and {\eclipse} when doing the search. As the search is a single atomic 922step from the {\eclipse} level, it is not suitable if your code needs to 923interact with the search, e.g. if you are using constraints defined at the 924{\eclipse} level, and/or if you are using other solvers during the search. 925 926On the other hand, GFD's search/6 is less flexible than the generic search 927-- you can only use the predefined variable 928selection and value choice methods, i.e. you cannot provide user-defined 929predicates for the Select and Choice arguments. 930 931The search engine to use is specified by the Method argument in search/6. 932One method provided by Gecode is bb_min -- finding a minimal solution using 933branch-and-bound, which is not provided by the generic search. 934 935Instead, branch-and-bound in {\eclipse} is provided by {\tt lib(branch_and_bound)}, which can 936be used with generic search's {\tt search/6} to provide a similar functionality as 937the {\tt bb_min} method of GFD's {\tt search/6}. The {\eclipse} branch-and-bound is more 938flexible, but is likely to be slower. Note that {\tt lib(branch_and_bound)} can 939be used in combination with GFD's search/6, but this is probably not useful 940unless you are doing some search in your own code in addition to that done by 941search/6, or if you want to see the non-optimal solutions generated by the 942search. 943 944 945There are some differences in how search is performed by Gecode and generic 946search; 947the most significant is that all the built-in choice-operators of the generic 948search library make repeated choices on one variable until it becomes ground, 949before proceeding and selecting the next variable. Gecode's built-in 950strategies on the other hand always interleave value choices with variable 951selection. 952 953Other differences from generic search are: 954\begin{itemize} 955 956\item the partial search methods of generic search are not supported. 957Instead, restart-based search are supported as search methods. This is 958discussed in section~\ref{restartsearch}. 959\item Lightweight Dynamic Symmetry Breaking is supported natively 960(section~\ref{ldsb}). 961\item when two or more variables can be selected by the variable selection 962method, tie-breaking with a different method can be used to chose between 963these variables.. 964\item there are some differences in the available variable and value 965selection methods. Most importantly, variable selection methods based 966on two dynamic measure of constraint propagations are available. This 967is discussed in section~\ref{dynmeasure}. 968\item parallel search is supported. 969\end{itemize} 970 971Here is the N-Queens example using GFD's \texttt{search/6}: 972\begin{quote} 973\begin{verbatim} 974:- lib(gfd). 975 976queens_list(N, Board) :- 977 length(Board, N), 978 Board :: 1..N, 979 (fromto(Board, [Q1|Cols], Cols, []) do 980 ( foreach(Q2, Cols), param(Q1), count(Dist,1,_) do 981 Q2 #\= Q1, 982 Q2 - Q1 #\= Dist, 983 Q1 - Q2 #\= Dist 984 ) 985 ), 986 search(Board, 0, input_order, indomain_min, complete, []). 987\end{verbatim} 988\end{quote} 989 990 991\subsection{Search in {\eclipse} using GFD primitives\label{searchgfd}} 992 993The built-in Gecode search is appropriate when the problem consists 994exclusively of GFD-variables and GFD-library-constraints, and when the 995built-in search methods and search heuristics are sufficient to solve 996the problem. 997 998As soon as any user-defined constraints or any other {\eclipse} 999solvers are involved, then the top-level search control should be 1000written in \eclipse, in order to allow non-gfd propagators to execute 1001between the labelling steps. Also the implementation of problem-specific 1002search heuristics will usually make it necessary to lift the top-level 1003search control to the {\eclipse} level. 1004To make this possible, GFD provides primitives to support variable 1005selection and value choice heuristics. 1006 1007\begin{description} 1008\item[\biptxtrefni{gfd:select_var(-X, +Collection, -Rest, ++Arg, ++Select)}{select_var/5!gfd}{../bips/lib/gfd/select_var-5.html}] 1009Select a domain variable from Collection according to one of Gecode's 1010pre-defined selection criteria. These include criteria not available in 1011other {\eclipse} solvers, like accumulated failure count. 1012 1013\item[\biptxtrefni{gfd_search:delete(-X, +Collection, -Rest, ++Arg, ++Select)}{delete/5!gfd}{../bips/lib/gfd_search/delete-5.html}] 1014Select (and remove) a domain variable from Collection. This is the 1015generic implementation, (compatible with IC and FD solvers), providing 1016a different choice of selection options, but likely to be less 1017efficient than select_var/5. 1018 1019\item[\biptxtrefni{gfd:try_value(?Var, ++Method)}{try_value/2!gfd}{../bips/lib/gfd/try_value-2.html}] 1020This value choice predicate supports both Gecode-style binary choice and 1021generic search's multi-way choice on the domain of a variable, 1022according to Method. 1023The binary-choice methods create two search alternatives, which reduce the variable domain 1024in complementary ways. Because the variable is not necessarily instantiated, 1025this must be combined with a variable selection method that does not delete 1026the selected variable, such as select_var/5. 1027 1028The multi-way choice methods make repeated choices on one variable as 1029gfd_search's indomain/2. 1030 1031\item[\biptxtrefni{gfd:indomain(?Var)}{indomain/1!gfd}{../bips/lib/gfd/indomain-1.html}] 1032Instantiate Var to elements in its domain, using a default method. 1033 1034\item[\biptxtrefni{gfd_search:indomain(?Var, ++Method)}{indomain/2!gfd}{../bips/lib/gfd_search/indomain-2.html}] 1035A flexible way to nondeterministically assign values to finite domain 1036variables according to Method. On success, Var is always instantiated. 1037This is the generic implementation 1038(compatible with IC and FD solvers), providing a different choice of methods, 1039and likely to be less efficient than try_value/5. 1040\end{description} 1041 1042A simple search using GFD's primitives can be defined in the following way: 1043\begin{quote} 1044\begin{verbatim} 1045labeling(Vars, Select, Choice) :- 1046 ( select_var(V, Vars, Rest, 0, Select) -> 1047 try_value(V, Choice), 1048 labeling(Rest, Select, Choice) 1049 ; 1050 true 1051 ). 1052\end{verbatim} 1053\end{quote} 1054For binary choice methods of try_value/2, the search will 1055mimic Gecode's built-in search (where a variable selection step is usually 1056interleaved with a binary choice on the variable domain). 1057 1058For multi-way choice methods of try_value/2, 1059(possibly several) value choices on a variable are made until the 1060variable is ground, before proceeding to select the next variable: On 1061backtracking to the try_value/2, alternative values for the variable 1062will be tried. This mimics the behaviour of gfd_search's indomain/2, 1063but try_value/2 is likely to be more efficient as it is specifically 1064tailored for GFD. 1065 1066The same effect can be achieved by using select_var/5 and try_value/2 1067together with the generic 1068\biptxtrefni{gfd_search:search/6}{search/6!gfd_search}{../bips/lib/gfd_search/search-6.html} 1069predicate: 1070\begin{quote} 1071\begin{verbatim} 1072gfd_search:search(Vars, 0, 1073 select_var(Select), try_value(Choice), complete, []) 1074\end{verbatim} 1075\end{quote} 1076\begin{sloppypar} 1077Several selection methods predicates that are designed to be used with 1078generic search, are provided: 1079\bipref{max_regret_lwb/2}{../bips/lib/gfd/max_regret_lwb-2.html}, \bipref{max_regret_upb/2}{../bips/lib/gfd/max_regret_upb-2.html}, \bipref{max_weighted_degree/2}{../bips/lib/gfd/max_weighted_degree-2.html}, 1080\bipref{max_weighted_degree_per_value/2}{../bips/lib/gfd/max_weighted_degree_per_value-2.html}, \bipref{most_constrained_per_value/2}{../bips/lib/gfd/most_constrained_per_value-2.html}. 1081These allow selection methods supported in GFD but not in generic search 1082to be used with gfd_search:search/6. 1083\end{sloppypar} 1084 1085For even more complex user-defined heuristics, various properties associated 1086with a variable and its domain can be obtained using predicates described 1087in section~\ref{gfdvarquery}. Note that these include properties that are not 1088available in 1089\eclipse's solvers, such as weighted degree (a.k.a. accumulated failure count). 1090 1091\subsection{GFD specific search support\label{addsearch}} 1092 1093GFD supports various search support facilities that are not found in 1094\eclipse. This section discuss some of these features in more detail. 1095 1096\subsubsection{Dynamic measure of propagation\label{dynmeasure}} 1097 1098Gecode supports two ways of dynamically measuring constraint propagation for 1099variables. These measures can be used in variable selection heuristics 1100that 'learn' from the actual propagations of the program. Such 1101heuristics may perform better, and is particularly suited to Gecode's 1102interleaving of variable selection and value choice. The two measures are: 1103\begin{description} 1104\item[weighted degree] Known as Accumulated Failure Count in Gecode. 1105Count of the number of failures in 1106constraints associated with the variable. Count is updated after each 1107propagation failure. 1108\item[activity] Count of the number of domain 1109reduction on the variable during propagation. Count is updated after each 1110propagation. 1111\end{description} 1112 1113As the search normally starts immediately after modelling, there would be 1114very little constraint propagation, so both measures 1115will not have much information to be used for variable selection. 1116One way to work around this is to assign initial 1117values to the counts, to give reasonable start values. This is the reason 1118that, by default, the initial value for weighted degree of a variable is set 1119to its degree. 1120 1121For {\bf gfd:search/6}, an alternative to setting the initial values is to 1122use the \texttt{tiebreak/1} option to use a tie-breaking 1123selection method. Another alternative is to use restart-based search, with 1124the initial search acting as a 'probe' to obtain good values for the measures 1125for the 'real' search. 1126 1127Gecode also supports a {\it decay\/} factor for both measures, where the 1128count values can be reduced by the decay factor if their count is not 1129incremented when the measure is updated: The idea is to favour those 1130variables that are involved in the propagation most recently. 1131 1132GFD supports setting of both the initial values and the decay factor for 1133variable selection methods that uses weighted 1134degree and activity via parameters in 1135\biptxtrefni{gfd:search/6}{search/6!gfd}{../bips/lib/gfd/search-6.html} and 1136\bipref{select_var/5}{../bips/lib/gfd/select_var-5.html}. 1137 1138\begin{sloppypar} 1139Weighted degree is computed for all variables, and can be obtained with 1140\bipref{get_weighted_degree/2}{../bips/lib/gfd/get_weighted_degree-2.html}. It can be re-initialised using 1141\bipref{init_weighted_degree/1}{../bips/lib/gfd/init_weighted_degree-1.html}. The decay factor can be obtained by 1142\bipref{get_weighted_degree_decay/1}{../bips/lib/gfd/get_weighted_degree_decay-1.html} and set with 1143\bipref{set_weighted_degree_decay/1}{../bips/lib/gfd/set_weighted_degree_decay-1.html}. 1144\end{sloppypar} 1145 1146Due to the way activity is implemented by Gecode, the use of activity in GFD 1147is limited to the variable selection methods for {\bf search/6} and 1148{\bf select_var/5}. 1149 1150Note also activity is computed for recomputation as well as normal computation, 1151so changing the amount of recomputation (by changing the cloning distance) 1152can change the activity counts for the same problem, thus affecting the 1153search if an activity based selection method is used. 1154 1155\subsubsection{Restart-based search methods\label{restartsearch}} 1156 1157Restart is a technique supported by Gecode, 1158where the current search is abandoned and restarted from the root, 1159allowing the restarted search to make different branching choices, 1160and send the search to a different part of the search space. 1161This is useful if the old search was not fruitful in getting 1162a solution, so exploring a different part of the search space may prove 1163better than continuing the old search. 1164 1165The restarted search will only be different from the old search 1166if different branching choices can be made, e.g. if at least some of these 1167choices are random, or if some of the choices have a learning component, 1168e.g. variable selection methods that uses activity or weighted degree. 1169 1170The branching choices can also be different if the restarted search 1171is more constrained. Gecode supports no-goods learning, an automatic 1172technique for remembering failures in the old search, and posting 1173'no-good' constraints for the new search that prevent the search from 1174repeating these failures. 1175 1176Restart-based search is not complete, and is mostly useful for finding a 1177single solution, rather than many solutions. 1178 1179GFD provides two search methods for \biptxtrefni{gfd:search/6} 1180{search/6!gfd}{../bips/lib/gfd/search-6.html} that are restart-based: 1181\texttt{restart} and \texttt{restart_min}. Both methods 1182will only find one solution. 1183 1184\subsubsection{Lightweight Dynamic Symmetry Breaking} 1185\label{ldsb} 1186Lightweight Dynamic Symmetry Breaking (LDSB) is a symmetry breaking 1187technique implemented for Gecode's search engines, and for IC in \eclipse 1188with \texttt{lib(ldsb)}. Currently, GFD supports LDSB for 1189\biptxtrefni{gfd:search/6}{search/6!gfd} 1190{../bips/lib/gfd/search-6.html} only, as \texttt{lib(ldsb)} is written 1191for IC only. 1192 1193LDSB is supported in {\bf gfd:search/6} by the \texttt{ldsb_sym/1} option, 1194where the symmetries for the problem are specified, and can be used 1195for all value choice method. This is unlike 1196\texttt{lib(ldsb)}, where LDSB is supported by separate predicates, 1197including predicates to perform value choice, rather than being integrated 1198into the generic search 1199 1200The syntax for the symmetry specifications follow those used in 1201\texttt{lib(ldsb)}. In particular, the definition of rows and columns 1202for a 2-D matrix is the one used in \eclipse and in 1203\texttt{lib(ldsb)}, but not in Gecode (where the definitions are reversed). 1204That is, the matrix are organised as collection of rows. 1205 1206While LDSB is not currently available for GFD at the \eclipse level, Symmetry 1207breaking is available via SBDS 1208(Symmetry Breaking During Search) in \texttt{lib(gfd_sbds)}. 1209 1210\section{User defined constraints and solver co-operation} 1211Like IC and FD solvers, GFD has facilities to allow the extension of the 1212solver library so that GFD can co-operate with other solvers in solving a 1213problem, and also to allow the user to define their own constraints at the {\eclipse} 1214level. This is achieved by providing a suspension list with the gfd attribute, 1215which allows for the data-driven programming needed by solver co-operation and 1216constraint propagation, and a set of low-level predicates to process, 1217 query and modify the domain of problem variables. 1218 1219These facilities allow solver co-operation and user-defined 1220constraints propagation at the {\eclipse} level, and not within Gecode directly. 1221So, search then must be done at the {\eclipse} level, i.e. not through Gecode's 1222search engines. The performance of constraints defined in this way will very 1223likely be less efficient than implementing the constraints directly in Gecode. 1224 1225\subsection{The {\it gfd\/} attribute} 1226 1227The GFD attribute is a meta-term which is attached to all GFD problem variables. 1228Many of the fields of the attribute are used for implementing the interface to 1229Gecode, and are of no interest to the user. The only field of interest is the 1230{\tt any} field, which is for the {\it any\/} suspension list, which is woken on 1231any change in the domain of the variable: 1232 1233\begin{verbatim} 1234gfd{ 1235 .... 1236 any:SuspAny, 1237 .... 1238} 1239\end{verbatim} 1240 1241The {\it any\/} suspension list has the same waking behaviour as the 1242{\it any\/} suspension 1243list of FD, and is sufficient for implementing constraints -- the other 1244suspension lists found in IC and FD are specialisations of the {\it any\/} 1245suspension list, in that they provide more precise waking conditions. 1246The reason that 1247only one suspension list is provided by GFD is to minimise the overhead in 1248normal use of the solver. 1249 1250 1251In addition to waking the attribute's {\it any\/} suspension list, the 1252{\it constrained\/} 1253suspension list will also be woken when a GFD variable's domain is changed, 1254and the {\it inst\/} suspension list will be woken if the variable is bound. 1255 1256The suspension lists allow constraint propagation to be implemented at the 1257{\eclipse} level, which is distinct from the propagation of ``native'' Gecode 1258constraints, where each propagation phase (and in the case of using the 1259search engine, the whole search) is an atomic step at the {\eclipse} level. 1260This has a similar effect to running all ``native'' propagations 1261at a higher (more urgent) priority. 1262 1263As only the {\it any\/} suspension list is provided, some rewriting of existing 1264user-defined constraints for IC and FD may be needed when such code is ported 1265for GFD. 1266 1267\subsection{Modifying variable domains} 1268 1269Like IC, GFD provides a set of predicates to modify the domain of GFD 1270variables to support the writing of new constraints. Unlike normal constraints, 1271no Gecode level propagation or waking of other suspended goals (such as 1272scheduled by other {\eclipse} level constraints) occurs with these predicates. 1273 1274With the exception of 1275\bipref{impose_bounds/3}{../bips/lib/gfd/impose_bounds-3.html} none of 1276the goals call \bipref{wake/0}{../bips/kernel/suspensions/wake-0.html}, so 1277the programmer is free to do so at a convenient time. 1278 1279Some of these predicates are provided for compatibility with IC, as these 1280predicates have the same name and similar semantics to their IC counter-parts 1281(including the waking behaviour for {\tt impose_bounds/3}). 1282However, due to the difference in the way domains are represented in IC and 1283Gecode, these predicates may be inefficient for use with Gecode, particularly 1284if you need to modify multiple variables and/or multiple domain values. 1285The predicates with names that begin with {\tt gfd_vars} are specific 1286to GFD and are designed to be more efficient than their IC compatible 1287counter-parts. 1288 1289The ``native'' primitives are: 1290 1291\begin{description} 1292\item[\biptxtrefni{gfd_vars_exclude(+Vars,+Excl)}{gfd_vars_exclude/2!gfd}{../bips/lib/gfd/gfd_vars_exclude-2.html}] 1293Exclude the element Excl from the domains of Vars. 1294 1295\item[\biptxtrefni{gfd_vars_exclude_domain(+Vars, ++Domain)}{gfd_vars_exclude_domain/2!gfd}{../bips/lib/gfd/gfd_vars_exclude_domain-2.html}] 1296Exclude the values specified in Domain from the domains of Vars. 1297 1298\item[\biptxtrefni{gfd_vars_exclude_range(+Vars, +Lo, +Hi)}{gfd_vars_exclude_range/3!gfd}{../bips/lib/gfd/gfd_vars_exclude_range-3.html}] 1299Exclude the elements Lo..Hi from the domains of Vars. 1300 1301\item[\biptxtrefni{gfd_vars_impose_bounds(+Vars, +Lo, +Hi)}{gfd_vars_impose_bounds/3!gfd}{../bips/lib/gfd/gfd_vars_impose_bounds-3.html}] 1302Update (if required) the bounds of Vars. 1303 1304\item[\biptxtrefni{gfd_vars_impose_domain(+Vars,++Domain)}{gfd_vars_impose_domain/2!gfd}{../bips/lib/gfd/gfd_vars_impose_domain-2.html}] 1305Restrict (if required) the domain of Var to the domain specified in Domain. 1306 1307\item[\biptxtrefni{gfd_vars_impose_max(+Vars,+Bound)}{gfd_vars_impose_max/2!gfd}{../bips/lib/gfd/gfd_vars_impose_max-2.html}] 1308Update (if required) the upper bounds of Vars. 1309 1310\item[\biptxtrefni{gfd_vars_impose_min(+Vars,+Bound)}{gfd_vars_impose_min/2!gfd}{../bips/lib/gfd/gfd_vars_impose_min-2.html}] 1311Update (if required) the lower bounds of Vars. 1312 1313\end{description} 1314 1315The IC-compatible primitives are: 1316 1317\begin{description} 1318\item[\biptxtrefni{exclude(?Var, +Excl)}{exclude/2!gfd}{../bips/lib/gfd/exclude-2.html}] 1319Exclude the element Excl from the domain of Var. 1320 1321\item[\biptxtrefni{exclude_range(?Var, +Lo, +Hi)}{exclude_range/3!gfd}{../bips/lib/gfd/exclude_range-3.html}] 1322Exclude the elements Lo..Hi from the domain of Var. 1323 1324\item[\biptxtrefni{impose_bounds(?Var,+Lo,+Hi)}{impose_bounds/3!gfd}{../bips/lib/gfd/impose_bounds-3.html}] 1325Update (if required) the bounds of Var. 1326 1327\item[\biptxtrefni{impose_domain(?Var,++Domain)}{impose_domain/2!gfd}{../bips/lib/gfd/impose_domain-2.html}] 1328Restrict (if required) the domain of Var to the domain of DomVar. 1329 1330\item[\biptxtrefni{impose_max(?Var, +Hi)}{impose_max/2!gfd}{../bips/lib/gfd/impose_max-2.html}] 1331Update (if required) the upper bound of Var. 1332 1333\item[\biptxtrefni{impose_min(?Var, +Lo)}{impose_min/2!gfd}{../bips/lib/gfd/impose_min-2.html}] 1334Update (if required) the lower bound of Var. 1335 1336\end{description} 1337 1338 1339\subsection{Variable query predicates} 1340\label{gfdvarquery} 1341 1342These predicates are used to retrieve various properties of a domain variable 1343(and usually work on integers as well). 1344 1345In most cases, the property is obtained directly from Gecode. Many of these 1346properties are useful for selecting a variable for labelling. Here are some 1347examples: 1348 1349\begin{description} 1350\item[\biptxtrefni{get_bounds(?Var, -Lo, -Hi)}{get_bounds/3!gfd}{../bips/lib/gfd/get_bounds-3.html}] 1351Retrieves the current bounds of Var. 1352 1353\item[\biptxtrefni{get_constraints_number(?Var, -Number)}{get_constraints_number/2!gfd}{../bips/lib/gfd/get_constraints_number-2.html}] 1354Returns the number of propagators attached to the Gecode variable representing Var. 1355 1356\item[\biptxtrefni{get_delta(?Var, -Width)}{get_delta/2!gfd}{../bips/lib/gfd/get_delta-2.html}] 1357Returns the width of the interval of Var. 1358 1359\item[\biptxtrefni{get_domain(?Var, -Domain)}{get_domain/2!gfd}{../bips/lib/gfd/get_domain-2.html}] 1360Returns a ground representation of the current GFD domain of a variable. 1361 1362\item[\biptxtrefni{get_domain_size(?Var, -Size)}{get_domain_size/2!gfd}{../bips/lib/gfd/get_domain_size-2.html}] 1363Returns the number of elements in the GFD domain of Var. 1364 1365\item[\biptxtrefni{get_max(?Var,-Hi)}{get_max/2!gfd}{../bips/lib/gfd/get_max-2.html}] 1366Retrieves the current upper bound of Var. Similarly, \biptxtrefni{get_min/2)}{get_min/2!gfd}{../bips/lib/gfd/get_min-2.html} returns the lower bound. 1367 1368 1369\item[\biptxtrefni{get_median(?Var,-Median)}{get_median/2!gfd}{../bips/lib/gfd/get_median-2.html}] 1370Returns the median domain value of the GFD domain variable Var. 1371 1372\item[\biptxtrefni{get_regret_lwb(?Var, -Regret)}{get_regret_lwb/2!gfd}{../bips/lib/gfd/get_regret_lwb-2.html}] 1373Returns the regret value for the lower bound of Var. Similarly, \biptxtrefni{get_regret_upb/2}{get_regret_upb/2!gfd}{../bips/lib/gfd/get_regret_upb-2.html} 1374for the upper bound. 1375 1376\item[\biptxtrefni{get_weighted_degree(?Var,-WD)}{get_weighted_degree/2!gfd}{../bips/lib/gfd/get_weighted_degree-2.html}] 1377Returns the weighted degree (wdeg, accumulated failure count) of domain 1378variable Var. 1379 1380\item[\biptxtrefni{is_in_domain(+Val,?Var,[-Result])}{is_in_domain/2!gfd}{../bips/lib/gfd/is_in_domain-2.html}] 1381Succeeds iff Val is in the domain of Var. The \biptxtrefni{version}{is_in_domain/3!gfd}{../bips/lib/gfd/is_in_domain-3.html} with the \verb'+Result' argument 1382binds Result instead. 1383 1384 1385\item[\biptxtrefni{is_solver_var(?Term)}{is_solver_var/1!gfd}{../bips/lib/gfd/is_solver_var-1.html}] 1386Succeeds iff Term is an GFD domain variable. 1387\end{description} 1388 1389\section{Low-level control of Gecode computation} 1390This section gives some information on the low-level workings of GFD and how 1391to adjust it. This information is not needed for most users, and can be 1392skipped and consulted only when GFD is not behaving well with the user's 1393program. 1394 1395GFD is designed so that the user can write programs that will run with 1396 Gecode without knowing any details about Gecode or how GFD interfaces 1397 to it. However, GFD does provide some parameters to control its behaviour. 1398While the default settings should work well under most circumstances, some 1399understanding of the inner workings of GFD is needed to change this default 1400behaviour. 1401 1402\subsection{Recomputation and Cloning} 1403 1404 1405Gecode implements search using a recomputation and cloning model, 1406which is fundamentally different from the backtracking model of \eclipse. 1407When failure occurs, Gecode does not backtrack to a previous computation 1408state; instead, the previous state is recomputed. To reduce the amount 1409of recomputation, the computation state is {\it cloned\/} periodically 1410during execution, and the recomputation would start from the nearest 1411such cloned state rather than from the start. 1412 1413With GFD, when the search is done in Gecode (via GFD's 1414\biptxtrefni{search/6}{search/6!gfd}{../bips/lib/gfd/search-6.html}), the 1415recomputation and cloning is handled by Gecode. When the search is done 1416at the {\eclipse} level, GFD handles the recomputation and cloning automatically, 1417so that the user does not need to be aware of it. 1418 1419GFD will create clones of the Gecode state periodically, and when the 1420current Gecode computation state becomes invalid through {\eclipse} backtracking, 1421GFD will recompute the new state from the closest cloned state. 1422The frequency at which GFD create clones can be adjusted by the user -- 1423the more frequently clones are created, the more memory will be used, but 1424the cost of recomputation will be less. Cloning itself will take time, 1425and depends on the size of the state. Normally, the cost of cloning is 1426quite low, so GFD by default will clone frequently during search, as 1427this leads to faster execution times. However, if the program has a large 1428state (many variables and constraints), then frequent cloning may lead to 1429excessive memory consumption (and larger computation state will also be 1430more expensive to clone), and reducing the frequency of cloning may 1431improve performance. 1432 1433The frequency of cloning in GFD is controlled by the 1434\texttt{cloning_distance} parameter, which can be changed by 1435\bipref{gfd_set_default/2}{../bips/lib/gfd/gfd_set_default-2.html} 1436(and the current value can be accessed with 1437\bipref{gfd_get_default/2}{../bips/lib/gfd/gfd_get_default-2.html}) 1438The \texttt{cloning_distance} specifies a threshold for the number of 1439changes GFD makes to the Gecode state before a clone is created. 1440Note that GFD does not create a clone simply when cloning_distance is 1441exceeded, as it only creates a new clone when the cloned state would 1442be the state just before a choice-point, so clones will normally only 1443be created during search phase of the user program. 1444 1445While it is not necessary for the user to specify the creation of a clone, 1446under very unusual circumstances -- when the \texttt{cloning_distance} is 1447set very high -- GFD may not produce a clone at the right place. So 1448\bipref{gfd_update/0}{../bips/lib/gfd/gfd_update-0.html} is provided to force the creation of a clone. 1449The expected usage is to call this predicate just before search starts. 1450For example, \texttt{labeling/3} can be written as: 1451 1452\begin{quote} 1453\begin{verbatim} 1454labeling(Vs, Select, Choice) :- 1455 gfd_update, 1456 labeling1(Vs, Select, Choice, _). 1457 1458labeling1(Vs, Select, Choice, VsH) :- 1459 ( select_var(V, Vs, 0, Select, VsH) -> 1460 indomain(V, Choice), 1461 labeling1(Vs, Select, Choice, VsH) 1462 ; 1463 true 1464 ). 1465 1466\end{verbatim} 1467\end{quote} 1468Calling \texttt{gfd_update} before calling \texttt{labeling1} ensures that 1469GFD will only recompute inside the search. 1470 1471\section{Main differences between GFD and IC} 1472 1473Although GFD was designed to be code compatible with IC in terms of 1474syntax, there are still some unavoidable differences, because of differences 1475between Gecode and IC. In addition, Gecode is 1476implemented using very different implementation techniques from IC, and 1477although such differences are mostly not visible in terms of syntax, there 1478are still semantics and performance implications. 1479 1480The main visible differences between GFD and IC are: 1481\begin{itemize} 1482 \item Real interval arithmetic and variables are not supported in GFD. 1483 1484 \item Domain variables always have finite integer bounds, and the maximum 1485 bounds are 1486 determined by Gecode. Like FD, default finite bounds are given to 1487 domain variables that do not have explicit bounds, and the default 1488 settings for these bounds are below the maxima that Gecode allows. 1489 1490 \item Constraint propagation is performed within Gecode, and each propagation 1491 phase is atomic at the {\eclipse} level. Posting of constraints and 1492 propagation of their consequences are separate in Gecode. GFD uses a 1493 demon suspended goal to perform the propagation: after the posting 1494 of any constraint (and other changes to the problem that need 1495 propagation), this suspended goal is scheduled and woken. When the 1496 woken goal is executed, propagation is performed. 1497 1498 \item All constraints can be called from the gfd module, and in 1499 addition, some constraints can be called from modules that specify 1500 the consistency level: gfd_gac (generalised arc consistency, also 1501 known as domain consistency), gfd_bc (bounds consistency), gfd_vc (value 1502 consistency (naive)). The gfd module versions use the 1503 default consistency 1504 defined for the constraint by Gecode. These consistency levels map 1505 directly to those defined in Gecode for the constraints. 1506 1507 \item gfd:search/6 interfaces to Gecode's search-engines, where the 1508 entire search is performed in Gecode, and the whole search appears 1509 atomic at the {\eclipse} level. 1510 1511 \item The suspension lists supported by GFD are different from IC. 1512 Currently, only the 'any' suspension list (for {\em any} changes to the 1513 variable's domain) found in FD but not IC, is supported. Note that 1514 the GFD constraints are implemented in Gecode directly, and therefore 1515 do not use GFD's suspension lists. 1516 1517 \item Constraint and integer expressions are designed to be compatible with 1518 IC's, and the arithmetic operators and logical connectives supported 1519 by Gecode are supported, and these largely overlaps those of IC's. 1520 In addition, ``functional'' (where the last argument is a domain 1521 variable) and reified constraints can appear in expressions without the 1522 last argument, as in IC. 1523 1524 The differences from IC are: 1525 \begin{itemize} 1526 \item User defined constraints are not allowed in expressions. 1527 1528 \item The operators and connectives supported are those supported by 1529 Gecode, so most of the IC operators for real arithmetic are not 1530 supported. 1531 1532 %%% Is this correct? 1533 \item Only inlined arithmetic (sub-)expressions are allowed between 1534 logical connectives. 1535 1536 \item GFD expressions are broken down into sub-expressions and 1537 constraints that are supported natively by Gecode, where the additional 1538 sub-expressions are replaced by a domain variable in the original 1539 expression. These domain variables are given the default bounds. 1540 IC does something similar, but what constitutes additional sub-expressions 1541 will differ between GFD and IC, and the variables substituted 1542 for the sub-expressions would be given infinite bounds in IC. 1543 1544 \end{itemize} 1545 1546\item GFD variables cannot be copied to non-logical storage, and an error is 1547raised if a GFD variable occurs in a term that is being copied for such purpose 1548(assert, non-logical variables, shelves, etc.). Note that this means that 1549GFD is incompatible with Propia, as this library makes use of non-logical 1550storage. 1551\end{itemize} 1552 1553%HEVEA\cutend 1554