001    /*
002     * Created on Feb 17, 2005
003     *
004     */
005    package aima.logic.demos;
006    
007    import aima.logic.propositional.algorithms.KnowledgeBase;
008    import aima.logic.propositional.algorithms.Model;
009    import aima.logic.propositional.algorithms.WalkSAT;
010    
011    /**
012     * @author Ravi Mohan
013     * 
014     */
015    public class WalkSatDemo {
016            public static void main(String[] args) {
017                    System.out.println("\nWalkSatDemo\n");
018                    KnowledgeBase kb = new KnowledgeBase();
019                    kb.tell(" (P => Q)");
020                    kb.tell("((L AND M) => P)");
021                    kb.tell("((B AND L) => M)");
022                    kb.tell("( (A AND P) => L)");
023                    kb.tell("((A AND B) => L)");
024                    kb.tell("(A)");
025                    kb.tell("(B)");
026    
027                    System.out.println("Example from  page 220 of AIMA 2nd Edition");
028                    System.out.println("KnowledgeBsse consists of sentences");
029                    System.out.println(" (P => Q)");
030                    System.out.println("((L AND M) => P)");
031                    System.out.println("((B AND L) => M)");
032                    System.out.println("( (A AND P) => L)");
033                    System.out.println("((A AND B) => L)");
034                    System.out.println("(A)");
035                    System.out.println("(B)");
036    
037                    WalkSAT walkSAT = new WalkSAT();
038                    Model m = walkSAT.findModelFor(kb.asSentence().toString(), 1000, 0.5);
039                    if (m == null) {
040                            System.out.println("failure");
041                    } else {
042                            m.print();
043                    }
044            }
045    
046    }