/** Copies the info out of the old proposition into a new proposition for the new BayesIm. */
  public Proposition(VariableSource variableSource, Proposition proposition) {
    this(variableSource);

    if (proposition == null) {
      throw new NullPointerException();
    }

    List<Node> variables = variableSource.getVariables();
    List<Node> oldVariables = proposition.getVariableSource().getVariables();

    for (int i = 0; i < variables.size(); i++) {
      DiscreteVariable variable = (DiscreteVariable) variables.get(i);
      int oldIndex = -1;

      for (int j = 0; j < oldVariables.size(); j++) {
        DiscreteVariable _variable = (DiscreteVariable) oldVariables.get(j);
        if (variable.equals(_variable)) {
          oldIndex = j;
          break;
        }
      }

      if (oldIndex != -1) {
        for (int j = 0; j < allowedCategories[i].length; j++) {
          allowedCategories[i][j] = proposition.isAllowed(oldIndex, j);
        }
      }
    }
  }
  private static int nextValue(Proposition proposition, int variable, int currentIndex) {
    for (int i = currentIndex + 1; i < proposition.getNumCategories(variable); i++) {
      if (proposition.isAllowed(variable, i)) {
        return i;
      }
    }

    return -1;
  }
  /**
   * Restricts this proposition to the categories for the given variable that are true in the given
   * proposition.
   */
  public void restrictToProposition(Proposition proposition, int variable) {
    if (proposition.getVariableSource() != this.variableSource) {
      throw new IllegalArgumentException(
          "Can only restrict to " + "propositions for the same variable source.");
    }

    for (int j = 0; j < allowedCategories[variable].length; j++) {
      if (!proposition.isAllowed(variable, j)) {
        removeCategory(variable, j);
      }
    }
  }