private Assignment doOnePass(FactorGraph mdl, Assignment initial) {
    Assignment ret = (Assignment) initial.duplicate();
    for (int vidx = 0; vidx < ret.size(); vidx++) {
      Variable var = mdl.get(vidx);
      DiscreteFactor subcpt = constructConditionalCpt(mdl, var, ret);
      int value = subcpt.sampleLocation(r);
      ret.setValue(var, value);
    }

    return ret;
  }
  // Verify that potentialOfVertex and potentialOfEdge (which use
  // caches) are consistent with the potentials set even if a vertex is removed.
  public void testUndirectedCachesAfterRemove() {
    List models = TestInference.createTestModels();
    for (Iterator mdlIt = models.iterator(); mdlIt.hasNext(); ) {
      FactorGraph mdl = (FactorGraph) mdlIt.next();
      mdl = (FactorGraph) mdl.duplicate();
      mdl.remove(mdl.get(0));

      // Verify that indexing correct
      for (Iterator it = mdl.variablesIterator(); it.hasNext(); ) {
        Variable var = (Variable) it.next();
        int idx = mdl.getIndex(var);
        assertTrue(idx >= 0);
        assertTrue(idx < mdl.numVariables());
      }

      // Verify that caches consistent
      verifyCachesConsistent(mdl);
    }
  }