⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 gridsimrandom.java

📁 一个非常著名的网格模拟器,能够运行网格调度算法!
💻 JAVA
📖 第 1 页 / 共 2 页
字号:
/* * Title:        GridSim Toolkit * Description:  GridSim (Grid Simulation) Toolkit for Modeling and Simulation *               of Parallel and Distributed Systems such as Clusters and Grids * Licence:      GPL - http://www.gnu.org/copyleft/gpl.html * * $Id: GridSimRandom.java,v 1.13 2004/11/01 02:52:35 anthony Exp $ */package gridsim;import java.util.Random;/** * GridSim Random provides static methods for incorporating randomness in data * used for any simulation. * <p> * This class will be created by GridSim upon initialization of the simulation, * i.e. done via <tt>GridSim.init()</tt> method. Hence, do not need to worry * about creating an object of this class. * <p> * Any predicted or estimated data, e.g. number of * Gridlets used by an experiment, execution time and output size of a Gridlet, * etc. need to present in the prediction or estimation process and the * randomness that exists in the nature itself. * <p> * <tt>Example:</tt> to produce a random number between 18.00 and 22.00, need * to invoke <tt>GridSimRandom.real(20.0, 0.1, 0.1, randDouble)</tt> where * <tt>randDouble</tt> comes from <b>java.util.Random</b>. * * @author       Manzur Murshed and Rajkumar Buyya * @since        GridSim Toolkit 1.0 * @see gridsim.Gridlet * @see java.util.Random * @invariant $none * @see gridsim.GridSim#init(int, Calendar, boolean) * @see gridsim.GridSim#init(int, Calendar, boolean, String[], String[], String) */public class GridSimRandom{    private static final int MIN_VALUE = 0;    private static final int MAX_VALUE = 1;    private static Random random_;    // Factor values for Network I/O    private static double lessFactorIO_;    private static double moreFactorIO_;    // Factor values for Execution    private static double lessFactorExec_;    private static double moreFactorExec_;    /** Initializes all static variables */    static    {        random_ = new Random();        lessFactorIO_ = 0.0;        moreFactorIO_ = 0.0;        lessFactorExec_ = 0.0;        moreFactorExec_ = 0.0;    }    /**     * Allocates a new GridSimRandom object     * @pre $none     * @post $none     */    public GridSimRandom() {        // empty    }    /**     * Allocates a new GridSimRandom object using a single <tt>long</tt> seed     * @param seed the initial seed     * @pre seed >= 0.0     * @post $none     */    public GridSimRandom(long seed) {        random_.setSeed(seed);    }    /**     * Allocates a new GridSimRandom object with specified parameters     * @param seed          the initial seed     * @param lessFactorIO  less factor for Network I/O     * @param moreFactorIO  more factor for Network I/O     * @param lessFactorExec   less factor for execution     * @param moreFactorExec   more factor for execution     * @pre seed >= 0.0     * @pre lessFactorIO >= 0.0     * @pre moreFactorIO >= 0.0     * @pre lessFactorExec >= 0.0     * @pre moreFactorExec >= 0.0     * @post $none     */    public GridSimRandom(long seed, double lessFactorIO, double moreFactorIO,                double lessFactorExec, double moreFactorExec)    {        random_.setSeed(seed);        lessFactorIO_ = lessFactorIO;        moreFactorIO_ = moreFactorIO;        lessFactorExec_ = lessFactorExec;        moreFactorExec_ = moreFactorExec;    }    /**     * Sets the Network I/O and execution values     * @param lessFactorIOValue  less factor for Network I/O     * @param moreFactorIOValue  more factor for Network I/O     * @param lessFactorExecValue   less factor for execution     * @param moreFactorExecValue   more factor for execution     * @deprecated As of GridSim 2.1, replaced by {@link #setAllFactors(double,     *             double, double, double)}     * @pre lessFactorIOValue >= 0.0     * @pre moreFactorIOValue >= 0.0     * @pre lessFactorExecValue >= 0.0     * @pre moreFactorExecValue >= 0.0     * @post $none     */    public static void set_factors(double lessFactorIOValue,                double moreFactorIOValue, double lessFactorExecValue,                double moreFactorExecValue)    {        setAllFactors(lessFactorIOValue, moreFactorIOValue, lessFactorExecValue,                moreFactorExecValue);    }    /**     * Sets the Network I/O and execution values     * @param lessFactorIOValue  less factor for Network I/O     * @param moreFactorIOValue  more factor for Network I/O     * @param lessFactorExecValue   less factor for execution     * @param moreFactorExecValue   more factor for execution     * @pre lessFactorIOValue >= 0.0     * @pre moreFactorIOValue >= 0.0     * @pre lessFactorExecValue >= 0.0     * @pre moreFactorExecValue >= 0.0     * @post $none     */    public static void setAllFactors(double lessFactorIOValue,                double moreFactorIOValue, double lessFactorExecValue,                double moreFactorExecValue)    {        lessFactorIO_ = lessFactorIOValue;        moreFactorIO_ = moreFactorIOValue;        lessFactorExec_ = lessFactorExecValue;        moreFactorExec_ = moreFactorExecValue;    }    /**     * Gets the random int value from <b>java.util.Random</b>     * @param range the bound on the random number to be returned.     *              The range must be positive (excluding 0).     * @return a pseudorandom, uniformly distributed <tt>int</tt> value between     *         0 (inclusive) and range (exclusive)     * @throws IllegalArgumentException range is not positive     * @deprecated As of GridSim 2.1, replaced by {@link #intSample(int)}     * @pre range > 0     * @post $result >= 0     */    public static int int_sample(int range) throws IllegalArgumentException {        return intSample(range);    }    /**     * Gets the random int value from <b>java.util.Random</b>     * @param range the bound on the random number to be returned.     *              The range must be positive (excluding 0).     * @return a pseudorandom, uniformly distributed <tt>int</tt> value between     *         0 (inclusive) and range (exclusive)     * @throws IllegalArgumentException range is not positive     * @pre range > 0     * @post $result >= 0     */    public static int intSample(int range) throws IllegalArgumentException {        return random_.nextInt(range);    }    /**     * Gets the random double value from <b>java.util.Random</b>     * @return the next pseudorandom, uniformly distributed <tt>double</tt>     *         value between 0.0 and 1.0 from this random number generator's     *         sequence     * @deprecated As of GridSim 2.1, replaced by {@link #doubleSample()}     * @pre $none     * @post $result >= 0.0 && $result <= 1.0     */    public static double double_sample() {        return doubleSample();    }    /**     * Gets the random double value from <b>java.util.Random</b>     * @return the next pseudorandom, uniformly distributed <tt>double</tt>     *         value between 0.0 and 1.0 from this random number generator's     *         sequence     * @pre $none     * @post $result >= 0.0 && $result <= 1.0     */    public static double doubleSample() {        return random_.nextDouble();    }    /**     * Sets the less factor of Network I/O. If <tt>factor</tt> is less than     * 0, then it is being ignored.     * @param factor the initial factor     * @throws IllegalArgumentException factor is not zero or positive     * @deprecated As of GridSim 2.1, replaced by     *             {@link #setLessFactorIO(double)}     * @pre factor >= 0.0     * @post $none     */    public static void set_less_factor_io(double factor)                throws IllegalArgumentException    {        setLessFactorIO(factor);    }    /**     * Sets the less factor of Network I/O     * @param factor the initial factor     * @throws IllegalArgumentException factor is not zero or positive     * @pre factor >= 0.0     * @post $none     */    public static void setLessFactorIO(double factor)                throws IllegalArgumentException    {        if (factor < MIN_VALUE)        {            throw new IllegalArgumentException(                    "GridSimRandom.setLessFactorIO() : Error - factor must" +                    " be zero or positive value.");        }        lessFactorIO_ = factor;    }    /**     * Sets the more factor of Network I/O     * @param factor the initial factor     * @throws IllegalArgumentException factor is not zero or positive     * @deprecated As of GridSim 2.1, replaced by     *             {@link #setMoreFactorIO(double)}     * @pre factor >= 0.0     * @post $none     */    public static void set_more_factor_io(double factor)                throws IllegalArgumentException    {        setMoreFactorIO(factor);    }    /**     * Sets the more factor of Network I/O     * @param factor the initial factor     * @throws IllegalArgumentException factor is not zero or positive     * @pre factor >= 0.0     * @post $none     */    public static void setMoreFactorIO(double factor)                throws IllegalArgumentException    {        if (factor < MIN_VALUE)        {            throw new IllegalArgumentException(                    "GridSimRandom.setMoreFactorIO() : Error - factor must" +                    " be zero or positive value.");        }        moreFactorIO_ = factor;    }    /**     * Sets the less factor of Execution     * @param factor the initial factor     * @throws IllegalArgumentException factor is not zero or positive     * @deprecated As of GridSim 2.1, replaced by     *             {@link #setLessFactorExec(double)}

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -