// END-Factor // /** * Iterate over all the possible value assignments for the Random Variables * comprising this ProbabilityTable. * * @param pti * the ProbabilityTable Iterator to iterate. */ public void iterateOverTable(IIterator pti) { IMap <IRandomVariable, object> possibleWorld = CollectionFactory.CreateInsertionOrderedMap <IRandomVariable, object>(); MixedRadixNumber mrn = new MixedRadixNumber(0, radices); do { foreach (RVInfo rvInfo in randomVarInfo.GetValues()) { possibleWorld.Put(rvInfo.getVariable(), rvInfo .getDomainValueAt(mrn.GetCurrentNumeralValue(rvInfo .getRadixIdx()))); } pti.iterate(possibleWorld, values[mrn.IntValue()]); } while (mrn.Increment()); }
public void testDecrement() { MixedRadixNumber mrn = new MixedRadixNumber(5, new int[] { 3, 2 }); int i = 0; while (mrn.Decrement()) { ++i; } Assert.AreEqual(i, mrn.GetMaxAllowedValue()); i = 0; while (mrn.Increment()) { ++i; } while (mrn.Decrement()) { i--; } Assert.AreEqual(i, mrn.IntValue()); }
public void testSetCurrentValueFor() { MixedRadixNumber mrn; // mrn = new MixedRadixNumber(0, new int[] { 3, 3, 2, 2 }); mrn.SetCurrentValueFor(new int[] { 0, 0, 0, 0 }); Assert.AreEqual(0, mrn.IntValue()); Assert.AreEqual(0, mrn.GetCurrentNumeralValue(0)); Assert.AreEqual(0, mrn.GetCurrentNumeralValue(1)); Assert.AreEqual(0, mrn.GetCurrentNumeralValue(2)); Assert.AreEqual(0, mrn.GetCurrentNumeralValue(3)); // mrn = new MixedRadixNumber(0, new int[] { 3, 3, 2, 2 }); mrn.SetCurrentValueFor(new int[] { 2, 2, 1, 1 }); Assert.AreEqual(35, mrn.IntValue()); Assert.AreEqual(2, mrn.GetCurrentNumeralValue(0)); Assert.AreEqual(2, mrn.GetCurrentNumeralValue(1)); Assert.AreEqual(1, mrn.GetCurrentNumeralValue(2)); Assert.AreEqual(1, mrn.GetCurrentNumeralValue(3)); // mrn = new MixedRadixNumber(0, new int[] { 3, 3, 2, 2 }); mrn.SetCurrentValueFor(new int[] { 1, 2, 0, 1 }); Assert.AreEqual(25, mrn.IntValue()); Assert.AreEqual(1, mrn.GetCurrentNumeralValue(0)); Assert.AreEqual(2, mrn.GetCurrentNumeralValue(1)); Assert.AreEqual(0, mrn.GetCurrentNumeralValue(2)); Assert.AreEqual(1, mrn.GetCurrentNumeralValue(3)); // mrn = new MixedRadixNumber(0, new int[] { 3, 3, 2, 2 }); mrn.SetCurrentValueFor(new int[] { 2, 2, 1, 0 }); Assert.AreEqual(17, mrn.IntValue()); Assert.AreEqual(2, mrn.GetCurrentNumeralValue(0)); Assert.AreEqual(2, mrn.GetCurrentNumeralValue(1)); Assert.AreEqual(1, mrn.GetCurrentNumeralValue(2)); Assert.AreEqual(0, mrn.GetCurrentNumeralValue(3)); // mrn = new MixedRadixNumber(0, new int[] { 3, 3, 2, 2 }); mrn.SetCurrentValueFor(new int[] { 2, 2, 0, 0 }); Assert.AreEqual(8, mrn.IntValue()); Assert.AreEqual(2, mrn.GetCurrentNumeralValue(0)); Assert.AreEqual(2, mrn.GetCurrentNumeralValue(1)); Assert.AreEqual(0, mrn.GetCurrentNumeralValue(2)); Assert.AreEqual(0, mrn.GetCurrentNumeralValue(3)); // mrn = new MixedRadixNumber(0, new int[] { 3, 4, 5, 6 }); mrn.SetCurrentValueFor(new int[] { 2, 3, 4, 5 }); Assert.AreEqual(359, mrn.IntValue()); Assert.AreEqual(2, mrn.GetCurrentNumeralValue(0)); Assert.AreEqual(3, mrn.GetCurrentNumeralValue(1)); Assert.AreEqual(4, mrn.GetCurrentNumeralValue(2)); Assert.AreEqual(5, mrn.GetCurrentNumeralValue(3)); // mrn = new MixedRadixNumber(0, new int[] { 6, 5, 4, 3 }); mrn.SetCurrentValueFor(new int[] { 5, 4, 3, 2 }); Assert.AreEqual(359, mrn.IntValue()); Assert.AreEqual(5, mrn.GetCurrentNumeralValue(0)); Assert.AreEqual(4, mrn.GetCurrentNumeralValue(1)); Assert.AreEqual(3, mrn.GetCurrentNumeralValue(2)); Assert.AreEqual(2, mrn.GetCurrentNumeralValue(3)); }