Example usage for org.apache.commons.math3.distribution IntegerDistribution reseedRandomGenerator

List of usage examples for org.apache.commons.math3.distribution IntegerDistribution reseedRandomGenerator

Introduction

In this page you can find the example usage for org.apache.commons.math3.distribution IntegerDistribution reseedRandomGenerator.

Prototype

void reseedRandomGenerator(long seed);

Source Link

Document

Reseed the random generator used to generate samples.

Usage

From source file:fr.inria.atlanmod.instantiator.neoEMF.GenericMetamodelConfig.java

@Override
public EClass getNextRootEClass(ImmutableSet<EClass> rootEClasses) {
    if (rootEClasses.size() == 1)
        return rootEClasses.asList().get(0);

    IntegerDistribution distribution = distributions.get(rootEClasses);
    if (distribution == null) {
        distribution = new UniformIntegerDistribution(0, rootEClasses.size() - 1);
        distribution.reseedRandomGenerator(random.nextLong());
        distributions.put(rootEClasses, distribution);
    }// ww w  .ja va 2s . c o m

    return rootEClasses.asList().get(distribution.sample());
}

From source file:fr.inria.atlanmod.instantiator.neoEMF.GenericMetamodelConfig.java

@Override
public IntegerDistribution getValueDistributionFor(Class<?> clazz) {
    IntegerDistribution distribution = distributions.get(clazz);
    if (distribution == null) {
        distribution = new UniformIntegerDistribution(valuesRange.getMinimum(), valuesRange.getMaximum());
        distribution.reseedRandomGenerator(random.nextLong());
        distributions.put(clazz, distribution);
    }/*from   www  .  jav  a 2s  . co m*/
    return distribution;
}

From source file:fr.inria.atlanmod.instantiator.neoEMF.GenericMetamodelConfig.java

@Override
public IntegerDistribution getResourceSizeDistribution() {
    IntegerDistribution distribution = distributions.get(metamodelResource);
    if (distribution == null) {
        distribution = new UniformIntegerDistribution(elementsRange.getMinimum(), elementsRange.getMaximum());
        distribution.reseedRandomGenerator(random.nextLong());
        distributions.put(metamodelResource, distribution);
    }//from ww w. ja va2  s  . c  om
    return distribution;
}

From source file:fr.inria.atlanmod.instantiator.neoEMF.GenericMetamodelConfig.java

@Override
public IntegerDistribution getDepthDistributionFor(EClass eClass) {
    IntegerDistribution distribution = distributions.get(eClass);
    if (distribution == null) {
        distribution = new UniformIntegerDistribution(referencesRange.getMinimum(),
                referencesRange.getMaximum());
        distribution.reseedRandomGenerator(random.nextLong());
        distributions.put(eClass, distribution);
    }/*  w ww.  j a  v  a 2  s . c  o  m*/
    return distribution;
}

From source file:fr.inria.atlanmod.instantiator.neoEMF.GenericMetamodelConfig.java

@Override
public IntegerDistribution getDistributionFor(EAttribute eAttribute) {
    IntegerDistribution distribution = distributions.get(eAttribute);

    if (distribution == null) {
        if (!eAttribute.isMany()) {
            distribution = new UniformIntegerDistribution(propertiesRange.getMinimum(),
                    propertiesRange.getMaximum());
            distribution.reseedRandomGenerator(random.nextLong());
        } else {/*www .j a  v a  2  s . c  om*/
            final int upperBound = eAttribute.getUpperBound() == EAttribute.UNBOUNDED_MULTIPLICITY
                    ? Integer.MAX_VALUE
                    : eAttribute.getUpperBound();
            // TODO fix lowerBound when it is equal to 
            int lowerBound = upperBound == eAttribute.getLowerBound() ? 0 : eAttribute.getLowerBound();
            int min = Math.max(Math.min(propertiesRange.getMinimum(), upperBound), lowerBound);
            int max = Math.min(propertiesRange.getMaximum(), upperBound);
            if (min == max) {
                return new MonoValuedIntegerDistribution(min);
            } else {
                distribution = new UniformIntegerDistribution(min, max);
                distribution.reseedRandomGenerator(random.nextLong());
            }
        }
        distributions.put(eAttribute, distribution);
    }
    return distribution;
}

From source file:fr.inria.atlanmod.instantiator.neoEMF.GenericMetamodelConfig.java

@Override
public IntegerDistribution getDistributionFor(EReference eReference) {
    IntegerDistribution distribution = distributions.get(eReference);

    if (distribution == null) {
        if (!eReference.isMany()) {
            distribution = new UniformIntegerDistribution(propertiesRange.getMinimum(),
                    propertiesRange.getMaximum());
            distribution.reseedRandomGenerator(random.nextLong());
        } else {/*from  w  w w.j  a v a 2 s.c  om*/
            final int upperBound = eReference.getUpperBound() == EAttribute.UNBOUNDED_MULTIPLICITY
                    ? Integer.MAX_VALUE
                    : eReference.getUpperBound();
            // TODO fix lowerBound when it is equal to 
            int lowerBound = upperBound == eReference.getLowerBound() ? 0 : eReference.getLowerBound();
            int min = Math.max(Math.min(propertiesRange.getMinimum(), upperBound), lowerBound);
            int max = Math.min(propertiesRange.getMaximum(), upperBound);
            if (min == max) {
                return new MonoValuedIntegerDistribution(min);
            } else {
                distribution = new UniformIntegerDistribution(min, max);
                distribution.reseedRandomGenerator(random.nextLong());
            }
        }
        distributions.put(eReference, distribution);
    }
    return distribution;
}

From source file:org.apache.beam.sdk.io.synthetic.SyntheticOptions.java

public static Sampler fromIntegerDistribution(final IntegerDistribution dist) {
    return new Sampler() {
        private static final long serialVersionUID = 0L;

        @Override/*from  w  ww .  java 2 s.co m*/
        public double sample(long seed) {
            dist.reseedRandomGenerator(seed);
            return dist.sample();
        }

        @Override
        public Object getDistribution() {
            return dist;
        }
    };
}