





Study with the several resources on Docsity
Earn points by helping other students or get them with a premium plan
This page cannot be seen from the preview
Don't miss anything!






MEng Degree Examination, 2004/
Part A
Open Examination Issued at: Friday, 10 December 2004
Submission due: Noon, Wednesday, 26 January 2005
Your attention is drawn to the Guidelines on Mutual Assistance and Collaboration in the Student’s Handbook.
All queries on this assessment should be addressed to Alan Frisch, [email protected].
Your examination number must be written on the front of your submission. You must not identify yourself in any other way.
test1 :- solve(... parameters for first test...). test2 :- solve(... parameters for second test...).
If your experiments involved counting nodes, the code that does the counting and reports it should be left in your program. The programs you submit will be tested using Eclipse Version 5.6 #50 running on the Departmental computer named “Hercules”. Your program must work without modifi- cation in this setting.
(b) [2 marks] If we assume that in this constraint X and Y are are the same variable, then even the correct algorithm goes wrong. Through use of an example, show this. (c) [3 marks] Give an algorithm that takes a constraint of the form X = c 1 → X = c 2 and prunes the domain of X to make the constraint arc consistent without losing any solutions.
(a) [12 marks] Read Sections 1 through 3 of [?], a copy of which can be found on the module web page, http://www-course.cs.york.ac.uk/cop/. Pay particular attention the model presented in Section 3, which we shall call Model 1. Implement this model in Eclipse.^2 Given parameters specifying a problem instance, your program should find an optimal solution and output increasingly-good answers along the way. The solution should be returned through variable bindings. The program should work by performing partial assignment search and should exploit the finite-domain features of the fd or the ic library.^3 The predicate that is called to execute your program must be named solve and it must take 5 arguments in order:
however, to keep things simple, you should restrict your attention to depth-first search. You should consider alternative strategies, possibly including some that are purely generic (i.e., model independent), but certainly including some that exploit the structure of the model. Present some simple experiments that guide and support your design choice. You may wish your choice of search strategy to depend on some features of the problem instance. If so, to keep things simple, you need not implement the function that guides the strategy based on the instance. Instead, for each instance you test, you can hardwire the strategy for that instance. As an example, you might argue that one strategy should be used on instances that meet a certain condition and another strategy should be used all other instances. Instead of designing a program that tests this condition and does the appropriate thing, it is acceptable (and probably simpler) to write two programs: one that you use on instances that meet the condition and the other for instances that do not. (c) [5 marks] Now consider Model 2, which is obtained by adding to Model 1 the symmetry-breaking constraints discussed in Section 4 of [?]. Implement Model 2 by extending your program for Model 1. Show that these symmetry-breaking constraints can sometimes be very important by using a carefully-constructed test instance and comparing the performance of your program with and without the symmetry-breaking constraints.
Now consider a different extension to SSSD. In this extension, the slabs are going to be manufactured in sequence, starting from s 1 and ending with sn, and certain orders must be manufactured before other orders. Thus, a problem instance provides a list of pairs of orders and for every pair [oi, oj ] a solution must assign oi to an “earlier” slab than that assigned to oj. Now explain how Model 1 could could be modified to handle this extended problem. You are not required to implement this model, but your description should clearly and precisely state what constraints need to be generated for any given instance.
Now consider an extension to the SSSD in which certain specified orders cannot be placed on the same slab. Thus, a problem instance provides a list of pairs of distinct orders and a solution cannot assign to the same slab any two orders that appear in one of the pairs. Now explain how Model 2 could be modified to handle this extended problem. You are not required to implement this model, but your description should clearly and precisely state what constraints need to be generated for any given instance.
fourqueens2(Sol) :- Sol=[A,B,C,D,E,F,G,H,I,J,K,L,M,N,O,P],
sel(A,[0,1]), sel(B,[0,1]), sel(C,[0,1]), sel(D,[0,1]), 1 is A+B+C+D, % Exactly one queen on first row
sel(E,[0,1]), sel(F,[0,1]), sel(G,[0,1]), sel(H,[0,1]), 1 is E+F+G+H, % Exactly one queen on second row
sel(I,[0,1]), sel(J,[0,1]), sel(K,[0,1]), sel(L,[0,1]), 1 is I+J+K+L, % Exactly one queen on third row
sel(M,[0,1]), sel(N,[0,1]), sel(O,[0,1]), sel(P,[0,1]), 1 is M+N+O+P, % Exactly one queen on fourth row
1 is A+E+I+M, % Exactly 1 queen in each col 1 is B+F+J+N, 1 is C+G+K+O, 1 is D+H+L+P,
IN is I+N, IN =< 1, % At most one queen on each downward diagonal EJO is E+J+O, EJO =< 1, AFKP is A+F+K+P, AFKP =< 1, BGL is B+G+L, BGL =< 1, CH is C+H, CH =< 1,
EB is E+B, EB =< 1, % At most one queen on each upward diagonal IFC is I+F+C, IFC =< 1, MJDG is M+J+D+G, MJDG =< 1, NKH is N+K+H, NKH =< 1, OL is O+L, OL =< 1.
sel(H,[H|]). % sel(E,L) succeeds if E is an sel(H,[|T]) :- % element of L sel(H,T).
Figure 2: fourqueens2 is a Prolog program for solving the 4-queens problem.
fourqueens3([A,B,C,D,E,F,G,H,I,J,K,L,M,N,O,P]) :-
A>=0, B>=0, C>=0, D>=0, E>=0, F>=0, G>=0, H>=0, % All variables at least 0 I>=0, J>=0, K>=0, L>=0, M>=0, N>=0, O>=0, P>=0,
A<=1, B<=1, C<=1, D<=1, E<=1, F<=1, G<=1, H<=1, % All variables at most 1 I<=1, J<=1, K<=1, L<=1, M<=1, N<=1, O<=1, P<=1,
A+B+C+D = 1, % Exactly one queen in each row E+F+G+H = 1, I+J+K+L = 1, M+N+O+P = 1,
A+E+I+M = 1, % Exactly 1 queen in each col B+F+J+N = 1, C+G+K+O = 1, D+H+L+P = 1,
I+N <= 1, % At most one queen on a downward diagonal E+J+O <= 1, A+F+K+P <= 1, B+G+L <= 1, C+H <= 1,
E+B <= 1, % At most one queen on an upward diagonal I+F+C <= 1, M+J+G+D <= 1, N+K+H <= 1, O+L <= 1, generate([A,B,C,D,E,F,G,H,I,J,K,L,M,N,O,P],[0,1]).
generate([],_). % generate(L1,L2) labels the variables generate([H|T],L) :- % in L1 with the values in L2. sel(H,L), generate(T,L).
sel(H,[H|]). % sel(E,L) succeeds if E is an sel(H,[|T]) :- % element of L sel(H,T).
Figure 3: fourqueens3 is a CLP(R) program for solving the 4-queens.