Prepare for your exams

Study with the several resources on Docsity

Earn points to download

Earn points by helping other students or get them with a premium plan

Guidelines and tips

Prepare for your exams

Study with the several resources on Docsity

Earn points to download

Earn points by helping other students or get them with a premium plan

Community

Ask the community

Ask the community for help and clear up your study doubts

University Rankings

Discover the best universities in your country according to Docsity users

Free resources

Our save-the-student-ebooks!

Download our free guides on studying techniques, anxiety management strategies, and thesis advice from Docsity tutors

Instructions for solving the fractions puzzle and creating rotas for paradise green promotions (pgp), a company that runs theatre venues at the edinburgh festival fringe. The fractions puzzle requires assigning distinct non-zero digits to each letter to make an equation hold. The rota construction problem involves generating suitable rotas that meet pgp's requirements, such as limiting the number of consecutive days someone can work. The document also covers setting up the problem as a constraint model and implementing it in eclipse.

Typology: Exams

2010/2011

1 / 9

Download Solving the Fractions Puzzle and Creating Rotas for Paradise Green Promotions and more Exams Computer Numerical Control in PDF only on Docsity! 0640178 MEng Degree Examination, 2003/2004 Part A Constraint Programming (COP) Open Examination Issued at: Friday, 5 December 2003 Submission due: Noon, Wednesday, 28 January 2004 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. • All students should submit their answers to the General Office of the Department of Computer Science. An assessment that has been handed in 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. • Any programs that you construct should be fully documented. For each program present some sample runs to illustrate how your program is used and what output it produces. There should be enough sample runs to show that your program works 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.) • In the interest of fairness, any clarification or further information that is issued will appear at http://www-course.cs.york.ac.uk/cso/ No clarification or information will be issued between 13 December and 6 January inclusive. 1 0640178 1. [11 marks] The fractions puzzle requires assigning distinct non-zero digits to each of the letters A through I so that the following equation holds: A BC + D EF + G HI = 1. (1) To be clear, a pair such as BC represents the value 10 ∗ B + C. Here is one solution1 (written in the form of the equation). 5 34 + 7 68 + 9 12 = 1. (2) Now consider the four programs shown in Figures 1 through 4 (which appear at the end of all questions), each of which generates all solutions to the fractions puzzle.2 In all of the programs, to avoid any subexpression whose value is not an integer, divi- sion is eliminated from all constraints by multiplying by all the denominators. Hence, removing division from (1) results in (A ∗ EF ∗ HI) + (D ∗ BC ∗ HI) + (G ∗ BC ∗ EF ) = (BC ∗ EF ∗ HI) (3) In answering the following questions, you should pay particular attention to the search space in which each program operates and the method by which each prunes this search space. It may be useful to illustrate your explanations by referring to particular states in the execution of the search. In some cases you may be able to compare the amount of pruning performed by one program to that of another program. (a) [2 marks] In no more than 200 words explain the operation of fraction1. (b) [3 marks] In no more than 300 words explain the operation of fraction2 and how this compares to the operation of fraction1. Pay particular attention to the dif- ferences between them. (c) [3 marks] In no more than 300 words explain the operation of fraction3 and how this compares to the operation of fraction1. Pay particular attention to the dif- ferences between them. (d) [3 marks] In no more than 300 words explain the operation of fraction4 and how this compares to the operation of fraction1. Pay particular attention to the dif- ferences between them. 2. [26 marks] This question involves creating a constraint model an then an Eclipse program that solves a real rota-construction problem. Paradise Green Promotions (PGP) runs theatre venues at the Edinburgh Festival Fringe. They do not perform any shows themselves; they are facility providers. They hire large buildings (churches, church halls etc.) in central Edinburgh, and add seating, stages, lighting and sound equipment to convert them into temporary theatres. These theatres are hired out to small theatre companies from all over the world. Furthermore in each of the theatres they create, PGP also builds and runs a comput- erised box office system. PGP also runs a café in one venue, where food is also prepared 1But you probably knew that already! 2In other words, assume that when queried the user always requests more answers. 2 0640178 (b) [8 marks] Now design a search strategy for your program that makes it as fast as possible at finding a single correct rota or determining that there is none. Consider the issues of variable ordering, value ordering, or anything else you con- sider relevant; however, to keep things simple, you should restrict your attention to depth-first search. It is suggested that you pay particular attention to the structure of your model. Explain and justify your design. Present some simple experiments that support your reasoning. 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 do 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. 5 0640178 lib(fd). fraction1([A, B, C, D, E, F, G, H, I]) :- [A, B, C, D, E, F, G, H, I]::[1..9], % Each letter gets value 1..9 EF #= 10*E+F, HI #= 10*H+I, BC #= 10*B+C, A*EF*HI + D*BC*HI + G*EF*BC #= EF*BC*HI, % Equation must hold generate([A,B,C,D,E,F,G,H,I], % Now search! [1,2,3,4,5,6,7,8,9]). generate([],_). % generate(L1,L2) labels the variables generate([H|T],L) :- % in L1 with the values in L2. sel(H,L,L2), generate(T,L2). sel(H,[H|T],T). % sel(E,L1,L2) succeeds if E is an sel(H,[H2|T],[H2|T2]) :- % element of L1 and L2 is the sel(H,T,T2). % result of removing E from L1 Figure 1: Fraction1 is an Eclipse program for solving the fractions puzzle. 6 0640178 fraction2([A, B, C, D, E, F, G, H, I]) :- L=[1,2,3,4,5,6,7,8,9], % List of all unused values sel(A,L,L2), % Guess A, remove from list sel(B,L2,L3), % Guess B, remove from list sel(C,L3,L4), % Guess C, remove from list BC is 10*B + C, % Check that A/BC < 1 A < BC, % by checking A < BC sel(D,L4,L5), % Guess D, remove from list sel(E,L5,L6), % Guess E, remove from list sel(F,L6,L7), % Guess F, remove from list EF is 10*E + F, % Check that A/BC + D/EF <1 LHS is A*EF+ D*BC, % by checking A*EF+ D*BC < BC*EF RHS is BC*EF, LHS < RHS, sel(G,L7,L8), % Guess G, remove from list sel(H,L8,L9), % Guess H, remove from list sel(I,L9,[]), % Guess I, remove from list HI is 10*H + I, % Check A/BC + D/EF + G/HI = 1 LHS2 is A*EF*HI + D*BC*HI + G*BC*EF, % by checking RHS2 is BC*EF*HI, % A*EF*HI + D*BC*HI + G*BC*EF = BC*EF*HI LHS2 = RHS2. sel(H,[H|T],T). % sel(E,L1,L2) succeeds if E is an sel(H,[H2|T],[H2|T2]) :- % element of L1 and L2 is the sel(H,T,T2). % result of removing E from L1 Figure 2: Fraction2 is a Prolog program for solving the fractions puzzle. 7