001    /*
002     * Created on Feb 9, 2005
003     *
004     */
005    package aima.test.logictest.prop.algorithms;
006    
007    import junit.framework.TestCase;
008    import aima.logic.propositional.algorithms.KnowledgeBase;
009    import aima.logic.propositional.algorithms.Model;
010    import aima.logic.propositional.algorithms.WalkSAT;
011    
012    /**
013     * @author Ravi Mohan
014     * 
015     */
016    
017    public class WalkSATTest extends TestCase {
018            // NOT REALLY A JUNIT TESTCASE BUT written as one to allow easy execution
019            public void testWalkSat() {
020                    WalkSAT walkSAT = new WalkSAT();
021                    Model m = walkSAT.findModelFor("( A AND B )", 1000, 0.5);
022                    if (m == null) {
023                            System.out.println("failure");
024                    } else {
025                            m.print();
026                    }
027            }
028    
029            public void testWalkSat2() {
030                    WalkSAT walkSAT = new WalkSAT();
031                    Model m = walkSAT.findModelFor("( A AND (NOT B) )", 1000, 0.5);
032                    if (m == null) {
033                            System.out.println("failure");
034                    } else {
035                            m.print();
036                    }
037            }
038    
039            public void testAIMAExample() {
040                    KnowledgeBase kb = new KnowledgeBase();
041                    kb.tell(" (P => Q)");
042                    kb.tell("((L AND M) => P)");
043                    kb.tell("((B AND L) => M)");
044                    kb.tell("( (A AND P) => L)");
045                    kb.tell("((A AND B) => L)");
046                    kb.tell("(A)");
047                    kb.tell("(B)");
048                    WalkSAT walkSAT = new WalkSAT();
049                    Model m = walkSAT.findModelFor(kb.asSentence().toString(), 1000, 0.5);
050                    if (m == null) {
051                            System.out.println("failure");
052                    } else {
053                            m.print();
054                    }
055            }
056    }