
Constraint Satisfaction Problems The ECLi PSe Constraint Logic Programming System Albert-Ludwigs-Universität Freiburg Christian Becker-Asano, Bernhard Nebel and Stefan Wölfl January 26, 2015 Motivation Problem modeling Prolog & ECLi PSe Programming Motivation in Prolog ECLi PSe Pro- gramming Interval Constraints Library Example Summary Literature January 26, 2015 Becker-Asano, Nebel and Wölfl – Constraint Satisfaction Problems 2 / 100 What is ECLiPSe ? Motivation Problem modeling Prolog & i e i e “ECL PS is designed for solving combinatorial optimization ECL PS problems, for the development of new constraint solver Programming in Prolog technology and their hybrids, and for the teaching of modelling, ECLi PSe Pro- solving and search techniques.” gramming (http://sourceforge.net/projects/eclipse-clp/) Interval Constraints Library Example Summary Literature January 26, 2015 Becker-Asano, Nebel and Wölfl – Constraint Satisfaction Problems 4 / 100 What is ECLiPSe ? Motivation i e ECL PS : Problem modeling 1 is a declarative language Prolog & ECLi PSe 2 is a Constraint Programming toolkit Programming 3 is available open source (Mozilla Public License) in Prolog 4 has been applied to areas of planning, scheduling, resource ECLi PSe Pro- allocation, timetabling, transport. gramming Interval 5 provides bindings for Python, C/C++, Tcl/Tk, Java (Eclipse Constraints Library IDE plugin), SQL, . Example 6 can be interfaced to remotely (RPC) Summary Literature January 26, 2015 Becker-Asano, Nebel and Wölfl – Constraint Satisfaction Problems 5 / 100 Why ECLiPSe ? Motivation Problem modeling The TPK (Trabb Pardo-Knuth) algorithm of Donald Knuth and Prolog & ECLi PSe Luis Trabb Pardo (1976) (the “Hello World!” of algorithms): Programming in Prolog “The algorithm prompts for 11 real numbers (a0 :::a10) and for p 3 i e each ai computes bi = f(ai ), where f(t) = jtj + 5t . After that for ECL PS Pro- gramming i = 10:::0 (in that order) the algorithm outputs a pair (i;bi ) if Interval bi ≤ 400, or (i;TOO LARGE) otherwise.” (Dymchenko & Mykhailova, 2014) Constraints Library Example Summary Literature January 26, 2015 Becker-Asano, Nebel and Wölfl – Constraint Satisfaction Problems 6 / 100 Declarative programming with logic The TPK algorithm in ECLi PSe / Prolog: Motivation Problem 1 f(T,Y):- modeling 2 Y is sqrt(abs(T)) + 5*T^3. Prolog & 3 main:- ECLi PSe 4 read(As), Programming 5 length(As,N), reverse(As, Rs), in Prolog 6 ( foreach(Ai, Rs), for(I,N - 1, 0, -1) do 7 Bi isf(Ai), ECLi PSe Pro- 8 ( Bi > 400 -> gramming 9 printf("%wTOOLARGE\n",I) Interval 10 ; Constraints 11 printf("%w%w\n",[I, Bi]) Library 12 ) Example 13 ). Summary (Dymchenko & Mykhailova, 2014) Literature January 26, 2015 Becker-Asano, Nebel and Wölfl – Constraint Satisfaction Problems 7 / 100 Declarative programming with functions Motivation The TPK algorithm in python 3: Problem modeling 1 >>> deff(x): return abs(x) ** 0.5 + 5 *x**3 Prolog & 2 ECLi PSe 3 >>> print(’,’.join(’%s:%s’% Programming 4 (x,v ifv<=400 else"TOOLARGE!") in Prolog 5 forx,v in((y,f(float(y))) 6 fory in input(’\nnumbers:’) ECLi PSe Pro- 7 .strip.split()[:11][::-1]))) gramming Interval (http://rosettacode.org/wiki/Trabb_Pardo%E2%80%93Knuth_algorithm#Python) Constraints Library Is the logical Prolog version “easier/better” than the functional Example Python version? Summary Literature January 26, 2015 Becker-Asano, Nebel and Wölfl – Constraint Satisfaction Problems 8 / 100 Python binding for ECLiPSe The “Search Solution” example of pyclp: 1 from pyclp import* Motivation 2 init()# Init ECLiPSe engine Problem 3 Compound("lib",Atom("ic")).post_goal()# Load ic library modeling 4 A_var=Var()# Create variableA Prolog & 5 B_var=Var()# Create variableB ECLi PSe 6 #[A,B]#::1..10 Programming 7 Compound("#::",PList([A_var,B_var]),\ in Prolog 8 Compound("..",1,10)).post_goal() 9 Compound("#<",A_var,B_var).post_goal()#A#<B ECLi PSe Pro- 10 Compound("#=",A_var,5).post_goal()#A#=5 gramming 11 # labeling([A,B]) Interval 12 Compound("labeling",\ Constraints 13 PList([A_var,B_var])).post_goal() Library 14 # Loop on all solution and print them. Example 15 while(resume()[0]==SUCCEED): Summary 16 print(B_var) Literature 17 # backtracking over solutions 18 Atom("fail").post_goal() 19 cleanup()# Shutdown ECLiPSe engine January 26, 2015 Becker-Asano, Nebel and Wölfl – Constraint Satisfaction Problems 9 / 100 So again, why ECLiPSe ? Motivation Problem modeling ) Because it can be considered more elegant and even easier Prolog & ECLi PSe to (only) declare a problem logically and then use all the power Programming of standard reasoning and search algorithms to find a solution. in Prolog i e ECL PS contains all major CLP algorithms as libraries and ECLi PSe Pro- gramming provides the full power of the Prolog language for problem Interval modeling. Constraints Library Example Summary Literature January 26, 2015 Becker-Asano, Nebel and Wölfl – Constraint Satisfaction Problems 10 / 100 Suitable problems for ECLiPSe Motivation i e Problem Characteristics of problems suitable for ECL PS : modeling 1 There are no general methods or algorithms Prolog & ECLi PSe NP-completeness Programming Different strategies and heuristics have to be tested in Prolog 2 Requirements are quickly changing ECLi PSe Pro- Programs should be flexible enough to adapt gramming 3 Interval Decision support required Constraints Co-operate with user Library Friendly interfaces Example Summary Literature January 26, 2015 Becker-Asano, Nebel and Wölfl – Constraint Satisfaction Problems 11 / 100 Motivation Problem modeling Issues CLP and ECLi PSe Prolog & Problem modeling ECLi PSe Programming in Prolog ECLi PSe Pro- gramming Interval Constraints Library Example Summary Literature January 26, 2015 Becker-Asano, Nebel and Wölfl – Constraint Satisfaction Problems 12 / 100 Logic programming Constraint Programming can be characterized by two pseudo-equations: Motivation Problem modeling Solution = Logic + Control (1) Issues CLP and ECLi PSe Prolog & Control = Reasoning + Search (2) ECLi PSe Programming Equation (1): a solution can be found by: in Prolog 1 a , declarative description of the problem, and logical ECLi PSe Pro- gramming 2 control information for the computer to deduce it. Interval Equation (2): control is a combination of: Constraints Library 1 reasoning to (efficiently) limit the search space, and Example 2 subsequent (inefficient) search through that space Summary Literature Problem modeling deals with the Logic part of Equation (1). January 26, 2015 Becker-Asano, Nebel and Wölfl – Constraint Satisfaction Problems 14 / 100 Issues in Problem Modeling A good formalism should fulfill the following criteria: Motivation 1 Expressive power: Problem modeling formal model of real world problem possible? Issues CLP and ECLi PSe 2 Clarity for humans: Prolog & i e ease of use of formalism (read, write, understand, modify) ECL PS Programming 3 Solvability for computers: in Prolog Good methods available to solve problem? ECLi PSe Pro- Higher-level models gramming Interval + closer to the user and the problem Constraints Library + easier to understand and trust, to debug and modify, but Example - difficult to see how they can be solved Summary Literature January 26, 2015 Becker-Asano, Nebel and Wölfl – Constraint Satisfaction Problems 15 / 100 Issues in Problem Modeling Motivation Classical source of error in application development: Problem ) Transition from formal description to final program modeling Issues ) Can the final program be trusted? CLP and ECLi PSe Prolog & CLP solution: ECLi PSe Programming Keep initial formal model as part of the final program in Prolog Enhance rather than rewrite: ECLi PSe Pro- Add control annotations (e.g., algorithmic or heuristic gramming information) Interval Constraints Transform higher-level (problem) constraints into Library low-level (solver) constraints Example Summary Literature January 26, 2015 Becker-Asano, Nebel and Wölfl – Constraint Satisfaction Problems 16 / 100 Modeling with CLP and ECLiPSe Built-in language constructs used in modeling: Motivation Build-in constraints: X #> Y Problem modeling Abstraction: Issues CLP and ECLi PSe bef(task(Si,Di,),task(Sj,Dj)) :- Si+Dj #<= Sj. Prolog & i e Conjunction: betw(X,Y,Z) :- X #< Y, Y #< Z. ECL PS Programming Disjunction: neighb(X,Y) :- ( X #= Y+1 ; Y #= X+1 ). in Prolog Iteration: ECLi PSe Pro- not_among(X,L) :- gramming Interval ( foreach(Y,L), param(X) do X #\= Y ). Constraints Library Recursion: Example not_among(X,[]). Summary not_among(X,[Y|Ys]) :- X #\= Y, not_among(X,Ys). Literature January 26, 2015 Becker-Asano, Nebel and Wölfl – Constraint Satisfaction Problems 17 / 100 CLP and ECLiPSe An example constraint network (Cheadle et al., 2014): Motivation Problem modeling Issues CLP and ECLi PSe Prolog & ECLi PSe Programming in Prolog ECLi PSe Pro- gramming Interval Constraints Library Example But, of course, one problem can be modeled in multiple ways.. Summary Literature January 26, 2015 Becker-Asano, Nebel and Wölfl – Constraint Satisfaction Problems 18 / 100 Same Problem – Different Model 1 sendmore(Digits):- 2 Digits=[S,E,N,D,M,O,R,Y], Motivation 3 Digits :: [0..9], 4 alldifferent(Digits), Problem modeling 5 S #\= 0,M #\= 0, Issues 6 1000*S + 100*E + 10*N+D CLP and ECLi PSe 7 + 1000*M + 100*O + 10*R+E Prolog & 8 #= 10000*M + 1000*O + 100*N + 10*E+Y. ECLi PSe Programming 1 sendmore(Digits):- in Prolog 2 Digits=[S,E,N,D,M,O,R,Y], 3 Digits :: [0..9], ECLi PSe Pro- 4 Carries=[C1,C2,C3,C4], gramming 5 Carries :: [0..1], Interval 6 alldifferent(Digits), Constraints 7 S #\= 0,M #\= 0, Library 8 C1 #=M, Example
Details
-
File Typepdf
-
Upload Time-
-
Content LanguagesEnglish
-
Upload UserAnonymous/Not logged-in
-
File Pages92 Page
-
File Size-