Docsity

Examination Document for Constraint Programming (COP) - MEng Degree, 2004/2005, Exams of Computer Numerical Control

Toggle sidebar
bg1
0640178
MEng Degree Examination, 2004/2005
Part A
Constraint Programming (COP)
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.
Instructions
•All questions should be attempted.
•A submission after the deadline will be marked initially as if it had been handed in on
time, but the Board of Examiners will normally apply a lateness penalty.
•Your write-up should be typeset and submitted to the General Office of the Department
of Computer Science. The programs you develop in questions 2(a), 2(b), and 2(c) should
be submitted electronically through the webpage at http://www.cs.york.ac.uk/submit/.
•Any programs that you submit should be fully documented. For each program present
some sample runs to demonstrate that your program operates correctly in a variety of
circumstances.
•Where you are asked to give experimental evidence, you are not expected to conduct
rigorous controlled experiments; a few simple runs measuring cpu time and nodes visited
suffice. (Note: Measuring very short runtimes may be unreliable. In such cases, it is
suggested that you measure the time taken by multiple executions.)
•Your write-up should treat the electronically-submitted programs as if they are appen-
dices to the write-up. You can, and perhaps should, refer to the programs in the body
of the write-up.
1
pf3
pf4
pf5
pf8
pf9

Partial preview of the text

Download Examination Document for Constraint Programming (COP) - MEng Degree, 2004/2005 and more Exams Computer Numerical Control in PDF only on Docsity!

MEng Degree Examination, 2004/

Part A

Constraint Programming (COP)

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.

Instructions

  • All questions should be attempted.
  • A submission after the deadline will be marked initially as if it had been handed in on time, but the Board of Examiners will normally apply a lateness penalty.
  • Your write-up should be typeset and submitted to the General Office of the Department of Computer Science. The programs you develop in questions 2(a), 2(b), and 2(c) should be submitted electronically through the webpage at http://www.cs.york.ac.uk/submit/.
  • Any programs that you submit should be fully documented. For each program present some sample runs to demonstrate that your program operates correctly in a variety of circumstances.
  • Where you are asked to give experimental evidence, you are not expected to conduct rigorous controlled experiments; a few simple runs measuring cpu time and nodes visited suffice. (Note: Measuring very short runtimes may be unreliable. In such cases, it is suggested that you measure the time taken by multiple executions.)
  • Your write-up should treat the electronically-submitted programs as if they are appen- dices to the write-up. You can, and perhaps should, refer to the programs in the body of the write-up.
  • Your programs should be submitted in three files named 2a.ecl, 2b.ecl and 2c.ecl, which contain the programs for questions 2(a), 2(b) and 2(c), respectively. In each file, the main predicate and any alternative versions of it should be named solve, solve1, solve2, etc. The arguments to these predicates should be as described in the question. Any experiments or tests reported within your write-up should be available within you program files though a sequence of clauses such as these:

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.

  • In the interest of fairness, any clarification or further information that is issued will appear on the module web page: http://www-course.cs.york.ac.uk/cop/ No clarification or information will be issued between 18 December and 9 January inclusive.

(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.

  1. [25 marks] This question involves the use of finite-domain constraint programming to solve a sim- plified steel mill slab design problem (henceforth SSSD, appears as problem 038 in www.csplib.org), and some of its extensions. The SSSD is a simplified version of a real problem that arises in the manufacture of steel. In considering this problem assume that the sizes of all orders and slabs are positive integers.

(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:

  • a list of positive integers indicating the available slab sizes;
  • a positive integer indicating the maximum number of colours that can be allocated to a slab;
  • a positive integer indicating the number of colours (We shall assume that the colours are named 1 through n, where n is the number of colours.);
  • a list of orders where each order is a two element list in which the first element is the size of the order and the second is the colour of the order; and
  • a variable that is to be bound to the answer, which is the orderA matrix. You are not required to prettyprint the output of your program, but doing so may be useful. If you do this, then use a second program outside of your “solve” predicate. Thus to prettyprint your output, you can issue the Eclipse query solve(input_parameters,output_parameters), pretty_print(output_parameters). Your program should contain comments to make it understandable and to show its correspondence to the model. Explain and justify any design choices that you made. In answering this question you need not be concerned with identifying highly efficient variable or value orderings; use any orderings that seem reasonable and very briefly explain why they are reasonable. (b) [8 marks] Now design a search strategy for your program that makes it as fast as possible at finding an optimal solution and proving that it is optimal. Consider the issues of variable ordering, value ordering, or anything else you consider relevant; (^2) Your program should use the same decision variables and domains as those in Model 1. Your program might use slightly different constraint than those given in Model 1/ (^3) You are entitled to use other Eclipse libraries as well. Some libraries that you may find useful are branch_and_bound, ic_global, ic_search, fd_search and fd_global.

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.

  1. [3 marks]

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.

  1. [6 marks]

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.