001 package aima.test.probdecisiontest; 002 003 import junit.framework.TestCase; 004 import aima.probability.decision.MDP; 005 import aima.probability.decision.MDPFactory; 006 import aima.probability.decision.MDPUtilityFunction; 007 import aima.probability.decision.cellworld.CellWorldPosition; 008 009 /** 010 * @author Ravi Mohan 011 * 012 */ 013 public class ValueIterationTest extends TestCase { 014 private MDP<CellWorldPosition, String> fourByThreeMDP; 015 016 @Override 017 public void setUp() { 018 fourByThreeMDP = MDPFactory.createFourByThreeMDP(); 019 } 020 021 public void testValueIterationInCellWorld() { 022 MDPUtilityFunction<CellWorldPosition> uf = fourByThreeMDP 023 .valueIterationTillMAximumUtilityGrowthFallsBelowErrorMargin(1, 024 0.00001); 025 026 // check against Fig 17.3 027 assertEquals(0.705, uf.getUtility(new CellWorldPosition(1, 1)), 0.001); 028 assertEquals(0.655, uf.getUtility(new CellWorldPosition(1, 2)), 0.001); 029 assertEquals(0.611, uf.getUtility(new CellWorldPosition(1, 3)), 0.001); 030 assertEquals(0.388, uf.getUtility(new CellWorldPosition(1, 4)), 0.001); 031 032 assertEquals(0.762, uf.getUtility(new CellWorldPosition(2, 1)), 0.001); 033 assertEquals(0.660, uf.getUtility(new CellWorldPosition(2, 3)), 0.001); 034 assertEquals(-1.0, uf.getUtility(new CellWorldPosition(2, 4)), 0.001); 035 036 assertEquals(0.812, uf.getUtility(new CellWorldPosition(3, 1)), 0.001); 037 assertEquals(0.868, uf.getUtility(new CellWorldPosition(3, 2)), 0.001); 038 assertEquals(0.918, uf.getUtility(new CellWorldPosition(3, 3)), 0.001); 039 assertEquals(1.0, uf.getUtility(new CellWorldPosition(3, 4)), 0.001); 040 041 assertEquals(0.868, uf.getUtility(new CellWorldPosition(3, 2)), 0.001); 042 } 043 }