[go: up one dir, main page]

Academia.eduAcademia.edu
Applications of a Propositional Calculator: Constraint Satisfaction Problems Author: Jon Awbrey April 24, 1995 Course: Engineering 690, Graduate Project Winter Semester Supervisors: F. Mili & M.A. Zohdy Oakland University The Four Houses Puzzle Constructed on the model of the “Five Houses Puzzle” in [VaH, 132-136]. Problem Statement. Four people with different nationalities live in the first four houses of a street. They practice four distinct professions, and each of them has a favorite animal, all of them different. The four houses are painted different colors. The following facts are known: 1. The Englander lives in the first house on the left. 2. The doctor lives in the second house. 3. The third house is painted red. 4. The zebra is a favorite in the fourth house. 5. The person in the first house has a dog. 6. The Japanese lives in the third house. 7. The red house is on the left of the yellow one. 8. They breed snails in the house to right of the doctor. 9. The Englander lives next to the green house. 10. The fox is in the house next to to the diplomat. 11. The Spaniard likes zebras. 12. The Japanese is a painter. 13. The Italian lives in the green house. 14. The violinist lives in the yellow house. 15. The dog is a pet in the blue house. 16. The doctor keeps a fox. The problem is to find all the assignments of features to houses that satisfy these requirements. Input: House4.Log (a) eng_1 doc_2 red_3 zeb_4 dog_1 jap_3 (( red_1 yel_2 ),( red_2 yel_3 ),( red_3 yel_4 )) (( doc_1 sna_2 ),( doc_2 sna_3 ),( doc_3 sna_4 )) (( eng_1 gre_2 ), ( eng_2 gre_3 ),( eng_2 gre_1 ), ( eng_3 gre_4 ),( eng_3 gre_2 ), ( eng_4 gre_3 )) (( dip_1 fox_2 ), ( dip_2 fox_3 ),( dip_2 fox_1 ), ( dip_3 fox_4 ),( dip_3 fox_2 ), ( dip_4 fox_3 )) (( spa_1 zeb_1 ),( spa_2 zeb_2 ),( spa_3 zeb_3 ),( spa_4 zeb_4 )) (( jap_1 pai_1 ),( jap_2 pai_2 ),( jap_3 pai_3 ),( jap_4 pai_4 )) (( ita_1 gre_1 ),( ita_2 gre_2 ),( ita_3 gre_3 ),( ita_4 gre_4 )) (( yel_1 vio_1 ),( yel_2 vio_2 ),( yel_3 vio_3 ),( yel_4 vio_4 )) (( blu_1 dog_1 ),( blu_2 dog_2 ),( blu_3 dog_3 ),( blu_4 dog_4 )) (( doc_1 fox_1 ),( doc_2 fox_2 ),( doc_3 fox_3 ),( doc_4 fox_4 )) Input: House4.Log (b) (( (( eng_1 ),( eng_2 ),( eng_3 ),( eng_4 )) (( spa_1 ),( spa_2 ),( spa_3 ),( spa_4 )) (( jap_1 ),( jap_2 ),( jap_3 ),( jap_4 )) (( ita_1 ),( ita_2 ),( ita_3 ),( ita_4 )) (( eng_1 ),( spa_1 ),( jap_1 ),( ita_1 )) (( eng_2 ),( spa_2 ),( jap_2 ),( ita_2 )) (( eng_3 ),( spa_3 ),( jap_3 ),( ita_3 )) (( eng_4 ),( spa_4 ),( jap_4 ),( ita_4 )) (( gre_1 ),( gre_2 ),( gre_3 ),( gre_4 )) (( red_1 ),( red_2 ),( red_3 ),( red_4 )) (( yel_1 ),( yel_2 ),( yel_3 ),( yel_4 )) (( blu_1 ),( blu_2 ),( blu_3 ),( blu_4 )) (( gre_1 ),( red_1 ),( yel_1 ),( blu_1 )) (( gre_2 ),( red_2 ),( yel_2 ),( blu_2 )) (( gre_3 ),( red_3 ),( yel_3 ),( blu_3 )) (( gre_4 ),( red_4 ),( yel_4 ),( blu_4 )) (( pai_1 ),( pai_2 ),( pai_3 ),( pai_4 )) (( dip_1 ),( dip_2 ),( dip_3 ),( dip_4 )) (( vio_1 ),( vio_2 ),( vio_3 ),( vio_4 )) (( doc_1 ),( doc_2 ),( doc_3 ),( doc_4 )) (( pai_1 ),( dip_1 ),( vio_1 ),( doc_1 )) (( pai_2 ),( dip_2 ),( vio_2 ),( doc_2 )) (( pai_3 ),( dip_3 ),( vio_3 ),( doc_3 )) (( pai_4 ),( dip_4 ),( vio_4 ),( doc_4 )) (( dog_1 ),( dog_2 ),( dog_3 ),( dog_4 )) (( zeb_1 ),( zeb_2 ),( zeb_3 ),( zeb_4 )) (( fox_1 ),( fox_2 ),( fox_3 ),( fox_4 )) (( sna_1 ),( sna_2 ),( sna_3 ),( sna_4 )) (( dog_1 ),( zeb_1 ),( fox_1 ),( sna_1 )) (( dog_2 ),( zeb_2 ),( fox_2 ),( sna_2 )) (( dog_3 ),( zeb_3 ),( fox_3 ),( sna_3 )) (( dog_4 ),( zeb_4 ),( fox_4 ),( sna_4 )) )) Output: House4.Sen eng_1 doc_2 red_3 zeb_4 dog_1 jap_3 yel_4 sna_3 gre_2 dip_1 fox_2 spa_4 pai_3 ita_2 vio_4 blu_1 Table 1. Solution to the Four Houses Puzzle House 1 House 2 House 3 House 4 Nation England Italy Japan Spain Color blue green red yellow Profession diplomat doctor painter violinist Animal dog fox snails zebra Fabric Knowledge Base Based on the example in [MaW, 8-16]. (has_floats , plain_weave ) (has_floats ,(twill_weave ),(satin_weave )) (plain_weave , (plain_weave one_color ), (color_groups ), (grouped_warps ), (some_thicker ), (crossed_warps ), (loop_threads ), (plain_weave flannel )) (plain_weave one_color cotton balanced smooth ,(percale )) (plain_weave one_color cotton sheer ,(organdy )) (plain_weave one_color silk sheer ,(organza )) (plain_weave color_groups warp_stripe fill_stripe ,(plaid )) (plaid equal_stripe ,(gingham )) (plain_weave grouped_warps ,(basket_weave )) (basket_weave typed ,(type_2_to_1 ),(type_2_to_2 ),(type_4_to_4 )) (basket_weave typed type_2_to_1 thicker_fill ,(oxford )) (basket_weave typed (type_2_to_2 , type_4_to_4 ) same_thickness ,(monks_cloth )) (basket_weave (typed ) rough open ,(hopsacking )) (typed (basket_weave )) (basket_weave ,(oxford ),(monks_cloth ),(hopsacking )) (plain_weave some_thicker ,(ribbed_weave )) (ribbed_weave ,(small_rib ),(medium_rib ),(heavy_rib )) (ribbed_weave ,(flat_rib ),(round_rib )) (ribbed_weave thicker_fill ,(cross_ribbed )) (cross_ribbed small_rib flat_rib ,(faille )) (cross_ribbed small_rib round_rib ,(grosgrain )) (cross_ribbed medium_rib round_rib ,(bengaline )) (cross_ribbed heavy_rib round_rib ,(ottoman )) (cross_ribbed ,(faille ),(grosgrain ),(bengaline ),(ottoman )) (plain_weave crossed_warps ,(leno_weave )) (leno_weave open ,(marquisette )) (plain_weave loop_threads ,(pile_weave )) (pile_weave ,(fill_pile ),(warp_pile )) (pile_weave ,(cut ),(uncut )) (pile_weave warp_pile cut ,(velvet )) (pile_weave fill_pile cut aligned_pile ,(corduroy )) (pile_weave fill_pile cut staggered_pile ,(velveteen )) (pile_weave fill_pile uncut reversible ,(terry )) (pile_weave fill_pile cut ( (aligned_pile , staggered_pile ) )) (pile_weave ,(velvet ),(corduroy ),(velveteen ),(terry )) (plain_weave , (percale ),(organdy ),(organza ), (plaid ), (oxford ),(monks_cloth ),(hopsacking ), (faille ),(grosgrain ),(bengaline ),(ottoman ), (leno_weave ), (pile_weave ), (plain_weave flannel )) (twill_weave , (warp_faced ), (filling_faced ), (even_twill ), (twill_weave flannel )) (twill_weave warp_faced colored_warp white_fill ,(denim )) (twill_weave warp_faced one_color ,(drill )) (twill_weave even_twill diagonal_rib ,(serge )) (twill_weave warp_faced ( (one_color , ((colored_warp )(white_fill )) ) )) (twill_weave warp_faced ,(denim ),(drill )) (twill_weave even_twill ,(serge )) (( ( ((plain_weave )(twill_weave )) napped ((cotton )(wool )) ,(flannel )) )) (satin_weave ,(warp_floats ),(fill_floats )) (satin_weave ,(satin_weave smooth ),(satin_weave napped )) (satin_weave ,(satin_weave cotton ),(satin_weave silk )) (satin_weave warp_floats smooth ,(satin )) (satin_weave fill_floats smooth ,(sateen )) (satin_weave napped cotton ,(moleskin )) (satin_weave ,(satin ),(sateen ),(moleskin )) Graph Coloring Based on the discussion in [Wil, 196]. (Note: There is a wrong Figure printed in some editions, which does not match its description in the text.) Input: Color.Eg1 (( 1_orange ),( 1_silver ),( 1_indigo )) (( 2_orange ),( 2_silver ),( 2_indigo )) (( 3_orange ),( 3_silver ),( 3_indigo )) (( 4_orange ),( 4_silver ),( 4_indigo )) ( 1_orange 2_orange )( 1_silver 2_silver )( 1_indigo 2_indigo ) ( 1_orange 4_orange )( 1_silver 4_silver )( 1_indigo 4_indigo ) ( 2_orange 3_orange )( 2_silver 3_silver )( 2_indigo 3_indigo ) ( 2_orange 4_orange )( 2_silver 4_silver )( 2_indigo 4_indigo ) ( 3_orange 4_orange )( 3_silver 4_silver )( 3_indigo 4_indigo ) Output: Color.Se1 1_orange 2_silver 3_orange 4_indigo 2_indigo 3_orange 4_silver 1_silver 2_orange 3_silver 4_indigo 2_indigo 3_silver 4_orange 1_indigo 2_orange 3_indigo 4_silver 2_silver 3_indigo 4_orange Differential Analytic Turing Automata Turing Machine Example: Parity Function [Wilf, Algorithms and Complexity, 188-201] Table 2. Parity Machine State Q Symbol S Next Symbol S¢ Ratchet dR Next State Q¢ 0 0 0 +1 0 0 1 1 +1 1 0 # # –1 # 1 0 0 +1 1 1 1 1 +1 0 1 # # –1 * Figure 3. Parity Machine Turing Machine Example: Parity Function Present State Function Qf:P->Q q# q* q0 q1 p0 p0_q# p0_q* p0_q0 p0_q1 p1 p1_q# p1_q* p1_q0 p1_q1 p2 p2_q# p2_q* p2_q0 p2_q1 … … … … … Present Register Function Rf:P->R r0 r1 r2 … p0 p0_r0 p0_r1 p0_r2 … p1 p1_r0 p1_r1 p1_r2 … p2 p2_r0 p2_r1 p2_r2 … … … … … … Present Symbol Function Sf:P->[R->S] s# s* s0 s1 p0_r0 p0_r0_s# p0_r0_s* p0_r0_s0 p0_r0_s1 p0_r1 p0_r1_s# p0_r1_s* p0_r1_s0 p0_r1_s1 p0_r2 p0_r2_s# p0_r2_s* p0_r2_s0 p0_r2_s1 … … … … … p1_r0 p1_r0_s# p1_r0_s* p1_r0_s0 p1_r0_s1 p1_r1 p1_r1_s# p1_r1_s* p1_r1_s0 p1_r1_s1 p1_r2 p1_r2_s# p1_r2_s* p1_r2_s0 p1_r2_s1 … … … … … p2_r0 p2_r0_s# p2_r0_s* p2_r0_s0 p2_r0_s1 p2_r1 p2_r1_s# p2_r1_s* p2_r1_s0 p2_r1_s1 p2_r2 p2_r2_s# p2_r2_s* p2_r2_s0 p2_r2_s1 … … … … … Turing.Lit: Logical Index File Present State Function Qf:P->Q p0_q# p0_q* p0_q0 p0_q1 p1_q# p1_q* p1_q0 p1_q1 p2_q# p2_q* p2_q0 p2_q1 Present Register Function Rf:P->R p0_r0 p0_r1 p0_r2 p1_r0 p1_r1 p1_r2 p2_r0 p2_r1 p2_r2 Present Symbol Function Sf:P->[R->S] p0_r0_s# p0_r0_s* p0_r0_s0 p0_r0_s1 p0_r1_s# p0_r1_s* p0_r1_s0 p0_r1_s1 p0_r2_s# p0_r2_s* p0_r2_s0 p0_r2_s1 p1_r0_s# p1_r0_s* p1_r0_s0 p1_r0_s1 p1_r1_s# p1_r1_s* p1_r1_s0 p1_r1_s1 p1_r2_s# p1_r2_s* p1_r2_s0 p1_r2_s1 p2_r0_s# p2_r0_s* p2_r0_s0 p2_r0_s1 p2_r1_s# p2_r1_s* p2_r1_s0 p2_r1_s1 p2_r2_s# p2_r2_s* p2_r2_s0 p2_r2_s1 Turing.Log: Logical Program Files Initial Condition 0 Initial Condition 1 p0_q0 p0_q0 p0_r1 p0_r1 p0_r0_s# p0_r1_s0 p0_r2_s# p0_r0_s# p0_r1_s1 p0_r2_s# Medial Conditions ( p0_q# ( p1_q# )) ( p0_q* ( p1_q* )) ( p1_q# ( p2_q# )) ( p1_q* ( p2_q* )) Terminal Conditions (( p2_q# )( p2_q* )) State Partition ((p0_q0 ),(p0_q1 ),(p0_q# ),(p0_q* )) ((p1_q0 ),(p1_q1 ),(p1_q# ),(p1_q* )) ((p2_q0 ),(p2_q1 ),(p2_q# ),(p2_q* )) Register Partition ((p0_r0 ),(p0_r1 ),(p0_r2 )) ((p1_r0 ),(p1_r1 ),(p1_r2 )) ((p2_r0 ),(p2_r1 ),(p2_r2 )) Symbol Partition ((p0_r0_s0 ),(p0_r0_s1 ),(p0_r0_s# )) ((p0_r1_s0 ),(p0_r1_s1 ),(p0_r1_s# )) ((p0_r2_s0 ),(p0_r2_s1 ),(p0_r2_s# )) ((p1_r0_s0 ),(p1_r0_s1 ),(p1_r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1_q0 p1_r2 p1_r1_s1 )) ( p0_q1 p0_r1 p0_r1_s# ( p1_q* p1_r0 p1_r1_s# )) ( p0_q1 p0_r2 p0_r2_s# ( p1_q* p1_r1 p1_r2_s# )) ( p1_q0 p1_r1 p1_r1_s0 ( p2_q0 p2_r2 p2_r1_s0 )) ( p1_q0 p1_r1 p1_r1_s1 ( p2_q1 p2_r2 p2_r1_s1 )) ( p1_q0 p1_r1 p1_r1_s# ( p2_q# p2_r0 p2_r1_s# )) ( p1_q0 p1_r2 p1_r2_s# ( p2_q# p2_r1 p2_r2_s# )) ( p1_q1 p1_r1 p1_r1_s0 ( p2_q1 p2_r2 p2_r1_s0 )) ( p1_q1 p1_r1 p1_r1_s1 ( p2_q0 p2_r2 p2_r1_s1 )) ( p1_q1 p1_r1 p1_r1_s# ( p2_q* p2_r0 p2_r1_s# )) ( p1_q1 p1_r2 p1_r2_s# ( p2_q* p2_r1 p2_r2_s# )) Output 0 Output 1 p0_q0 p0_q0 p0_r1 p0_r1 p0_r0_s# p0_r0_s# p0_r1_s0 p0_r1_s1 p0_r2_s# p0_r2_s# p1_q0 p1_q1 p1_r2 p1_r2 p1_r2_s# p1_r2_s# p1_r0_s# p1_r0_s# p1_r1_s0 p1_r1_s1 p2_q# p2_q* p2_r1 p2_r1 p2_r0_s# p2_r0_s# p2_r1_s0 p2_r1_s1 p2_r2_s# p2_r2_s# Extra Examples 1. Propositional logic example. Files: Alpha.lex + Prop.log Ref: [Cha, 20, Example 2.12] 2. Chemical synthesis problem. Files: Chem.* Ref: [Cha, 21, Example 2.13] 3. N Queens problem. Files: Queen*.*, Q8.*, Q5.* Refs: [BaC, 166], [VaH, 122], [Wir, 143]. Notes: Only the 5 Queens example will run in 640K memory. Use the “Queen.lex” file to load the “Q5.eg*” log files. 4. Five Houses puzzle. Files: House.* Ref: [VaH, 132]. Notes: Will not run in 640K memory. 5. Graph coloring example. Files: Color.* Ref: [Wil, 196]. 6. Examples of Cook’s Theorem in computational complexity, that propositional satisfiability is NP-complete. Files: StiltN.* = “Space and Time Limited Turing Machine”, with N units of space and N units of time. StuntN.* = “Space and Time Limited Turing Machine”, for computing the parity of a bit string, with Number of Tape cells of input equal to N. Ref: [Wil, 188-201]. Notes: Can only run Turing machine example for input of size 2. Since the last tape cell is used for an end-of-file marker, this amounts to only one significant digit of computation. Use the “Stilt3.lex” file to load the “Stunt2.egN” files. Their Sense file outputs appear on the “Stunt2.seN” files. 7. Fabric knowledge base. Files: Fabric.*, Fab.* Ref: [MaW, 8-16]. 8. Constraint Satisfaction example. Files: Consat1.*, Consat2.* Ref: [Win, 449, Exercise 3-9]. Notes: Attributed to Kenneth D. Forbus. References [Ang] Angluin, Dana “Learning with Hints”, in Proceedings of the 1988 Workshop on Computational Learning Theory, edited by D. Haussler & L. Pitt, Morgan Kaufmann, San Mateo, CA, 1989. [BaC] Ball, W.W. Rouse, & Coxeter, H.S.M. Mathematical Recreations and Essays, 13th ed., Dover, New York, NY, 1987. [Cha] Chang, Chin-Liang & Lee, Richard Char-Tung Symbolic Logic and Mechanical Theorem Proving, Academic Press, New York, NY, 1973. [DDQ] Denning, Peter J., Dennis, Jack B., and Qualitz, Joseph E. Machines, Languages, and Computation, Prentice-Hall, Englewood Cliffs, NJ, 1978. [Ede] Edelman, Gerald M. Topobiology: An Introduction to Molecular Embryology, Basic Books, New York, NY, 1988. [Llo] Lloyd, J.W. Foundations of Logic Programming, Springer-Verlag, Berlin, 1984. [MaW] Maier, David & Warren, David S. Computing with Logic: Logic Programming with Prolog, Benjamin/Cummings, Menlo Park, CA, 1988. [McR] McClelland, James L. and Rumelhart, David E. Explorations in Parallel Distributed Processing: A Handbook of Models, Programs, and Exercises, MIT Press, Cambridge, MA, 1988. [P1] Peirce, Charles Sanders Collected Papers of Charles Sanders Peirce, edited by Charles Hartshorne, Paul Weiss, & Arthur W. Burks, Harvard University Press, Cambridge, MA, 1931-1960. [P2] The New Elements of Mathematics, edited by Carolyn Eisele, Mouton, The Hague, 1976. [P3] Charles S. Peirce: Selected Writings; Values in a Universe of Chance, edited by Philip P. Wiener, Dover, New York, NY, 1966. [SpB] Spencer Brown, George Laws of Form, George Allen & Unwin, London, UK, 1969. [VaH] Van Hentenryck, Pascal Constraint Satisfaction in Logic Programming, MIT Press, Cambridge, MA, 1989. [Wil] Wilf, Herbert S. Algorithms and Complexity, Prentice-Hall, Englewood Cliffs, NJ, 1986. [Win] Winston, Patrick Henry Artificial Intelligence, 2nd ed., Addison-Wesley, Reading, MA, 1984. [Wir] Wirth, Niklaus Algorithms + Data Structures = Programs, Prentice-Hall, Englewood Cliffs, NJ, 1976. PAGE 17