home *** CD-ROM | disk | FTP | other *** search
/ NetNews Usenet Archive 1992 #19 / NN_1992_19.iso / spool / comp / lang / prolog / 1639 < prev    next >
Encoding:
Text File  |  1992-09-02  |  14.2 KB  |  313 lines

  1. Newsgroups: comp.lang.prolog
  2. Path: sparky!uunet!haven.umd.edu!darwin.sura.net!wupost!gumby!destroyer!ubc-cs!fornax!gregory
  3. From: gregory@cs.sfu.ca (Gregory Sidebottom)
  4. Subject: The Echidna CLP language
  5. Message-ID: <1992Sep2.174033.15627@cs.sfu.ca>
  6. Organization: CSS, Simon Fraser University, Burnaby, B.C., Canada
  7. Date: Wed, 2 Sep 1992 17:40:33 GMT
  8. Lines: 303
  9.  
  10. My posting about the Echidna CLP language (and how it relates to
  11. scheduling) generated quite a lot of interest.  To all that asked me
  12. to send them papers, there will be a delay while the proof is made
  13. into a technical report (with covers and everything).  In the
  14. meantime, I thought I should post this extended abstract about
  15. Echidna's numeric constraint processing capabilities.  Enjoy!
  16.  
  17. -----------------------------------8<--------------------------------------
  18.  
  19.     Hierarchical Arc Consistency Applied to Numeric Processing in
  20.   Constraint Logic Programming (Extended Abstract, Email Version)(1)
  21.                    
  22.            Greg Sidebottom and William S. Havens(2)
  23.  
  24.                1.  Introduction
  25.  
  26. There have been many proposals for adding sound implementations of
  27. numeric processing to Prolog.  Many constraint logic programming (CLP)
  28. languages use symbolic constraint solving techniques for linear
  29. constraints.  CHIP and BNR Prolog use consistency and case analysis
  30. algorithms (Mackworth, 1977) for solving constraints.  This paper
  31. describes an approach to real numeric constraint processing which has
  32. been implemented in Echidna, a new CLP language.  Like CHIP and BNR
  33. Prolog, Echidna uses consistency algorithms which can actively process
  34. a wide variety of numeric constraints.  The key difference is that
  35. Echidna implements domains which are disconnected sets using a
  36. hierarchical data structure and exploits this structure using a
  37. hierarchical arc consistency algorithm (Mackworth, Mulder and Havens,
  38. 1985) which is specialized for numeric constraints.  The hierarchial
  39. datastructure makes it possible to represent disjunctive information
  40. directly.
  41.  
  42. Echidna can handle such general systems of constraints because it uses
  43. partial consistency algorithms.  Normally, consistency algorithms
  44. compute solutions to sets of constraints.  Partial consistency
  45. algorithms approximate the set of solutions with a super-set.  Good
  46. partial consistency algorithms compute a super-set which is only
  47. slightly bigger than the actual set of solutions for a substantially
  48. reduced cost.  Echidna's algorithms are easily parameterized to
  49. compute arbitrarily close to the actual set of solutions.
  50.  
  51.        2.  Numeric Constraints in the Echidna Language
  52.  
  53. This section describes the particular extensions to Edinburgh syntax
  54. Prolog which are relevant to numeric constraint processing and takes
  55. some liberties with syntax.  Echidna provides domain constraints,
  56. equalities, inequalities, and disjunctions of inequalities on real
  57. numeric expressions.  A domain constraint is a unary constraint of the
  58. form 'X in Set' where X is a real valued variable and Set denotes the
  59. domain of X.  The Set in a domain constraint is specified by a finite
  60. union of real intervals.  Equalities and inequalities constrain real
  61. numeric expressions.  Expressions are built up from variables and real
  62. constant symbols using numeric function symbols(3).  Echidna also
  63. supports disjunctive inequalities constraints of the form 'C1 or C2'
  64. where C1 and C2 are inequalities.  For instance, Figure 1 gives an
  65. Echidna program for scheduling tasks using some of the relations on
  66. temporal intervals.  A task is represented by a term task(S, D) where
  67. S is the start time of the task and D is the duration of the task.
  68. The predicate, in(Task, SuperTask), is true if the interval for
  69. SuperTask contains the interval for Task.  NoOverlap(Task, Tasks) is
  70. true if Task overlaps with none of the tasks in the list Tasks.  It
  71. uses a disjunctive inequality constraint to make sure Task is either
  72. before or after each of the tasks in Tasks.  Schedule(Tasks,
  73. SuperTask) is true if all the tasks in the list Tasks are in SuperTask
  74. but no pair in Tasks overlap.
  75.  
  76.   in(task(S1, D1), task(S2, D2)) :-
  77.       S1 >= S2,
  78.       S1+D1 <= S2+D2.
  79.  
  80.   noOverlap(_, []).
  81.   noOverlap(task(S1, D1),
  82.              [task(S2,D2)|Tasks]):-
  83.       S1+D1<=S2 or S1>=S2+D2,
  84.       noOverlap(task(S1, D1),Tasks).  
  85.   schedule([], _).
  86.   schedule([Task | Tasks], SuperTask) :-
  87.       in(Task, SuperTask), 
  88.       noOverlap(Task, Tasks),
  89.       schedule(Tasks, SuperTask).
  90.  
  91.       Figure 1. An Echidna Program for scheduling tasks
  92.  
  93.            3.  Overview of Echidna's Implementation
  94.  
  95. Echidna programs are executed by an SLD-resolution theorem prover
  96. which incrementally constructs and maintains a constraint satisfaction
  97. problem (CSP).  A CSP consists of a set of variables, each associated
  98. with a domain of possible values; and a set of constraint relations on
  99. subsets of the variables which specify values to which those variables
  100. can simultaneously be assigned.  The notation D(X) is used to denote
  101. the domain of the variable X.  When a constraint is selected by the
  102. theorem prover, it is added to the CSP.  Echidna manipulates the CSP
  103. using two kinds of algorithms (Mackworth, 1977):
  104.  
  105. 1.  arc consistency is used to remove inconsistent values from the
  106. domains of variables participating in numeric constraints, and
  107.  
  108. 2.  case analysis is used to consider, alternatively, different halves
  109. of real variable domains.
  110.  
  111. If the arc consistency algorithm ever removes all values from a
  112. variable domain, the theorem prover backtracks using dependency
  113. backtracking (Havens, 1991).  Backtracking through a constraint
  114. consists of removing it from the CSP.
  115.  
  116. The case analysis algorithms implement a divide and conquer search for
  117. solutions to the CSP. The arc consistency algorithms are interleaved
  118. with the case analysis algorithms to help reduce the search space.
  119. The case analysis algorithm is accessed by the built in predicate
  120. split(Vars).  Split(Vars) repeatedly cycles through the list Vars of
  121. variables in a round robin fashion removing approximately half the
  122. values in each variable's domain.  Upon backtracking, split will
  123. restore half of a domain and remove the other half.  Currently, the
  124. number of times each variable in a list can be split is determined by
  125. a call to the built in predicate precision(Vars, Prec).
  126.  
  127.            4.  Numeric Hierarchical Arc Consistency
  128.  
  129. This section describes HACR, the hierarchical arc consistency
  130. algorithm Echidna uses for real numeric constraints.  We use the
  131. notation v(C) to denote the set of variables in the constraint C.  We
  132. assume the CSP is formulated as a directed hypergraph where variables
  133. are associated with nodes and each constraint C is a set of hyperarcs
  134. of the form (T, C) for each T in v(C).  T is called the target and the
  135. rest of the variables in v(C) are called sources.  Let C be constraint
  136. with v(C) = {X(1), X(2), I, X(k)}.  The notation pi(X(i),C) means the
  137. result of projecting the constraint C onto the variable Xi.  More
  138. formally,
  139.  
  140.   pi(X(i),C) =
  141.     {a(i) in D(X(i)) |
  142.          there exists (a(1),...,a(i-1),a(i+1),...,a(k)) in
  143.                D(X(1))x...xD(X(i-1))xD(X(i+1))x...xD(X(k)
  144.                      such that C(a(1),...,a(k))}.  
  145.  
  146. Full arc consistency algorithms terminate with D(T) = pi(T,C) for
  147. every hyperarc (T, C) which formulates the CSP.  Partial arc
  148. consistency algorithms set D(T) to some efficiently computable
  149. superset of pi(T,C).  HACR is a partial arc consistency algorithm
  150. based on the full hierarchical arc consistency algorithm HAC
  151. (Mackworth, Mulder and Havens, 1985).  Both are similar to AC-3
  152. (Mackworth, 1977), but they use different arc revision algorithms
  153. which operate on hierachically structured domains.  HACR represents a
  154. domain such as [1, 1.875] U [3.75, 4] using the structure shown in
  155. figure 2 (in the hardcopy version of this abstract).  The root's
  156. interval contains the domain and the intervals for the two children of
  157. an node are roughly the lower and upper halves of the their parent's
  158. domain.  The relationship between a parent and its children's is
  159.  
  160.  
  161.                 [x, y]
  162.                   /\
  163.                  /  \
  164.               [x,mid(x,y)]  (mid(x,y),y]
  165.                    
  166. where x < mid(x,y) < y.  The types of boundary (open or closed)
  167. associated with x and y in the children are inherited from parent and
  168. one of the boundaries associated with mid(x,y) is open while the other
  169. is closed.  A node is marked 'c', '?', or 'x' if, respectively, all,
  170. some (but not all), or none of the numbers in its interval are in the
  171. domain.  The trees are conceptually infinite but only a finite part
  172. needs to be examined by HACR.  The intervals can be computed using the
  173. path from the root, so no intervals are stored at each node.
  174.  
  175.           (in the hardcopy version of this abstract)
  176.            Figure 2  The domain for a real variable
  177.  
  178. For a hyperarc (T, C), HACR deletes values outside pi(T,C) by
  179. manipulating the marks in the tree representing D(T).  A set of
  180. intervals whose union is pi(T,C) is generated one at a time and a new
  181. value for D(T) is accumulated by adding an approximation of each
  182. interval to it.  HACR would be a full arc consistency algorithm if the
  183. marks could each D(T) could be set exactly to pi(T,C).  However, with
  184. any a priori splitting strategy, it is possible that an an unbounded
  185. amount of refinement will be required.  Since real domain trees are
  186. infinite, a full arc consistency algorithm using these trees may
  187. require infinite space and may not terminate.  Instead, HACR
  188. associates a non-negative integer precision P(X) with each variable X.
  189. P(X) is the maximum distance from the root to any node in the tree for
  190. D(X) which will be accessed by HACR.  Thus, at any particular point,
  191. HACR can only access a finite part of each domain tree.  The Echidna
  192. built in predicate precision(Vars, P) sets the precision of each
  193. variable in the list Vars to P.  When HACR determines that a node
  194. should be refined, that is its mark should be set to '?' and its
  195. children analyzed, if the node is at the precision limit then its mark
  196. is left 'c'.  For this reason, ReviseHACR is a partial arc revision
  197. algorithm, but it can be made arbitrarily close to a full arc revision
  198. algorithm by increasing the precision of variables.  If the predicate
  199. precision is used to increase the precision of a variable X, then HACR
  200. is reinvoked because it may be possible to refine D(X) and some other
  201. domains.
  202.  
  203. A set of intervals whose union is pi(T,C) is generated differently for
  204. each class of constraint.  All complex constraints are broken down
  205. into an equivalent set of constraints using at most one numeric
  206. function each using intermediate variables.
  207.  
  208. For an equality, pi(T,C) is computed by solving C for T.  Then, the
  209. projection is generated by iterating through all the combinations of
  210. intervals marked 'c' in the source domains.  This is done by
  211. traversing the fringe of domain trees and combining adjacent intervals
  212. marked 'c'.  The numeric function used in the constraint is then
  213. applied to each pair of intervals using formulas such as:
  214.  
  215.     [x1, x2] + [y1, y2] = [x1+y1, x2+y2], 
  216.     [x1, x2] - [y1, y2] = [x1-y2, x2-y1], 
  217.     [x1, x2]*[y1, y2] =
  218.        [min{x1*y1,x1*y2,x2*y1,x2*y2},max{x1*y1,x1*y2,x2*y1,x2*y2}], and
  219.     [x1, x2] / [y1, y2] = [x1, x2]*[1/y2, 1/y1].
  220.  
  221. Limit values are used where functions are discontinuous (eg. division
  222. by 0).  It is easy to verify that the projection of an inequality of
  223. the form 'T 2 S' is:
  224.  
  225.     pi(T,C) = [min D(T), max D(S)]  
  226.  
  227. and other inequality cases are similar.  
  228.  
  229. For a disjunctive inequality of the form C1 or C2,
  230.  
  231. pi(T,C1 or C2) =
  232.        -
  233.       | pi(T,C1) U pi(T,C2)  if T in v(C1) and T in v(C2)
  234.      <  D(T)     if T in v(C1) and T notin v(C2) and C2 is satisfiable
  235.       | pi(T,C1) if T in v(C1) and T notin v(C2) and C2 is unsatisfiable
  236.        -
  237.  
  238.                  5.  Examples
  239.  
  240. This section contains example runs of Echidna version 1.0 on a Sun
  241. Sparcstation.  Echidna can numerically solve polynomials with varying
  242. precision using the built in predicate precision.  Consider the
  243. following query, where, as described in section 3, precision([X], 8)
  244. sets the precision P(X) of the variable X to 8 bits and the call
  245. split([X]) invokes a case analysis algorithm to search for solutions
  246. for X.
  247.  
  248.   ?- X in [-1000, 1000), precision([X], 8),
  249.      (X - 1)*(X - 2) = 0, split([X]).
  250.  
  251. Since Echidna's numeric constraint solving system is incomplete,
  252. Echidna outputs approximate answers but guarantees that all solutions
  253. to the query are present in some answer.  For this query, Echidna
  254. computes the following three answers:
  255.  
  256.   X in [0, 7.8125)        ; % both solutions here
  257.   X in [7.8125, 15.625)   ;
  258.   X in [15.625, 23.4375)  ;
  259.   no.
  260.  
  261. More precise approximations of the solution can be obtained by
  262. computing CSPs with smaller domains.  Echidna can be used to do this
  263. by setting P(X) higher.  For instance, if P(X) is set to 32, then the
  264. following CSPs are computed.
  265.  
  266.   X in [0.9999997, 1.0000002) ;
  267.   X in [1.9999998, 2.0000003) ;
  268.   no.
  269.  
  270. For an example with disjunctive inequalities, consider the program
  271. given in figure 1 with the query:
  272.  
  273.   ?- precision([S1, S2], 3), S1 N [0, 4], S2 N [0, 4],
  274.      schedule([task(S1, 2), task(S2, 1.5)], task(0, 4)).
  275.  
  276. Echidna answers:
  277.  
  278.   S1 in [0, 0.5] U [1.5, 2], S2 in [0, 0.5] U [2, 2.5]
  279.  
  280. All other real numeric CLP systems can only implement disjunctive
  281. constraints using explicit disjunction in the logic program.
  282.  
  283.                   References
  284.  
  285. Havens, W. S. 1991. Dataflow Dependency Backtracking in a New CLP
  286. Language. In Proc. AAAI Spring Symposium on Constraint-Based
  287. Reasoning. Stanford.  110-127.
  288.  
  289. Mackworth, A. K. 1977. Consistency in Networks of Relations.
  290. Artificial Intelligence. 8. 99-118.
  291.  
  292. Mackworth, A. K., Mulder, J. A. and Havens, W. S. 1985. Hierarchical
  293. arc consistency: exploiting structured domains in constraint
  294. satisfaction problems.  Computational Intelligence. 1. 118-126.
  295.  
  296.                   Footnotes
  297.  
  298. (1)The full version of this paper appears under the same title as
  299. Centre for Systems Science technical report CSS-IS TR 91-06 and will
  300. appear in Computational Intelligence 8(4), Blackwell Publishers, 1992.
  301.  
  302. (2)Expert Systems Lab, Centre for Systems Science and School of
  303. Computing Science, Simon Fraser University, Burnaby, British Columbia,
  304. V5A 1S6, Canada.  Email: {gregory,havens}@cs.sfu.ca
  305.  
  306. (3)Echidna currently supports the arithmetic functions, some
  307. trigonometric functions, exponentiation, logarithm, and root
  308. extraction.
  309. -- 
  310. Greg Sidebottom,                                      | There's not a word that
  311. Expert Systems Laboratory, Centre for Systems Science | goes here that rhymes
  312. Simon Fraser University, Burnaby BC V5A 1S6, Canada   | with anything. -CVB
  313.