package dr.inference.operators;

import dr.inference.model.Parameter;
import dr.inferencexml.operators.UniformIntegerOperatorParser;
import dr.math.MathUtils;

/**
 * A generic uniform sampler/operator for use with a multi-dimensional parameter.
 *
 * @author Alexei Drummond
 * @author Andrew Rambaut
 * @version $Id: UniformOperator.java,v 1.16 2005/06/14 10:40:34 rambaut Exp $
 */
public class UniformIntegerOperator extends SimpleMCMCOperator {

    public UniformIntegerOperator(Parameter parameter, int lower, int upper, double weight) {
        this.parameter = parameter;
        this.lower = lower;
        this.upper = upper;
        setWeight(weight);
    }

    /**
     * @return the parameter this operator acts on.
     */
    public Parameter getParameter() {
        return parameter;
    }

    /**
     * change the parameter and return the hastings ratio.
     */
    public final double doOperation() {

        int index = MathUtils.nextInt(parameter.getDimension());
        int newValue = MathUtils.nextInt(upper - lower) + lower;

        parameter.setParameterValue(index, newValue);

        return 0.0;
    }

    //MCMCOperator INTERFACE
    public final String getOperatorName() {
        return "uniformInteger(" + parameter.getParameterName() + ")";
    }

    public final void optimize(double targetProb) {

        throw new RuntimeException("This operator cannot be optimized!");
    }

    public boolean isOptimizing() {
        return false;
    }

    public void setOptimizing(boolean opt) {
        throw new RuntimeException("This operator cannot be optimized!");
    }

    public double getMinimumAcceptanceLevel() {
        return 0.1;
    }

    public double getMaximumAcceptanceLevel() {
        return 0.4;
    }

    public double getMinimumGoodAcceptanceLevel() {
        return 0.20;
    }

    public double getMaximumGoodAcceptanceLevel() {
        return 0.30;
    }

    public String getPerformanceSuggestion() {
        if (Utils.getAcceptanceProbability(this) < getMinimumAcceptanceLevel()) {
            return "";
        } else if (Utils.getAcceptanceProbability(this) > getMaximumAcceptanceLevel()) {
            return "";
        } else {
            return "";
        }
    }

    public String toString() {
        return UniformIntegerOperatorParser.UNIFORM_INTEGER_OPERATOR + "(" + parameter.getParameterName() + ")";
    }

    //PRIVATE STUFF

    private Parameter parameter = null;
    private int upper;
    private int lower;
}

@@ -442,16 +442,47 @@
 erator %7B
+%0A    private final int howMany;
 %0A%0A    pu
@@ -565,16 +565,63 @@
 e weight
+,%0A                                  int howMany
 ) %7B%0A    
@@ -704,24 +704,56 @@
 er = upper;%0A
+        this.howMany = howMany;%0A
         setW
@@ -766,32 +766,185 @@
 weight);%0A    %7D%0A%0A
+    public UniformIntegerOperator(Parameter parameter, int lower, int upper, double weight) %7B%0A      this(parameter, lower, upper, weight, 1);%0A    %7D%0A    %0A
     /**%0A     * @
@@ -1178,24 +1178,134 @@
 ration() %7B%0A%0A
+        for(int n = 0; n %3C howMany; ++n) %7B%0A            // do not worry about duplication, does not matter%0A    
         int 
@@ -1361,24 +1361,28 @@
 ));%0A        
+  
+  
 int newValue
@@ -1435,16 +1435,20 @@
         
+    
 paramete
@@ -1484,16 +1484,26 @@
 wValue);
+%0A        %7D
 %0A%0A      
@@ -2850,24 +2850,30 @@
     private 
+final 
 int upper;%0A 
@@ -2883,16 +2883,22 @@
 private 
+final 
 int lowe

Allow multiple moves